/    Sign up×
Community /Pin to ProfileBookmark

login form probleme

hi i try to create a login form width inscription using md5() function for password and session but when i login its not working no errors nothing, the code after the line that compar md5 db password and form password is not working. please help me.
[B]code for page inscription[/B]

[CODE]
<?php
session_start();
if (isset($_POST[‘insc’]))
{
if (!empty($_POST[‘user’]) || !empty($_POST[‘pass’]))
{
mysql_connect(‘localhost’, ‘root’, ”);

mysql_select_db(‘test’);

$user = stripslashes($_POST[‘user’]);
$pass = stripslashes($_POST[‘pass’]);
$pass = mysql_real_escape_string($pass);
$user = mysql_real_escape_string($user);

$time = time();
$day = date(“y/m/d”,$time);
$select = “INSERT INTO `user` (user, pass, date) VALUES (‘”.$user.”‘,'”.md5($pass).”‘, ‘”.$day.”‘) “;
mysql_query($select);

header(“location:login.php?ins=ok”);

}
else{
$erreur = “<p>all informations must be entred</p>”;
}
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>inscription</title>
</head>

<body>
<?php if (isset($erreur)){echo $erreur;} ?>
<form name = “insc” method = “post” action = “<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
<p>
user : <br/>
<input type=”text” name=”user” maxlength = 20 />
</p>
<p>
Password : <br/>
<input type=”password” name=”pass” maxlength = 20 />
</p>
<p>
<input type = “submit” name=”insc” value = “inscription” />
</p>
<form>
</body>
</html>
[/CODE]

[B]code for login page[/B]

[CODE]
<?php
session_start();
if (isset($_GET[‘ins’]))
{
$mssg = “<p>you succesly registred</p>”;
}
if (isset($_POST[‘log’]))
{
if (!empty($_POST[‘user’]) || !empty($_POST[‘pass’]))
{
$con = mysql_connect(‘localhost’, ‘root’, ”);

mysql_select_db(‘test’);

$user = stripslashes($_POST[‘user’]);
$pass = stripslashes($_POST[‘pass’]);
$pass = mysql_real_escape_string($pass);
$user = mysql_real_escape_string($user);

$select = “SELECT * FROM `user` WHERE user = ‘”.$user.”‘ “;
$do = mysql_query($select, $con);

if ( mysql_num_rows($do) == 1)
{
$select_array = mysql_fetch_array($do);
if ($select_array[‘pass’] == md5($pass))
{
$_SESSION[‘user’]=$user;
$_SESSION[‘pass’]=$pass;

header(“location:index.php?log=ok”);
}

}
else{
$erreur = “<p>password or username incorrect</p>”;
}
}
else{
$erreur = “<p>all informations must be entred</p>”;
}
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>login</title>
</head>

<body>
<?php if (isset($erreur)){echo $erreur;} ?>
<?php if (isset($mssg)){echo $mssg;} ?>
<form name = “login” method = “post” action = “<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
<p>
user : <br/>
<input type=”text” name=”user” maxlength = 20 />
</p>
<p>
Password : <br/>
<input type=”password” name=”pass” maxlength = 20 />
</p>
<p>
<input type = “submit” name=”log” value = “login” />
</p>
<form>
<p><a href=”inscri.php”>inscription</a>
</body>
</html>
[/CODE]

[B]page of index after login[/B]

[CODE]
<?php
session_start();
if (isset($_GET[‘deco’]))
{
session_destroy();
}
if (!isset($_SESSION[‘user’]) && !isset($_SESSION[‘pass’]))
{
header(“location:login.php”);
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Ty
pe” content=”text/html; charset=utf-8″ />
<title></title>
</head>

<body>
<h1>Welcom to home page</h1>
<p>user : <?php echo $_SESSION[‘user’]; ?></p>
<p><a href=”index.php?deco=ok”>deconnection </a></p>
</body>
</html>
[/CODE]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @channark spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...