|
-
Feb 18th, 2010, 10:47 AM
#1
Thread Starter
Frenzied Member
[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.
-
Feb 18th, 2010, 11:01 AM
#2
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.
-
Feb 18th, 2010, 11:06 AM
#3
Re: Session problem
and don't use javascript to redirect. use headers.
PHP Code:
header("Location: http://mysite.com/main.php");
-
Feb 18th, 2010, 11:26 AM
#4
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|