[SOLVED] undefined indexes

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
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

[SOLVED] undefined indexes

Post by pleigh »

hi there...got a problem here....i have this error, undefined indexes...refers to the session keys that the script is calling...this happens when i access, for example, the index page, without logging in....the page requires to validate the session keys i've defined.....now, my idea is that users are limited in accessing the page by redirecting them to the login page.....i have done the following code

Code: Select all

if ($_SESSIONї'key'] == NULL)
{
header('location: login.php');
}
else
{
session_start();
require_once('mysql_connect.php');
}
it worked but when i tried to login, it redirects me to the login page again, though, the usename and password is correct
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

thanks feyd....i did this

Code: Select all

if (isset($_SESSIONї'userID']))
{
	header('Location: login.php');
}
else
{
session_start();
require_once ('dbconnect.php');
}
but it opens the index page, or other pages, instead of redirecting to the login page....undefined indexes still prompts me....
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you probably want to move that session start...

and you probably want to try if(!isset())

since you want to determine if the session var exists.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

i did this

Code: Select all

if (!isset($_SESSIONї'userID']))
{
	header('Location: login.php');
}
it redirects, but the same problem occur during login....it doesn't log me in my index page
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

did you move the session start?

if not, then it won't know that the session var is defined?
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

yes, i removed it but the same thing happens....
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

not REmove...just move it above the isset

otherwise, it'll never be set on that page and it will always redirect you.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

[SOLVED]

Post by pleigh »

thanks....it perfectly works well now....
:)
Post Reply