Page 1 of 1

Cookies Problem

Posted: Sat Nov 02, 2002 10:23 pm
by Little Spy
hey for some reason I just can't this to work right I spent 3 hours debugging and im not any closer than when i started.

Excert From global.php

Code: Select all

// ########## FUNCTION DESC: Admin Login Page ##########
function displayLogin($error) {
   include("./templates/login.inc");
   echo $error;
}

// ########## Start Stuff For Cookies ##########
   if (($HTTP_POST_VARSї'username'] == TRUE) && ($HTTP_GET_VARSї'action'] == "checklogin")) {
      $username = $HTTP_POST_VARSї'username'];
      $password = $HTTP_POST_VARSї'password'];
      dbConnect();
      $password2 = mysql_query("SELECT password FROM userinfo WHERE username = '" . $username . "'") or die(mysql_error());
      if ($password == $password2) {
         setcookie("username", $username, time()+3600);
         setcookie("password", $password, time()+3600);
      }
      elseif ($password != $password2) {
         displayLogin("Mismatch");
         exit;
      }
   }

/*if((array_key_exists("username", $HTTP_COOKIE_VARS)) && (array_key_exists("password", $HTTP_COOKIE_VARS))) {
}
else {

   exit;
}*/

if ($HTTP_COOKIE_VARSї'username'] == FALSE) {
     displayLogin();
     exit;
}
Excert From index.php

Code: Select all

<?php
// ----------------------------- //
// Installer For InvasionID     //
// Written By: Matt Moyles     //
// -------------------------- //

require("./global.php");

$page = new HtmlTemplate("templates/content.inc");

if ($HTTP_GET_VARS&#1111;'action'] == "") &#123;
   include("templates/frameset.inc");
&#125;

if ($HTTP_GET_VARS&#1111;'action'] == "top") &#123;
   include("templates/top.inc");
&#125;

if ($HTTP_GET_VARS&#1111;'action'] == "nav") &#123;
   include("templates/nav.inc");
&#125;

if ($HTTP_GET_VARS&#1111;'action'] == "main") &#123;
   $content = getContentFile("templates/main.inc");
&#125;

$page->SetParameter("PAGE_CONTENT", $content);
$page->CreatePage();
unset($page);


?>
Login.inc

Code: Select all

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Login To CP</title>
<base target="_self">
<style type="text/css">
	td &#123; font-family: "Verdana"; font-size: 12px; text-align: left color: #202931; &#125;
	p &#123; font-family: "Verdana"; font-size: 12px; &#125;
	a:link		&#123;COLOR: #374A57; TEXT-DECORATION: none; font-family: "Verdana"; &#125;
	a:visited	&#123;COLOR: #374A57; TEXT-DECORATION: none; &#125;
	a:hover		&#123;COLOR: #F7CB19; BACKGROUND-COLOR: #202931; &#125;
	a:active	&#123;COLOR: #F7CB19; BACKGROUND-COLOR: #202931; &#125;
	FORM		&#123;FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; FONT-SIZE: 10px; &#125;
	SELECT		&#123;FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; COLOR: #51485F; FONT-SIZE: 10px; &#125;
	INPUT		&#123;FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; COLOR: #51485F; FONT-SIZE: 10px; &#125;
	TEXTAREA	&#123;FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; COLOR: #51485F; FONT-SIZE: 10px; &#125;
	.tbl_caption &#123; background-color: #425766; color: #F7CB19; font-size: 9px; font-weight : bold; &#125;
	.tbl_border &#123; background-color: #425766; &#125;
	.tbl_light &#123; background-color: #CACFC8; &#125;
	.tbl_dark &#123; background-color: #C0C7BD; &#125;
	.button &#123; background-color: #425766; color: #F7CB19; font-size: 9px; font-weight : bold; &#125;
</style>
</head>

<body bgcolor="#C1C7BF" topmargin="10" leftmargin="10">

<form action="index.php?action=checklogin" method="post">
<p align="center"><b><font color="#F7CB19">
<div align="center">
    <center>
  <table cellpadding="0" cellspacing="0" border="1" class="tbl_border" style="border-collapse: collapse" bordercolor="#111111">
    <tr>
      <td>
      <div align="center">
        <center>
      <table cellpadding="4" cellspacing="0" border="0" width="439" height="62" style="border-collapse: collapse" bordercolor="#111111">
        <tr>
          <td class="tbl_caption" colspan="2" height="12" width="873">
          <font style="font-size: 7pt">Login To 
          Saiyan Invasion Site Control Panel</font></td>
        </tr>
        <tr class="tbl_light">
          <td height="18" width="589"><span style="font-size: 8pt">Username</span></td>
          <td width="276" height="18">
          <input type="text" size="28" name="username"></td>
        </tr>
        <tr class="tbl_dark">
          <td height="18" width="589"><span style="font-size: 8pt">Password</span></td>
          <td width="276" height="18">
          <input type="password" size="28" name="password"></td>
        </tr>
        <tr>
          <td class="tbl_light" colspan="2" align="center" height="1" width="873">
          <input type="submit" value="Login" class="button" name="Login"></td>
        </tr>
      </table>
        </center>
      </div>
      </td>
    </tr>
  </table>
    </center>
  </div>
</form>

</body>

</html>
Cookies won't set themselves right, or something around there is messed up and I cant figure it out. Hopefully a few other people looking @ it can find a careless mistake or a way to fix it.

Posted: Sat Nov 02, 2002 10:41 pm
by mydimension
your problem is in global.php on this line:

Code: Select all

$password2 = mysql_query("SELECT password FROM userinfo WHERE username = '" . $username . "'") or die(mysql_error());
the reason is becasue mysql_query() only returns a result resource which is not the same as the actual query result. try this code:

Code: Select all

$result = mysql_query("SELECT password FROM userinfo WHERE username = '" . $username . "'") or die(mysql_error());
$password2 = mysql_fetch_array($result);
$password2 = $password2&#1111;'password'];