Add session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
acwe88
Forum Newbie
Posts: 24
Joined: Tue Nov 07, 2006 10:47 am

Add session

Post by acwe88 »

Hi there

I need to add a session to my page that Gets A value from the database and according to that value it redirects the user to a particular part of the site

any ideas anyone?

any help will be much appreciated

Thanks
Al
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

I don't see why you need a session, do your query then do the redirect...

Code: Select all

// db connect, select here

$query = mysql_query ( "SELECT permission FROM users WHERE uid = " . $user['id'] );

$test = mysql_fetch_assoc ( $query );

switch ( $test['permission'] )
{
	case 0 :
	$page = 'login.php';
	break;
	case 1 :
	$page = 'admin.php';
	break;
	case 2 :
	$page = 'members.php';
	break;
}

header ( 'Location: http://www.site.com/' . $page );
exit ();

printf
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

session_start() starts a session, then you can access variables like this:

Code: Select all

<?
session_start();

$_SESSION[$variableName] = "whatever";

?>
-wyrmmage
Post Reply