Hy everyone,
I've been searching for help with a code that I have, but nobody seems to use it or know about it. I have 2 PHP pages, the first one is to verify the user and after that it takes you to another page.
The first one is called checklogin.php and the second is login_success.php
I was using an instrucction that is no longer used by the new PHP versions so someone told me to use ISSET, but I still can't understand how that really works.
The problems is that when you login my login_success.php page send me back to the page where I type the users credentials and that's not what I want the page to do.
This is checklogin.php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
$_SESSION['myusername'] = TRUE;
header("location:login_success.php");
exit();
}
else
{
if(isset($_SESSION['myusername'])){
unset($_SESSION['myusername']);
}
echo "Wrong username or password";
}
This is login_success.php
session_start();
if (isset($_SESSION['myusername']))
{
echo 'Login correcto, '.$_SESSION['myusername'].', usuario es: '. $_SESSION['myusername'];
} else {
header("location:main_login.php");
}
PLEASE HELP ME. I'M NEW IN THE PHP WORLD