Page 1 of 1

Login problem

Posted: Tue Jun 22, 2010 1:58 pm
by digrev
Hi eveyone im trying to write some code but there is a problem i think ..if i type index.php into browser before loggin in ..i get this error


Notice: Undefined index: position _ in C:\wamp\www\MemberForms\index.php on line 4
Notice: Undefined index: user_ in C:\wamp\www\MemberForms\index.php on line 5
Please sign in


but after sign-in everythin is ok no eny error messages and says "welcome " , Im confused could you help plase

my code

signinform.php

<form action="signin.php" method="post">

<div align="center" class="style1 style1">SIGN IN PAGE</div>
<table width="200" border="0">
<tr>
<td> Username: </td>
<td>
<input type="text" name="txtname" />

</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Passsword: </td>
<td>
<input type="password" name="txtpass" />

</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" name="Submit" value="Sign In" />

</td>
<td>&nbsp;</td>
</tr>
</table>

</form>
</body>
</html>


signin.php

<?php

session_start();

include("cnn.php");

$name=$_POST['txtname'];
$pass=$_POST['txtpass'];

$fetch_array=mysql_fetch_array(mysql_query("select * from memberinfo where Username='$name' and Pass='$pass' "));
if(($name!="" || $pass!="" ) && ($name==$fetch_array['Username'] && $pass==$fetch_array['Pass']))
{

$_SESSION['position _']= "girildi";
$_SESSION['user_']=$name;

header("location:index.php");
}

?>


index.php


<?php

session_start();
$Ses_value=$_SESSION['position _'];
$user=$_SESSION['user_'];
if($Ses_value == ""){

echo "Please sign in";
}

else{

echo "Welcome " .$user;

}

?>

Re: Login problem

Posted: Tue Jun 22, 2010 2:08 pm
by AbraCadaver
Because $_SESSION['position _'] and $_SESSION['user_'] don't exist until you sign in. You need to check them with isset() before using them.

Re: Login problem

Posted: Tue Jun 22, 2010 2:15 pm
by digrev
hi and thanks for replying me i watched a training video about sesion and cookie and that guy didnt use that code .so i thouht mybe it could be php server settings what do you say my friend

Re: Login problem

Posted: Tue Jun 22, 2010 2:24 pm
by AbraCadaver
The code you have is flawed, so I say that you need to check if a variable is set before you use it. If you turn off error reporting then you won't see those notices, but it is still flawed.

Re: Login problem

Posted: Tue Jun 22, 2010 2:27 pm
by AbraCadaver
On a side note, you need to be passing $name and $pass through mysql_real_escape_string() or you are open to SQL Injection attacks.

Re: Login problem

Posted: Tue Jun 22, 2010 2:43 pm
by digrev
Thanks a lot i will try but mybe you want to check this video because isset doesn't exist there thanks again

http://www.seyretogren.com/video/web-ta ... stemi.html

Re: Login problem

Posted: Tue Jun 22, 2010 2:51 pm
by AbraCadaver
digrev wrote:Thanks a lot i will try but mybe you want to check this video because isset doesn't exist there thanks again

http://www.seyretogren.com/video/web-ta ... stemi.html
Yes, there is a lot of useless stuff on the Internet. Just because you found it online does not mean that it is reliable. :wink:

Re: Login problem

Posted: Tue Jun 22, 2010 2:56 pm
by digrev
:wink: