Dear Noel Wade,

I've been coding session for quite sometime, but this is the first time i
encounter such problem...

in the login.php page, i've tested out
session_is_registered("userkey");

it was TRUE.

but when i redirect it to main.php
and did a checking on session_is_registered("userkey");
it return FALSE...

i've session_start(); at every start of the php page...

what's wrong?
I've output session not set on main.php when the userkey session is not set.
when i click on back button and retry login, it works!!! what happened?

please check my code again...

==============login.php==================
include "lib/mysql.php";
include "lib/u007lib.php";

// connecting to mysql db , my own lib...
$rs = getdb("");
$rs->query("select * from ct_user where companyid like '" .
$HTTP_POST_VARS["companyid"] .  "'");
$rs2 = getdb("");

$erron = "";

if(!$rs->eof)
{

// if company records found...
$rs2->query("select * from ct_login where loginid like '" .
$HTTP_POST_VARS["loginid"] . "' and userid=" . $rs->fields("id") . " and
pass like '" . $HTTP_POST_VARS["password"] . "'");

if(!$rs2->eof)
{
// if loginid and password match...

session_start();
// session key to be checked...
$userkey = $rs2->fields("lvl");

$userid = $rs2->fields("id");
$userloginid = $rs2->fields("loginid");

$usercomid = $rs->fields("id");
$usercompany = $rs->fields("company");
$usercompanyid = $rs->fields("companyid");

// registering session key
session_register("userkey");
session_register("usercomid");
session_register("usercompany");
session_register("usercompanyid");

session_register("userid");
session_register("userloginid");


setcookie("companyid", $HTTP_POST_VARS["companyid"], time()+(60*60*24*30));
setcookie("loginid", $HTTP_POST_VARS["loginid"], time()+(60*60*24*30));

//redirecting to main.php
//header("location: main.php"); exit();
if (session_is_registered("userkey")) { header("location: main.php");
return;  }
else { echo "session not set!"; } //  always return TRUE...

}
else
{
$erron = "Invalid User / Password";
}

}
else
{
$erron = "No Such Company ID";
}

?>
=============end of login code========================

=============beginning code of main.php=================
<?
session_start();
include "lib/u007lib.php";
include "lib/mysql.php";

// check session userkey
if (!session_is_registered("userkey")) { echo "session not set!"; exit(); }
// RETURNED FALSE HERE? Y?

if($HTTP_SESSION_VARS["userkey"]-0 < 1) { header("location: ./"); return; }
?>
==============end of main.php code=====================



best regards,

James

"Noel Wade" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> James -
>
> Don't know how you're working with Cookies and sessions for sure, but the
> default / "easy" way to check for an established session is to put
> "session_start();" at the top of every page that's going to access the
> session variables.  That will check for an established/open session and
make
> the registered session variables accessible to the page.
>
> Then a logical check is as simple as using "session_is_registered()" like
> this:
>
> if (session_is_registered("registered_variable_name"))
>     //do something here if the person has already registered their session
> else
>     //session not registered!
>
> Hope this helps!
>
> Take care,
>
> --Noel
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to