Login problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
digrev
Forum Newbie
Posts: 11
Joined: Sat Jun 19, 2010 1:51 pm

Login problem

Post 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;

}

?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Login problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
digrev
Forum Newbie
Posts: 11
Joined: Sat Jun 19, 2010 1:51 pm

Re: Login problem

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Login problem

Post 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.
Last edited by AbraCadaver on Tue Jun 22, 2010 2:29 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Login problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
digrev
Forum Newbie
Posts: 11
Joined: Sat Jun 19, 2010 1:51 pm

Re: Login problem

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Login problem

Post 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:
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
digrev
Forum Newbie
Posts: 11
Joined: Sat Jun 19, 2010 1:51 pm

Re: Login problem

Post by digrev »

:wink:
Post Reply