Hello world !
First of all, i'd like to say that this is my first page in PHP, so i may have made the most basic of mistakes :)
I wrote most of this from a tutorial i found somewhere on the web.
I get the following errors :
Notice: Undefined index: logged in (...)\index.php on line 7
Notice: Undefined index: user in (...)\index.php on line 67
Notice: Undefined index: pass in (...)\index.php on line 67
I understand the meaning of thoses messages, i think, which is that the variables are not set. I don't understand however how i can fix this.
Any help would be greatly appreciated :)
<?php
session_start();
if($_SESSION["logged"])
{
print_secure_content();
}
else {
if(!$_SESSION["logging"])
{
$_SESSION["logging"]=true;
loginform();
}
else if($_SESSION["logging"])
{
$number_of_rows=checkpass();
if($number_of_rows==1)
{
$_SESSION["user"]=$_GET[userlogin];
$_SESSION["logged"]=true;
print"You are now logged in.";
print_secure_content();
}
else{
print "wrong password or username, please try again";
loginform();
}
}
}
function loginform()
{
echo
"
Please login <BR>
username : <input type='text' name='user' size='20'> <BR>
password : <input type='password' name='pass' size='20'> <BR>
<input type='submit'> <BR>
Or register now !
";
}
function checkpass()
{
$servername="127.0.0.1";
$mysqluser="root";
$mysqlpass="mysql";
$conn=mysql_connect($servername,$mysqluser) or die (mysql_error());
mysql_select_db("profit",$conn);
$sql="select * from users where user='$_GET[user]' and pass='$_GET[pass]'";
$result=mysql_query($sql,$conn) or die (mysql_error());
return mysql_num_rows($result);
}
function print_secure_content()
{
echo
"
Status : Logged in as $_SESSION[user] <BR>
Logout...
";
}
?>