Problem with login script!

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

Post Reply
lnetzel
Forum Newbie
Posts: 4
Joined: Sun Oct 20, 2002 1:53 pm

Problem with login script!

Post by lnetzel »

I have these Pages:

login.php (works fine, just HTML code)

validateuser.php (works fine I guess):

//VALIDATE USER
$user_name = $_POST['user_name'];
$password = $_POST['password'];

if (($user_name == 'shaolin') && ($password == 'shaolin')) {
$_SESSION['username'] = $user_name;
echo $_SESSION['username'];
}
else {
echo "login Failed";
}


After I log n with 'shaolin', 'shaolin' the script returns 'shaolin' which would be the Session variable so it's definately set... now the troubles start...

Now I should be logged in and when I try to access my index.php which has the first coderow like:

include 'verifyuser.php';

and... Verifyuser.php has this code:
//CHECK IF USER IS LOGGED IN

session_start();
if(empty($_SESSION['username'])) {
$VerifiedUser = "false";
echo 'Session variabel not set';
}
else {
$VerifiedUser = "true";
echo $_SESSION['username'];
}


.. it returns 'Session variable not set'.. so I wonder where my SET SESSION VARIABLE went... why does'nt my loginscript work? What can I do, please help?

thank you/
Lars Netzel
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

it looks like you haven't started the session in validateuser.php. add the session_start() to the top of that script.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

put session_start(); at the top of validateuser.php
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

great minds think a like :D !!!
lnetzel
Forum Newbie
Posts: 4
Joined: Sun Oct 20, 2002 1:53 pm

Thank you... but still more problem

Post by lnetzel »

The help you guys gave solved my problem.. very grateful.

Now I can't logout:)...

I created this logout.php which only has this code:


<?
session_destroy();
?>


But it gives me this message:

"Warning: Trying to destroy uninitialized session in logout.php on line 2"

What does this mean? Or is this not the proper way to logout

thank you/
Lars Netzel
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

put

Code: Select all

session_start();
at the top.
Post Reply