PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Thu Aug 12, 2004 6:30 am
Hey, i have my login and signup pages finished and everything. So i made a logout link too, when they go on it, i get the error: Underfined variable: username. How can i make it remember the $username var from login.php ? i tried just doing global $username; but i think that only global's it for that page ?
It shows this error, but does actually log them out too, can someone tell me how to sort this out plz ?
// Getran
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 12, 2004 7:04 am
Use sessions. on pages after the login how do you validate the user?
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Thu Aug 12, 2004 7:10 am
i don't quite understand what u mean, but this is to check whether they're logged in: (btw i'm using cookies not sessions)
Code: Select all
<?
$checkcookie = $_COOKIE["terrastormlogin"];
if (isset($checkcookie))
{
$loggedin = "1";
global $loggedin;
global $username;
$maincontent = "";
$maincontent .= "Cookie is set";
}
else if (!isset($checkcookie))
{
$loggedin = "0";
global $loggedin;
$maincontent = "";
$maincontent .= "Cookie Not Set";
}
?>
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Thu Aug 12, 2004 7:15 am
it aint that, that's the problem, it logs out find as i have it. but i get undefined var error... the logout page is at its simplest atm..:
<?
setcookie("terrastormlogin", "$username", -3600);
echo "You have been logged out!";
?>
and even the $username var is undefined, it still logs them out...
*EDIT* - Maybe i should just use sessions...lol, might be a bit easier :/
Last edited by
Getran on Thu Aug 12, 2004 7:19 am, edited 1 time in total.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 12, 2004 7:18 am
What is the specific error you are getting?
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Thu Aug 12, 2004 7:20 am
Notice: Undefined variable: username in *hidden*\logout.php on line 2
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 12, 2004 7:39 am
Please show more of your code. Have you tried setting username to some bogous name?
Code: Select all
<?php
$username = 'Yo Mamma';
setcookie("terrastormlogin", "$username", -3600);
echo "You have been logged out!";
?>
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 12, 2004 8:01 am
Feyd, please mark as solved. Solved through PM.