can't get my session working

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

cho@
New php-forum User
New php-forum User
Posts: 39
Joined: Tue Aug 06, 2002 8:58 am
Location: UK

can't get my session working

Postby cho@ » Wed Sep 17, 2003 7:18 am

Hi,


I m creating a session after a user login...
here an extract where I create it

Code: Select all

if($found ==1){
                     $Result = mysql_query("SELECT * FROM user WHERE user='$user'", $Link);
                     $Row = mysql_fetch_array($Result);
                     session_start();
                     session_register('privileges');
                     session_register('status');
                     $HTTP_SESSION_VARS['privileges'] = $Row['privileges'];
                     $HTTP_SESSION_VARS['status'] = $Row['status'];
                     
      }


Then further in my page I have a link to some other page...normal you will say.. but then I dont understand...
In this new page I do session_start and when I do session_id();
I get the SID BUT when I do

Code: Select all

print($HTTP_SESSION_VARS['status']);


There is nothing output.. Why my Array is empty???

Help please....

thanks
francois

DigitalRice
New php-forum User
New php-forum User
Posts: 29
Joined: Fri Jun 27, 2003 10:05 pm

Postby DigitalRice » Wed Sep 17, 2003 4:09 pm

as far as i know, the session_start() function should be the first line of your code meanning that it should be the first line of code prior to any output from the server including blank space.

it should be something like this.

<?php
session_start();
?>

<html>
your html stuff here or mix php stuff here
<?php

?>
</html>

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

sid

Postby ruturajv » Wed Sep 17, 2003 9:18 pm

Are u sure you are passsing SID

as follows

Code: Select all

echo("<a href='somepage.php" . SID . "'>Somepage</a>");

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Re: can't get my session working

Postby Redcircle » Wed Sep 17, 2003 10:52 pm

cho@ wrote:Hi,

Code: Select all

if($found ==1){
                     $Result = mysql_query("SELECT * FROM user WHERE user='$user'", $Link);
                     $Row = mysql_fetch_array($Result);
                     session_start();
                     session_register('privileges');
                     session_register('status');
                     $HTTP_SESSION_VARS['privileges'] = $Row['privileges'];
                     $HTTP_SESSION_VARS['status'] = $Row['status'];
                     
      }



thanks
francois


If you are using php 4.1 or greater then you should be using superglobals i.e. $_SESSION[''] and not session_register.

check the stickies for some info on this.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron