[PHP] Cookies Help

2002-12-12 Thread Sean Mayhew
Ive created a log in that essentially if the username and password are found
in the database it displays one section of code and if its not found it
display another log in form

Im able to log in and my verifylogin() function works because if the
username and password are not found it displays the login form again but
when I click a link to another page that uses my admin class it just
displays that second log in form as if the username and password are not
carrying over I know this has something to do with my session_start or
something but I've no idea I'm very new to sessions and cookies:

Here is my page admin page display:

?
session_start();
session_register($employeeid,$password);
include ('include/adminclass.php');
$adminroot = new adminpage();
$title = Administration Portal;

$redux = Hello Some Temporary Content;
$adminroot-SetContent($redux);

$toolsneeded = admin;
$adminroot-SetToolsNeeded($toolsneeded);
$adminroot-Display($employeeid,$password,$title);
?


Here are the relevant parts of my class file:


##
##CLASS DECLARATION
##
class ADMINPAGE
{


##
##DISPLAY FUNCTION
##
function Display($employeeid,$password,$title)
 {
 $count = $this - VerifyLogin($employeeid,$password);
 switch($count)
  {
  case 1:
   $this - DisplayHeader($title,$employeeid);
   echo centerbrtable width=\500\trtd;
   $this - DisplayMenu($this-buttons);
   echo br;
   $this - DisplayContent($this-toolsneeded,$this-content);
   echo /td/tr/table/centerbr;
   $this - DisplayFooter();
   break;

  default:
   $title = Please Try Again;
   $employeeid = ;
   $password = ;
   $this - DisplayHeader($title,$employeeid,$password);
   echo centerbrtable width=\500\trtd valign=\top\;
   echo Your username and password combination is incorrect. Please try
again.;
   $this-DisplayLogInForm();
   echo /td/tr/table/centerbr;
   $this - DisplayFooter();
   break;
  }
 }


##
##VERIFY LOGIN FUNCTION
##
function VerifyLogin($employeeid,$password)
 {
 include('dbconnection.php');
 $employeequery = Select count(*) from employees where employeeid =
'$employeeid' and password='$password';
 $employeeresult = mysql_query($employeequery);
 if(!$employeeresult)
  {
  echo 'Please Try Again Later.';
  exit();
  }
 $count = mysql_result($employeeresult,0,0);
 if($count0)
  {
  $count = 1;
  }
  else
   {
   $count = 0;
   }
  return $count;
 }




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




[PHP] Cookies help please

2002-12-06 Thread Steve Vernon
Hiya,
Ive got a few websites that use sessions and I thought id upgrade them
now to use cookies. In the main file it calls the session start function,
and then this function is called, but it does not seem to work. I open a new
window and the cookie does not seem to auto log me on.

Sorry if I have not explained it right, I want a feature like amazon
where you go back to a site and you are still logged in.

The test member has rememberpassword as y.

The code below keeps my sessions but the cookie bit dosent work.

Thanks,

Steve
XX

 /* Check a session is valid
  */
 function session_check($db_link)
 {
  //Ok so either want to log on, or have a session or cookie allready
  if(isset($_SESSION['ssun']) || isset($_COKKIE[ssun]) ||
isset($_POST['ssname']))
  {
   //Attempt to logon. Set the logon form variables to the session
variables.
   if(isset($_POST['sspass'])isset($_POST['ssname']))
   {
$_SESSION['sspw'] =$_POST['sspass'];
$_SESSION['ssun'] =$_POST['ssname'];

if(isset($_COOKIE[ssun]))
   {
$_COOKIE['ssun']=;
$_COOKIE[ssun]=;
}
   }

   if(isset($_COOKIE[ssun]))
   {
$result = mysql_query(SELECT rememberpassword, memberid, title,
lastname, lastnamenow, md5(memberpassword), email FROM members WHERE
md5(memberpassword)='.$_COOKIE['sspw'].' AND
email='.$_COOKIE['ssun'].', $db_link);
   }
   else
   {
//Check if the session username and password are correct
$result = mysql_query(SELECT rememberpassword, memberid, title,
lastname, lastnamenow, md5(memberpassword), email FROM members WHERE
memberpassword='.$_SESSION['sspw'].' AND email='.$_SESSION['ssun'].',
$db_link);
   }

   if(mysql_num_rows($result)==1)
   {
$loggedin=yes;
$userdata = mysql_fetch_row($result);

if($userdata[0]==y)
{ //Set up the cookies, store the md5 version of the password
 setcookie (ssun, $userdata[6],time()+604800);
 setcookie (sspw, $userdata[5],time()+604800);
}

if($userdata[4]==) //If no last name now
{
 $_SESSION['title']=$userdata[2];
 $_SESSION['lastname']=$userdata[3];
}
else //Use the last name now
{
 $_SESSION['title']=$userdata[2];
 $_SESSION['lastname']=$userdata[4];
}
   }
   else
   {
$loggedin=no;
   }

   if(isset($_GET['logoff']))
   {
if($_GET['logoff']==true)
{
 //Remove the session and cookies
 $loggedin=no;
 $_SESSION['ssun']=;
 $_SESSION['sspw']=;
 $_SESSION['title']=;
 $_SESSION['lastname']=;
 setcookie (ssun, ,time()-3600);
 setcookie (sspw, ,time()-3600);
}
   }
   return $loggedin;
  }
  else
  {
   return no;
  }
 }


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




Re: [PHP] Cookies help please

2002-12-06 Thread Jason Wong
On Friday 06 December 2002 20:22, Steve Vernon wrote:

 The code below keeps my sessions but the cookie bit dosent work.

 Thanks,

 Steve
 XX

  /* Check a session is valid
   */
  function session_check($db_link)
  {
   //Ok so either want to log on, or have a session or cookie allready
   if(isset($_SESSION['ssun']) || isset($_COKKIE[ssun]) ||
-^

Shouldn't that be $_COOKIE??

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
A closed mouth gathers no foot.
*/


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




Re: [PHP] Cookies help please

2002-12-06 Thread Steve Vernon
Thanks a million, must of had something else on my mind ;-)

Love,

Steve
XX



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