Yuval200 Posted November 4, 2006 Share Posted November 4, 2006 Hello again guys :)This time I have a PHP problem regarding sessions. So basicly I have three pages, one is cplogin.php that works fine and isn't relavent, get.php and admincp.php. This is get.php: <?php include_once("data.php"); if ($form_name && $form_content != "") { mysql_query("INSERT INTO posts (post_sender, post_content, post_date, post_id) VALUES ('$form_name', '$form_content', '$form_date', NULL)", yp_mysql_connect); header("Location: main.php?page=outpost"); } elseif ($cplogin != "") { if ($cplogin == "****") { session_start(); $_SESSION['cpacaccess'] = 'true'; header("Location: main.php?page=admincp"); } else header("Location: main.php?page=cplogin&error=true"); } else header("Location: main.php");?> I censored the pass if you don't mind..and admincp.php: <?php if (isset($_SESSION['cpacaccess'])) echo <<< END <div id="container">Hello </div>END;else echo "2";?> The header redirects fine, the problem is with the session, it didn't echoed a thing, so I add the else part, and it echoed "2", so the session is not set. Why?Thanks in advance Link to comment Share on other sites More sharing options...
skym Posted November 4, 2006 Share Posted November 4, 2006 You need session_start() before using the $_SESSION:admincp.php<?phpsession_start();if (isset($_SESSION['cpacaccess'])).... Link to comment Share on other sites More sharing options...
shylor Posted November 11, 2006 Share Posted November 11, 2006 Not trying to highjack the post, but does session_start() have to be on every page? Link to comment Share on other sites More sharing options...
reportingsjr Posted November 11, 2006 Share Posted November 11, 2006 Yes, it must be on every page you want to use sessions on. Link to comment Share on other sites More sharing options...
shylor Posted November 11, 2006 Share Posted November 11, 2006 Thanks, It works now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now