fonecave Posted November 21, 2008 Share Posted November 21, 2008 Hi Guys, This question is partly about Javascript too but you probably know all about it too. I am trying to use a php script with mysql database to authenticate users and set a cookie. Basically i need a members site I currently have my database which is perfectly fine at the moment. Then i have 2 php scripts one is a login and one is registration. I have them as seperate scripts ie login.php and register.php both saved on the server and the index.html page has each of them in an iframe. They both seem to work ok but the only problem is what do i do when i have authenticated an set the cookie? i cant set a header as the script running it is in an iframe! could i send a refresh command or send an f5 key? What is the best way to do this? I also have login/logout part but i want to run it in javascript so that if a cookie is set, it shows logout and if pressed unsets the cookie (called user) and if no cookie is set i want it to display login and forward to a page.... login.html? or something not made it yet. I tried writing a script and placing it on the page in a script box (Sitespinner) but it doesnt work: <html> <head> <script type="text/javascript"> function checkCookie() { username=getCookie('user'); if (username!=null && username!="") { alert('Welcome again '+user+'!'); } } </script> </head> <body onLoad="checkCookie()"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/ Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 1) Why are you asking a Javascript question in the PHP Help section? 2) Why don't you use PHP to check the cookies? if (isset($_COOKIE["user"])) echo "Welcome " . $_COOKIE["user"] . "! "; else echo "Welcome guest! "; ?> Check out w3schools - cookies for a full explanation. Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/#findComment-695689 Share on other sites More sharing options...
fonecave Posted November 21, 2008 Author Share Posted November 21, 2008 So with that, if the cookie was set i want to show a logout link and when clicked should unset the cookie... How can i do that? Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/#findComment-695694 Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 if (isset($_COOKIE["user"])) echo "Welcome " . $_COOKIE["user"] . "! "; $user = $_COOKIE["user"]; echo "Logout" else echo "Welcome guest! "; ?> If the user clicks logout it goes to the logout.php page where you can create your own logout logic (unset the session, turn him offline in your DB, w/e). To retrieve the user name just use $_GET['user']; Does this help? Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/#findComment-695697 Share on other sites More sharing options...
fonecave Posted November 22, 2008 Author Share Posted November 22, 2008 thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/#findComment-696147 Share on other sites More sharing options...
fonecave Posted November 22, 2008 Author Share Posted November 22, 2008 After that i have eventually used a flash actionscript to post the login details to the database and then set a cookie if authorised and used the header() function to send the user back to the loginpage where there is a script that reads if there is a cookie set and if so shows the welcome message and a logout link, But.... when the user is authorised and sent back to the login page the logout script doesnt pick up the fact that there is a new cookie until the refresh key is hit! why is this? www.foxmart.co.uk/index.html test with: User Email: test@test.com password: test Thanks Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/#findComment-696283 Share on other sites More sharing options...
fonecave Posted November 22, 2008 Author Share Posted November 22, 2008 ANYBODY? Quote Link to comment https://forums.phpfreaks.com/topic/133697-page-error-login-script/#findComment-696420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.