Strange Error with PHP Sessioning

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
genesigalov
Forum Newbie
Posts: 1
Joined: Sat Jun 14, 2003 5:52 pm

Strange Error with PHP Sessioning

Post by genesigalov »

I am having a strange issue with php sessioning. It's pretty much the same code i have used over and over again on many different platforms and versions of php but on my most current host, it doesnt seem to function. Maybe someone here can help me clarify this problem.

Code for starting the session and registering my session vars when logging in... I pull the user info from a mysql members table and assign fields to vars. all that functions correctly.

// approved is from a db field in the members table . 0[off]/1[on]. yes it's set :)
if($approved==1) {
session_start();
// memid pulled from db, yes i am sure that $memid is set;)
session_register("memid");
// fname pulled from db, yes i am sure that $fname is set;)
session_register("fname");
header("Location: members.php\r\n");
} else {
header("Location: login.php\r\n");
}

this functions fine.

In members.php, i have the following to check for the session.

<?
session_start();
if(session_is_registered("memid")) {
// display members page. this functions fine.
} else {
header("Location: login.php\r\n");
// no session, plop back to login.php page. works fine.
}
?>

However... when i duplicate that chunk of code for members.php into other pages, i am plopped back to the login.php. I dont understand the problem. Certain pages using this sniplet function.. others dont. I have tried debugging via echo $HTTP_SESSION_VARS['memid'];exit(); and the faulty pages do not display the memid.

Thanks alot for reading this far. If you have any input or ideas please let me know. Thanks!
void
Forum Newbie
Posts: 3
Joined: Sat Jun 14, 2003 5:21 pm

Post by void »

Try with

Code: Select all

<?php

session_start();
if(isset($_SESSION['memid']) {
// display members page. this functions fine.
} else {
header("Location: login.php\r\n");
// no session, plop back to login.php page. works fine.
} 

?>
it might work...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The code you are using is a bit outdated and won't work on new default installations of PHP - did you have a read of:
Before Post Read: Sessions with a Minor in User Logins

Mac
Post Reply