View Full Version : Do sessions die if links contain http:// etc.. ??

12-29-2006, 10:44 AM

I am still busy learning about sessions for my user system and I have just tried to implement it into my site, the only thing is..

I have a main menu page that is included in every one of my sites pages, this is where the session_start() line is, since some of my pages are located in sub directories I have set it so that each link contains the FULL path including the http://www. .... .com

If I use a link like this, I lose all the info in my session.. is this right??

Can someone tell me a few of these little tricky things about sessions?

Thanks a lot and happy holidays to all.:)

12-29-2006, 12:47 PM
1) You don't have to use absoulyte URLs if you want to link to a subdirectory
2) It's the domain that matters to the session cookie and the querystring sid, if cookies are not used.

12-29-2006, 01:00 PM
okay, sorry, I was not clear in my first post..

1) The only reason I have absolute links on my menu is so I can get OUT of sub directories, if I am in mysite.com/content/page1.php, I cant have the menu (that is in my root) link to index.php as it will go to a non-exsistant page.
2) I am linking to my site, not another.. I dont know what you mean by its the domain that matters.. but its not like I am navigating to another site.

Anyone else know anything about this?

12-29-2006, 01:09 PM
you need to use an absolute path for your include if it includes PHP code that you do not want pre-parsed e.g.

include_once '/home/user/www/include.php';

else yes you will lose your session_start() since anything accessed via a url will be parsed by PHP before it gets included

12-29-2006, 09:16 PM
To link out of a subdirectory to the index page at the next level up use ../index.php

12-29-2006, 10:28 PM
You could morph your links on server side with php, just find out which directory you are in, by putting your whole page through an output buffer or something similar. Although this gets messy, slow, and unreliable.

You really want the HTML base tag. You specifiy the "base" of your application url, and all links will be relative from that location, not the current location. Hope this helps you.

12-30-2006, 09:27 AM
fegall : The point is that the menu stays the same throughout the whole site.. the pages in subdirectories include it as ../head.php

xconspirisist : That sounds pretty cool, I guess I will use that if I have to..

But I still didnt get a yes or no answer about my original question.

Does the session die if I use an absolute link

eg : does this die? http://www.mysite.com/mypage.php

and this does not? ../mypage.php

12-30-2006, 03:42 PM
No, the session does not die if you use absolute links. marek_mar answered your question in the first reply:

2) It's the domain that matters to the session cookie and the querystring sid, if cookies are not used.

12-30-2006, 04:09 PM
Yes the session does die if you use a url (http:// etc) since the included page gets parsed as a separate request from the calling page, it knows nothing about the session in the calling page & vice-versa

And your question has been answered, use absolute or relative path's not url's

12-30-2006, 04:19 PM
Great. Thanks, I just needed a bit of clarification.

Cool things!!!

Thanks everyone! And Happy New Year for Tomorrow (At least it is in South Africa!)