Page 1 of 1
SESSION variables, how do I know they have been set?
Posted: Tue Jun 01, 2004 2:40 pm
by jonas
Code: Select all
if (($active == 1) && ($powerlevel == 4)){
$_SESSIONї'user'] = $_POSTї'user'];
$_SESSIONї'powerlevel'] = $powerlevel;
$_SESSIONї'active'] = $active;
print("<br><div align="center">You have been authorized to work in the admin area, redirecting in 5 seconds...
<script type="text/javascript" src="http://www.bolt3.com/redirect.js"></script>
<script type="text/javascript">
var redirect = new Redirect("http://admin.bolt3.com/admin.php");
redirect.delay(5);
redirect.write();
redirect.go();
</script>
<br>
<a href="http://admin.bolt3.com/admin.php"> Click here to go to the Admin section immediately</a></div><br>");
} else {
print("You are not authorized to view this area.");
}
This is my code for a login I'm trying to make (an Admin login) and this page is fine. It works and I can login if I have the right power level.
Thing is, I set the SESSION variables in this code as you can see and when it redirects to the admin page.. I want to make sure the person just didnt type in the admin url so I recheck to see if SESSION powerlevel is 4, if it isnt they dont get access.
It doesn't seem to be working though. I tried to go $user = $_SESSION['user']; to see if it's setting and I put $user on a page but it displays nothing.
So what am I doing wrong? I remember something about a startsession.
Basically when they login I want it to remember these 3 variables on all pages but not using cookies using sessions.
Thanks.
Posted: Tue Jun 01, 2004 2:48 pm
by feyd
stupid question: session_start() is in the admin.php page?
Posted: Tue Jun 01, 2004 2:52 pm
by PrObLeM
make sure they are getting set and if what they are set with isnt just blank space
Code: Select all
if(!isset($_SESSION['user']))
{
echo 'SESSION NOT SET...baby jesus weeps';
}
else
{
echo 'SESSION SET the value is ' . $_SESSION['user']:
}
Posted: Tue Jun 01, 2004 2:52 pm
by pickle
Posted: Tue Jun 01, 2004 3:13 pm
by jonas
feyd, nope it isnt. how do i do that. ive been self teaching myself session variables from topics on these boards.
any help ? thanks (show examples would be best!)
Posted: Tue Jun 01, 2004 3:15 pm
by feyd
add session_start() just after the beginning of the file (inside php tags) similar to this:
Code: Select all
<?php
session_start();
// other code
?>
this needs to be in each and every page that you want to access session variables in..
Posted: Tue Jun 01, 2004 3:26 pm
by jonas
nice, ok i got it working with your help!
One question, session variables only stay until the browser is closed, correct?
Posted: Tue Jun 01, 2004 3:33 pm
by feyd
that's how they normally work, yes.
Posted: Tue Jun 01, 2004 3:34 pm
by feyd
that's how they normally work, yes.
Posted: Tue Jun 01, 2004 3:47 pm
by jonas
Ok I ran into another problem.
Code: Select all
<?
include("../dbcon/connect_db.inc.php");
session_start();
print_r($_SESSION);
if ($_SESSIONї'powerlevel'] = 4){
print("<HTML>
<HEAD>
<TITLE>Admin Options</TITLE>
</HEAD>
<link href="http://admin.bolt3.com/admincss.php" rel="stylesheet" type="text/css">
<table bgcolor="#86846B" width="100%" height="100%" class="regpart2">
<tr>
<td valign="top">
<div align="center">
<a href="main.php" target="main">MAIN</a><BR/>
<a href="addagame.php" target="main">ADD A GAME</a><BR/>
</div>
</td>
</tr>
</table>
</HTML>
");
} else {
print("<HTML>
<HEAD>
<TITLE>No access</TITLE>
</HEAD>
<link href="http://admin.bolt3.com/admincss.php" rel="stylesheet" type="text/css">
</HTML>
");
}
?>
Basically only people with powerlevel of 4 are allowed in the admin section but this isnt working. If you go to
http://admin.bolt3.com/admin.php (the redirect url) it still displays... shouldn't it display the else since powerlevel is not 4?
In this example the navigation bar (left frame) should just be blank if its not powerlevel = 4
Posted: Tue Jun 01, 2004 3:49 pm
by feyd
if ($_SESSION['powerlevel'] = 4){
you're setting $_SESSION['powerlevel'] to 4..
Posted: Tue Jun 01, 2004 3:52 pm
by jonas
lollerskates.
thanks haha