Hi there
I pass variable $user and $pass from login.php to loggedin.php using: http://blahblah/loggedin.php?user=$user&pass=$pass
In loggedin.php i have the following code:
<? setcookie ("user", $user,time()+3600); ?> <html> <head> <title>You have sucessfully logged in</title> </head> <body> <? echo $HTTP_COOKIE_VARS["user"]; ?> </body> </html>
Why isn't my variable $user from login.php being given to the cookie?
Thanks
-DF
You might have to use $HTTP_GET_VARS, like this:
<? setcookie ("user",$HTTP_GET_VARS['user'],time()+3600); ?> <html> <head> <title>You have sucessfully logged in</title> </head> <body> <? echo $HTTP_COOKIE_VARS['user']; ?> </body> </html>
Damn, didn't work
What method do you use in the login form, GET or POST?
post
Then use $HTTP_POST_VARS["user"] or $_POST["user"]
This may not work cos of cookies not enabled.. Enable them if there not..
🙁 Nope didn't work. I changed it to POST and set Internet Explorer to allow all cookies but it still displays nothing!
Would it help if i pasted all of my code, from all the pages i mean?
Sorry about this, thanks for your help
DF
Try this:
<? if(isset($HTTP_COOKIE_VARS['user'])) { echo "<html> <head> <title>You have sucessfully logged in</title> </head> <body> ".$HTTP_COOKIE_VARS['user']." </body> </html>\n"; } else { setcookie("user", $user,time()+3600); header("Location: $HTTP_SERVER_VARS[PHP_SELF]"); } ?>
weird, now i get an error 404, i think its something to do with the: header("Location: $HTTP_SERVER_VARS[PHP_SELF]"); bit cos i've uploaded the files
change that to the name of the file.
I've changed it to header("Location: loggedin.php[PHP_SELF]"); But i still get an error 404
I mean like this:
header("Location: loggedin.php");
no luck
Now it just sits there on the login.php page, doesn't go to logged in.
See for yourself:
http://members.lycos.co.uk/demonicfoetus/login.htm
User: will Pass: bowles
I tried altering the code to sessions instead of cookies
session_start(); session_register("user", "pass"); echo $HTTP_SESSION_VARS["user"];
But it still don't get anything echoing.
Could it be something in my servers php.ini file not set up?