Page 1 of 1

Help with login/logout script

Posted: Thu Aug 12, 2004 6:30 am
by Getran
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

Posted: Thu Aug 12, 2004 7:04 am
by hawleyjr
Use sessions. on pages after the login how do you validate the user?

Posted: Thu Aug 12, 2004 7:10 am
by Getran
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";
    }
?>

Posted: Thu Aug 12, 2004 7:13 am
by hawleyjr
When they log-out. change the expire date of your cookie:

Code: Select all

<?php
	//KILL COOKIE
	$tm =time()-60*60*24*30;
	setcookie("my_cookie_name", $some_variable,$tm,'/');
?>

Edit: Take a look at the following tuturials for sessions:

http://www.phpexamples.net/tutorial-8-1.html
http://www.digiways.com/articles/php/sessauth/
http://www.phptutorial.info/learn/session.html

Posted: Thu Aug 12, 2004 7:15 am
by Getran
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 :/

Posted: Thu Aug 12, 2004 7:18 am
by hawleyjr
What is the specific error you are getting?

Posted: Thu Aug 12, 2004 7:20 am
by Getran
Notice: Undefined variable: username in *hidden*\logout.php on line 2

Posted: Thu Aug 12, 2004 7:39 am
by hawleyjr
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!"; 
?>

Posted: Thu Aug 12, 2004 8:01 am
by hawleyjr
Feyd, please mark as solved. Solved through PM.