Forums

PHP

This topic is locked

How to add a session

Posted 08 Nov 2006 17:34:04
1
has voted
08 Nov 2006 17:34:04 alex webb posted:
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

Replies

Replied 09 Nov 2006 03:03:53
09 Nov 2006 03:03:53 LorD ExoskeletoN replied:
hi there, you can start a session by

// 1) put this at the very first line of the page

session_start();

// 2) putting a value to the session from the database, first run a SQL query of course like this for example

$SQL="SELECT username FROM tbl_user where username='$user'";
$Execute = @msyql_query($SQL) or die(@mysql_error());

while ($field=@mysql_fetch_array($Execute)) {

$username = $field['username'];

// 3) saving value to session variable
$_SESSION['variable_name']= $username;

}

Hope this helps...good luck!!!


Reply to this topic