Results 1 to 3 of 3

Thread: Sessions Help

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Sessions Help

    I am working on my register page.

    I start the session at the top of my php file:

    Code:
    <?php
    
    	// Lets start the session
    	session_start();
    After form/data validation I create some session variables ($username comes from the HTML textbox and $insertedId comes from a select statement):

    Code:
    			// Lets set a few session variables
    			$_SESSION['userName'] = $username;
    			$_SESSION['userId'] = $insertedId;
    Once sesssion variables are set I change locations to another php file:

    Code:
    			// Lets get out of here ...
    		 	header("Location: home.php");


    now, I am in home.php and I try to print my session variables:

    Code:
    <?php  
    
    			echo "userName=". $_SESSION['userName'];
    			echo "userId=". $_SESSION['userId'];
    
    ?>


    This is the error message I get:

    Notice: Undefined variable: _SESSION in C:\wamp\www\TheLastPick\home.php on line 45
    userName=
    Notice: Undefined variable: _SESSION in C:\wamp\www\TheLastPick\home.php on line 46
    userId=



    Any idea why my session variables aren't accessible in home.php?

    Many thanks for any help.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Sessions Help

    you need to be using session_start() on every page that uses sessions. this function also resumes sessions, and doesn't just begin them. just place that at the top of your home.php page and everything should be fine.

  3. #3

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Re: Sessions Help

    One word, gangster ...

Posting Permissions

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



Click Here to Expand Forum to Full Width