...

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



DR.Wong
12-29-2006, 09:44 AM
Hi!

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.:)

marek_mar
12-29-2006, 11:47 AM
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.

DR.Wong
12-29-2006, 12: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?

firepages
12-29-2006, 12: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

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

xconspirisist
12-29-2006, 09: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.

DR.Wong
12-30-2006, 08: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

xconspirisist
12-30-2006, 02: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.

firepages
12-30-2006, 03: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

DR.Wong
12-30-2006, 03: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!)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum