SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Apr 30, 2005, 11:25 #1
- Join Date
- Mar 2004
- Location
- scotland
- Posts
- 20
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
having difficulty passing session variable
I have made a simple login using the following code.
PHP Code:<?php
include 'db.inc.php';
if(isset($_POST['submit']))
{
$email = $_POST['email'];
$acode = $_POST['acode'];
$sql = "SELECT acode FROM dealers WHERE email='$email'";
$result = @mysql_query($sql);
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
while($row = mysql_fetch_array($result)){
$bcode = $row['acode'];
}
if($bcode == $acode)
{
$_SESSION['authorized'] = TRUE;
}
}//end of if isset submit
if(isset($_REQUEST['logout']))
{
unset($_SESSION['authorized']);
}
if(isset($_SESSION['authorized']))
{
?>
DISPLAY THE PAGE CONTENT
What I want to do is get nrb.php to either display its contents or redirect back to index.php to login, depending on whether or not the dealer is logged in; but I can't get it to work.
No matter what I try, typing localhost/folder/nrb.php into the address bar of the browser just shows it to me.
I was basing it on various incarnations of, "if the session variable is not set to true, send them to index.php to login," but no joy.
Any answers greatly appreciated.
-
Apr 30, 2005, 12:08 #2
- Join Date
- Jul 2004
- Location
- canada
- Posts
- 3,193
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
where are you putting session_start()
it shoupld be very first line on EACH AND EVERY PAGE, where you want to use session.
(first line means before anything goes out to browser and before you start using SESSION VARIABLES)
-
Apr 30, 2005, 14:45 #3
- Join Date
- Mar 2004
- Location
- scotland
- Posts
- 20
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you. I didn't have start_session at the top of the index page. Thanks for the prompt reply as well. Thought this one was going to keep me awake tonight!
-
Apr 30, 2005, 14:46 #4
- Join Date
- Jul 2004
- Location
- canada
- Posts
- 3,193
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Glad to help you.
enjoy you night
Bookmarks