|
Posted by SA SA on 07/12/07 18:04
Hello i am not PHP expert - i need help big time.
i am having issue with PHP session i think. I have two page login.php
and admn.php As name implied login to log in to admin page manage
database. But as soon as session initiated and passed to admin.php -
the session variable fails and it always default to else section in
php. And again - that what i think i may be completely off base.
Here is the part of the code:
login.php
<?
session_start();
$expiry = 60*60; //1hr in seconds
setcookie(session_name(), session_id(), time()+$expiry, "/");
?>
.....
.....
.....
else //FORM SUBMITTED
{
include ("config.php");
//validate username and pass
$user_name = $HTTP_POST_VARS['username'];
$pass_word = $HTTP_POST_VARS['pass'];
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");
mysql_select_db($db) or die (mysql_error());
$query = "SELECT * FROM ".$users_table." WHERE username =
'$user_name' AND password = '$pass_word'";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 1)
{
//valid pass
$row = mysql_fetch_object($result);
if (!empty($row))
{
//session_unregister( "USER" );
session_register( "db_user", "db_cat", "db_username",
"db_name" );
$db_name = $row->first_name." ".$row->last_name;
$db_username = $row->username;
$db_user = md5($db_username);
$db_cat = $row->category;
echo "<div style='text-align: center; font-family: verdana; font-
size: 13px'><b>Log-in Successful.</b>
<br>Remember to log-off when finished.<br><br>Redirecting to <a
href='admin.php'>Admin Page</a>...</div>";
echo "<meta http-equiv=\"refresh\" content=\"1;URL=admin.php\">";
}
Admin.php
<?session_save_path("/tmp");
session_start();?>
<?
if ( isset ($db_cat))
{?>
<?}
else
echo "<meta http-equiv=\"refresh\" content=\"1;URL=login.php\">";?>
[Back to original message]
|