Jump to content

PHP Sessions drop/reset when a hyperlink to a site page is clicked


riT-k0MA

Recommended Posts

Hi.

 

The site I'm trying to sort out is hosted on a Linux webserver running Apache version 1.3.34, PHP version 4.4.4-8 and MySQL version 5.0.32.

 

I built the site on my own PC, running WinXP Pro, Abyss version 2.6.0.0, PHP version 5.2.0 and the same mySQL instance as the webhost, version 5.0.32.

 

I coded the site and it worked perfectly as localhost. I changed the hyperlinks to what they should be on the webserver and uploaded it.

 

One has to enter the site through a PHP-based login screen. The login page calls up the Welcome Page, which checks a mySQL DB for the username and password, validates it, then queries the same DB for some other fields. The Welcome Page then shows some links, menu-style, based on what the user's access privellages are.

 

Every page has a session_start() at the top, before any other code.

 

The problem I'm having is that the session seems to reset (The session ID is different) everytime the user clicks on a hyperlink.

(It never does, or did, on my computer, whether on localhost or webhost.)

I've tried this on three other computers, and all three do the same thing.

 

I was wondering if it was the way I'd structured my website:

 

    Main

    |_ Login.php

    |_ Welcome.php

    |_ menu.php

    |_ Logout.php

    |_ Users

    |  |_ UserPage1.php

    |  |_ UserPage2.php

    |  |_ UserPage3.php

    |  |_ Functions

    |      |_UserFunction1.php

    |      |_UserFunction2.php

    |_ FAQ

    |  |_ FaqPage1.php

    |  |_ FaqPage2.php

    |  |_ FaqPage3.php

    |  |_ Functions

    |      |_FaqFunction1.php

    |      |_FaqFunction2.php

etc.

 

Each page in the site calls the menu.php in the site root. Each hyperlink in the menu starts from the root (/usr/htdocs/main/Users/Page.php). It was the only way I could get the hyperlinks to work.

Could this be what's terminating the session?

 

or is it a problem with different PHP versions?

If it is different PHP versions, why does it work perfectly on my PC?

 

Hours of googling yesterday got me absolutely nowhere.

 

I would really appreciate any sort of clue as to why this is happening. Even if you only have a small hunch or gut-feel, it'd be more than I've got.

 

Thanks an epic amount in advance

riT-k0MA

 

PS: If you need some code to test this out, I'll have to make some for you. I can't show any of my actual code due to one of those hated Contractual clauses.

Link to comment
Share on other sites

What does a phpinfo() statement show for session.cookie_path and session.cookie_domain and do the URL's consistently use www.yourdomain.com or yourdomain.com and not a mix or www. and no-www.?

 

For debugging, add the following two lines immediately after your first opening <?php tag on your main pages (the pages in the URL) -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

 

 

Link to comment
Share on other sites

Hi. Thanks for replying.

 

session.cookie_path = "/"

session.cookie_domain has no value. I am unable to change any configurations as the hosting company does not want them changed for security reasons.

 

Every hyperlink in the menu uses a path similar to "/usr/htdocs/main/Users/Page.php"

 

I added that code you suggested and got the following error:

"

Notice: A session had already been started - ignoring session_start() in /usr/www/<deleted>/Menu.php on line 3

"

 

Tried using this:

if (isset($_SESSION['SessionUserID']))
{
	//do nothing
} 
else 
{
	echo"Starting Session <br />";
	session_start();
}

 

and got:

"

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /usr/www/<Deleted>/Welcome.php:9) in /usr/www/<Deleted>/Welcome.php on line 10

"

 

So I tried disabling the Session_start() on each page but the Welcome Page and got:

"

Notice: Undefined variable: _SESSION in /usr/www/users/vector/VectorTechBETA/VectorLogin/Functions/EditUserBody.php on line 6

"

 

Either I'm a total frikking idiot, am missing a brain and need to be beat about the head with a cluestick, or there's an error in this.

 

I'm hoping it's the former. Brainless Idiots can be cured

Link to comment
Share on other sites

Every hyperlink in the menu uses a path similar to "/usr/htdocs/main/Users/Page.php"

That is a server file system path and it has no meaning when used in a URL. URL's of pages are requested by the browser and they are either absolute - http://www.yourdomain.com/your_path/your_file.ext or they are relative to the current URL - some_path/your_file.ext or relative to your document root folder - /your_path/your_file.ext

 

Fix your links first or post an actual example of what your menu looks like.

 

You can set the session cookie parameters anywhere you want, even in your script - http://us.php.net/manual/en/function.session-set-cookie-params.php, though the current settings would work as long as you are not switching between www. and no www. on your URL's which you did not bother to answer.

Link to comment
Share on other sites

Sorry for the long time it took me to reply. I've been on sickleave for the last few days, which could also explain why my last post was a bit muddled.  :P

 

Every menu link uses the following formula:  http://www.site/folder/file.php

Every Require() statement uses the following formula: /usr/htdocs/main/Users/Page.php.

 

I have not mixed www. and no www.

 

Should I use the full path (http://.....) for my Includes Requires?

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.