PDA

Click to See Complete Forum and Search --> : login works... but is stupid


PlaGuE
Sep 7th, 2005, 03:29 AM
okay i have a login script... now the url link would be index.php?console...

but i wana do it that way....lol


anyways heres the code... that i think im having the trouble with. WHich is located in consolefunctions.php

function check_login($user, $pass, $nRank) {
global $userinfo;
$result = @mysql_query("SELECT * FROM members WHERE username = \"$user\"");
$userinfo = mysql_fetch_array($result);
if($userinfo != NULL)
extract($userinfo);

// If the username matches the result in the mysql query and the password is correct
// return the rank of the user.
if($user == $username && $pass == $password and $username != NULL) {
if($disabled != 1) {
if($rank >= $nRank) {
return 1;
}
else {
echo("
<table width=100% align=center height=4% border=0 cellpadding=3 cellspacing=1 bgcolor=#000000>
<tr>
<td height=25 bgcolor=#333333><div align=center>

$fontString
You are not high enough rank. <center><br><font size=2 face=verdana><b><a href=index.php?console.php>Click Here to return to console</font></b></center>
</div></td>
</tr>
</table> ");
}
}
if($disabled == 1) {
$result = @mysql_query("SELECT * FROM members WHERE username = \"$user\"");
$row = mysql_fetch_array($result);
extract($row);


echo("
<table width=100% align=center height=4% border=0 cellpadding=3 cellspacing=1 bgcolor=#000000>
<tr>
<td height=25 bgcolor=#333333><div align=center>

$fontString
You have been disabled.<br><br>
<font color=#1C86EE size=1 face=verdana>$disabled</font>
</div></td>
</tr>
</table> ");
}
}
else {
if(!$user) {

echo("
<table width=100% align=center height=4% border=0 cellpadding=3 cellspacing=1>
<tr>
<td height=25><div align=center>

<b><font color=FF6600>Please Login.</font></b><br><br>
<p>
<p>
<form action=index.php?console method=post>
<FONT color=#FFFFFF size=2>
<b>Username:<b> <INPUT style=\"border:1px solid #76A5D5; WIDTH: 115px; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff\" type=username name=username size=\"20\"><br>
<b>Password:</b>&nbsp; <INPUT style=\"border:1px solid #76A5D5; WIDTH: 115px; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff\" type=password name=password size=\"20\"><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type='submit' value='submit' name='login'>
</div></td>
</tr>
</table>");

}
else {
echo("
<table width=100% align=center height=4% border=0 cellpadding=3 cellspacing=1>
<tr>
<td height=25><div align=center>


<b><font color=FF6600>Invalid Username or Password</font></b><br><br>
<font color=FF6600>Error:</font> Invalid information was given<br>
Please check the email sent to you for your correct Information.
<p>
<p>
<form action=index.php?console method=post>
<FONT color=#FFFFFF size=2>
<b>Username:<b> <INPUT style=\"border:1px solid #76A5D5; WIDTH: 115px; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff\" type=username name=username size=\"20\"><br>
<b>Password:</b>&nbsp; <INPUT style=\"border:1px solid #76A5D5; WIDTH: 115px; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff\" type=password name=password size=\"20\"><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type='submit' value='submit' name='login'>
</div></td>
</tr>
</table>");
}
}

}

this is the function that uses it.

function consolepages($page) {
switch($page){
default:
if(check_login($_COOKIE['cusername'], $_COOKIE['cpassword'], 0)==1) {
profile($_COOKIE['cusername'], $_SERVER['REMOTE_ADDR']);
displayconsole($_COOKIE['cusername']);
}
break;
case "change_profile":
echo"Change Profile";
break;


now when they hit login... the code for the cookies are activated in the index.php at the top of page.

if(isset($_POST['login'])){

$usern = $_POST['username'];

$passw = $_POST['password'];

setcookie("cpassword", "$passw",time() + 3600);

setcookie("cusername", "$usern",time() + 3600);
}



now when i click login. it asked me to input the stuff again... which is wierd... so plz help.

PlaGuE
Sep 7th, 2005, 08:29 PM
....hehe...bump...bump...

john tindell
Sep 7th, 2005, 09:24 PM
are you setting the cookies and then trying to read from them in the same run-though of the script?

try


function consolepages($page) {
switch($page){
default:
if(check_login($_SESSION['cusername'], $_SESSION['cpassword'], 0)==1) {
profile($_SESSION['cusername'], $_SERVER['REMOTE_ADDR']);
displayconsole($_SESSION['cusername']);
}
break;
case "change_profile":
echo"Change Profile";
break;


if(isset($_POST['login'])){

$usern = $_POST['username'];

$passw = $_POST['password'];

$_SESSION['cusername'] = $usern;
$_SESSION['cpassword'] = $passw;
setcookie("cpassword", "$passw",time() + 3600);

setcookie("cusername", "$usern",time() + 3600);
}


with this at the top of your script

session_start();
$_SESSION['cusername'] = $_COOKIE['cusername'];
$_SESSION['cpassword'] = $_COOKIE['cpassword'];

PlaGuE
Sep 8th, 2005, 08:21 AM
thanks... will try...

PlaGuE
Sep 10th, 2005, 03:55 AM
worked