Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post

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

    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.
    -DR.Wong

    Wheres the food at?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post
    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?
    -DR.Wong

    Wheres the food at?

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    To link out of a subdirectory to the index page at the next level up use ../index.php
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    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.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #7
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post
    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
    -DR.Wong

    Wheres the food at?

  • #8
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    No, the session does not die if you use absolute links. marek_mar answered your question in the first reply:

    Quote Originally Posted by Marek Mar
    2) It's the domain that matters to the session cookie and the querystring sid, if cookies are not used.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post
    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!)
    -DR.Wong

    Wheres the food at?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •