Javascript and php
Hi,
i have installed a PHP login system on a new site im designing. I want to use the login/logout/ membership details in an <iframe> and show on HTML pages, this works ok. My problem is I have 10 links on each HTML page and I want to disable two of them unless the user has logged in. Is it possible to do this using Javascript, ie javascript would read from the database and show user either logged in or not and so enable or disable the link as required. Any help would be great as I have spent weeks trawling the net to see if this is possible but to no avail. Thank You in Advance Back to top |
|||||
the first question is why do you want to do that?
Since php is going to tell you if the person is logged in or not, why not use php to output the values you 're looking for: :: Code ::
<?php if ( $logged_in ) { echo 'logged in data'; } else { echo 'non-logged in data'; } ?> Is all you need, that's much easier than creating something like an ajax script, with all its browser dependent variables etc. Theoretically, yes, you could do it, if you really wanted to. Or you could get rid of the iframe, and just build the page with php in the first place. If logged in, give that information, if not, give the other stuff. That's how pretty much every site on the web that has logins does it, including this one. But in answer to your question, yes, if you absolutely have to do it, y ou can do it. This recent ajax thread, plus a few others, search the forums, would give you a good start. But, again, this isn't a very good way to do it. That person was really just creating an exercise for themselves so they could learn ajax, the whole project would have been much easier to do with mysql and php, no ajax/javascript. And a lot more reliable. Back to top |
|||||
Thank you for reply jeefd
the reason I want to do it this way is two fold: (1) I have designed and set everything up in html and feel it would be difficult and very time consuming to change it all to php [over 200 pages] (2) I am not proficient in php and all of the pages are backed up by a perl/cgi script, one for each individual page. Having said that, I welcome your thoughts and believe that it is possibly the best course of action for me, keeps me busy. Again my Thanks for help Back to top |
|||||
:: Quote :: (2) I am not proficient in php and all of the pages are backed up by a perl/cgi script, one for each individual page. This makes it hard to do the job right. I know what you're saying, but I have to say, almost every time we see someone here asking about a solution using iframes, almost every single time it's because they don't know how to use programming to do the job the way it actually should be done. So it's a tough one. If you don't know programming, then doing the javascript solution isn't going to be any easier than just dumping the cgi script you picked up and just programming the solution in php. Ajax isn't particularly easy either, and also requires custom made data files and database accesses, so it's really not going to make it any easier for you. The basics for login stuff is pretty simple with php, somebody logs in, you have the programming create username / password combinations, then you set a cookie to say they are logged in. You check for the cookie, if present, you show some data, if not present, you show the non-logged in stuff. That's pretty much how it works, but you have to know some programming to implement that solution. So I'm not sure we can help you, we don't write people's scripts for them, though looking at code and seeing if we can find why it's not working is another matter. I don't know what more to say about that, except that I'm not surprised to see that once again an iframe is being used in place of the proper method more as a hack than as a good solution. But sometimes that's all you can do until you learn more, I've done that too. Back to top |
|||||
All times are GMT - 8 Hours
|