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 6 of 6

Thread: Session Problem

  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session Problem

    I want to start a session on a page, assign a value to a session variable then display it on another page. I've broken it down as simple as possible, and I still can't get it to work!!

    Page 1

    PHP Code:
    <?
    session_start
    ();
    $_SESSION['value'] = "Hello World";

    ?>
    Page 2

    PHP Code:
    <?
    session_start
    ();
    echo 
    $_SESSION['value'];
    ?>
    Only value I changed in the php.ini was

    session.save_path = C:\temp

    Can anyone offer any advice to get me goin?

  • #2
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using version 4.3.4 and phpinfo() says Session Support is enabled.

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Welcome here.

    I have no idea, based on the code you showed, i'd suspect it to work.

    Maybe 'value' isn't the most sensible variablename you could choose but i doubt if that is the problem (but you soon findout ifyou change it). Is there any other code in these pages? If so,try moving these lines to the very top of your script on both pages.

  • #4
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I look inside the session files and I can see

    myvar|s:9:"Hello";

    So this tells me its writing variable myvar, but I just can't get it to read properly. Any advice? I've tried reinstalling PHP. I dont want to use an older version of php... do I?

  • #5
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session Problem

    The problem may be in how you are transitioning from page 1 to page2. Specifically, if you are using a header() call you must supply a fully qualified URL, meaning give a complete URL specification to the header such as

    header( 'Location: http://www.yourdomain.com/path_to_web_page' )

    I had trouble with only supplying relative paths to web pages and session variaibles.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Indeed. You can dynamically build these like:
    PHP Code:
    header('Location: [url]http://[/url]'.$_SERVER['HTTP_HOST']
                   .
    dirname($_SERVER['PHP_SELF'])
                   .
    '/filename.php'); 
    This way, the redirect will generate a call to the webserver. I suppose i will only matter if you have cookies disabled, because the sessionID then need to be added to each request. With a serverside redirect, this iw probably not the case (not sure though)

    Also, try renaming the sessionvariable --> if you have another variable called "$value", then your code will not work on certain servers. (I know i have that problem with one of my hosts)


  •  

    Posting Permissions

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