Hello i made a website with a database and all i got the login to work but when i refresh it logs me back out my friend told me i need to get a cookie but i dont no how to make one i just want when the user logs in he stays on for 1 hour can any one help me please Thanks Ryan
setcookie("logged_in", 1, time()+3600); PHP: Then youll have to check that the cookie exists. This isnt fool proof and can be easily hacked, but it will work
i put that in the notepad and saved it as cookie.php and it didnt work i put it in the htdocs folder and all
It important that the cookiecode comes before the <HTML> tag Example in how it's done; this should be in the "login.php" <?php if($username==$getusername) setcookie("logged_in", 1, time()+3600); ?> PHP: This should be in all the pages that you need to login to get to; <?php if($_COOKIE["logged_in"]) { //here you put all the site-code } else echo "You are not logged in"; ?> PHP: hope it works ;D Tip: you could do like this; <?php if($_COOKIE["logged_in"]) { ?> <!--- here you put all the site-html and you don't need the "echo" ---> <?php } else echo "You are not logged in"; ?> PHP:
it still does not work what i have is 2 iframes 1 on the left and 1 on the right the right 1 is logged in but the left 1 asks me to keep logging in because when u go to a page and you r not logged in it will bring u back to the login page if you want to look for yourself go to http://71.196.111.196 and the login name is test the password is test123 the right iframe will say error 404 page not found because i didnt make that page yet but the thing i need to work is the left iframe wich is members.php and i dont no why it wont work it worked fine when i was using abyss webserver and then i switched to apache and it didnt work right please help thanks