Results 1 to 4 of 4

Thread: [RESOLVED] Session problem

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Resolved [RESOLVED] Session problem

    Hello everybody,

    I use session variables quite frequently bus this time when I set variable in one page and try to access it on another page, its just empty. Here's my code:

    Page 1:
    Code:
    <?
    	include "../includes/connect.php";
    
    	$_SESSION["admin"] = "yes";
    	echo "<script>location.href='main.php'</script>";	
    ?>
    Page 2:
    Code:
    <?
    	session_start();
    	echo $_SESSION["admin"];
    	exit;
    	
    	include "../includes/connect.php";
    ?>
    Please let me know what I am doing wrong here?

    Thanks.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Session problem

    You need to use session_start() before doing anything with session variables (echoing or setting them) - so add it to the top of your first bit of code.

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

    Re: Session problem

    and don't use javascript to redirect. use headers.

    PHP Code:
    header("Location: http://mysite.com/main.php"); 

  4. #4

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: Session problem

    Great, thanks.

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