Jump to content

Problem showing same $_session value in two files


aladdin249

Recommended Posts

Using PHP 4.4.6

in PHP.ini (session area)

Session Support enabled

Registered Save Handelers files user

 

login.php:

<?

session_start();

.. some other php code

      session_start();

        $_SESSION['user_login'] = 1;

        session_register('user_login');

        header ("Location: http://siteAddress/index.php");

.. some other php code

?>

 

in index.php

<?

session_start();

.. some other php code

if (isset($_SESSION["user_login"]) && ($_SESSION["user_login"]) == 1 ) {

  echo 'I am logged on';

} else {

  echo 'I am NOT logged on';

}

.. some other php code

?>

Whet it re-directs to index.php, it always shows me 'I am NOT logged on'

instead of 'I am logged on'

 

Any help? Thanks

 

 

 

 

Link to comment
Share on other sites

Remove the 2nd session_start() in login.php, remove session_register('user_login');

In index.php, echo $_SESSION['user_login'], if its empty, check your session save path in your php.ini

Don't direct to a absolute URL like http://siteAddress/index.php, but instead direct to index.php.  If you go to login.php with www.siteAddress.com and it directs to siteAddress.com, they are not the same and the session will be different.

Link to comment
Share on other sites

ThANKSSSSSSSSSSSSS - it worked

 

A short follow-up Q?

The session-path in php.ini is:

 

session.save_path = ".\"

 

Now I have to check if session works with other files in subdirectories as well.

Would you suggest anything with the path? or any suggestion for the .php files sitting in the subdirectories.

Thanks Again!!!!!

Link to comment
Share on other sites

It did work for the two files I mentioned above. These two files (login.php, index.php) are in the base dir.

 

But now when I check my $_SESSION in the subdirectory, it is not recognizing??

i.e www.sitename.com/html/anotherfile.php

and login.php, index.php are in the main dir (www.sitename.com)

 

This what I have for php.ini (or provide from the host provider):

[session]

session.save_handler = files

session.save_path = ".\"

session.use_cookies = 1

session.name = PHPSESSID

session.auto_start = 0

session.cookie_lifetime = 0

session.cookie_path = /

session.serialize_handler = php

session.gc_probability = 1

session.gc_divisor    = 1000

session.gc_maxlifetime = 1440

session.bug_compat_42 = 0

session.bug_compat_warn = 1

session.referer_check =

session.entropy_length = 0

session.entropy_file =

session.cache_limiter = nocache

session.cache_expire = 180

session.use_trans_sid = 0

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

 

Any idea????

 

 

Link to comment
Share on other sites

session.save_path should be an absolute path not a relative path. Set the session.save_path directive within the php.ini to:

session.save_path = "C:/php_sessions/

Create the folder php_sessions within the root of the C: drive. Save php.ini and restart your server (Apache or IIS). Retest your scripts and your sessions should work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.