У меня есть регистрационная форма, логин, дом и пользователь офлайн. Я использую wamp server 2.5. login перенаправляет пользователя либо на домашнюю страницу, либо на страницу входа в систему.
Моя проблема в том, что в автономном режиме все работает нормально, но только онлайн-регистрация, его рабочий логин не перенаправляет на домашнюю страницу.
Вот моя связь с кодом mysql:
dbconfig.php
<?php
session_start();
$DB_host = "localhost:3306";
$DB_user = "cashgalo";
$DB_pass = "57121363RbK@*<R>";
$DB_name = "cashgalo_bill";
try
{
$DB_con = new PDO("mysql:host = {$DB_host};dbname{$DB_name}",$DB_user,$DB_pass);
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
catch(PDOException $e)
{
echo $e->getMessage();
}
include_once 'user.php';
$user = new USER($DB_con);
вот моя индексная форма, где пользователь входит в систему после регистрации
index.php
<?php
require_once 'dbconfig.php';
if ($user->is_loggedin()! = "")
{
$user->redirect('homee.php');
}
if (isset($_POST['btn-login']))
{
$uname = $_POST['txt_uname_email'];
$umail = $_POST['txt_uname_email'];
$upass = $_POST['txt_password'];
if ($user->login($uname,$umail,$upass))
{
$user->redirect('home.php');
}
else
{
$error = "Wrong Details !";
}
}
?>
<!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 : cleartuts</title>
<link rel = "stylesheet" href = "bootstrap/css/bootstrap.min.css" type = "text/css" />
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>
<body>
<div class = "container">
<div class = "form-container">
<form method = "post">
<h2>Sign in.</h2><hr />
<?php
if (isset($error))
{
?>
<div class = "alert alert-danger">
<i class = "glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?> !
</div>
<?php
}
?>
<div class = "form-group">
<input type = "text" class = "form-control" name = "txt_uname_email" placeholder = "Username or E mail ID" required />
</div>
<div class = "form-group">
<input type = "password" class = "form-control" name = "txt_password" placeholder = "Your Password" required />
</div>
<div class = "clearfix"></div><hr />
<div class = "form-group">
<button type = "submit" name = "btn-login" class = "btn btn-block btn-primary">
<i class = "glyphicon glyphicon-log-in"></i> SIGN IN
</button>
</div>
<br />
<label>Don't have account yet ! <a href = "sign-up.php">Sign Up</a></label>
</form>
</div>
</div>
</body>
</html>
вот код хеширования пароля:
password hash().php
<?php
$password = "123456";
$hash = password_hash($passwod, PASSWORD_DEFAULT);
$hashed_password = "$2y$10$BBCpJxgPa8K.iw9ZporxzuW2Lt478RPUV/JFvKRHKzJhIwGhd1tpa";
/*
"123456" will become "$2y$10$BBCpJxgPa8K.iw9ZporxzuW2Lt478RPUV/JFvKRHKzJhIwGhd1tpa"
*/
?>
вот проверочный пароль:
password verify().php
<?php
$password = "123456";
$hashed_password = "$2y$10$BBCpJxgPa8K.iw9ZporxzuW2Lt478RPUV/JFvKRHKzJhIwGhd1tpa";
password_verify($password, $hashed_password);
/*
if the password match it will return true.
*/
?>
это форма регистрации пользователя
sign-up.php
<?php
require_once 'dbconfig.php';
if ($user->is_loggedin()! = "")
{
$user->redirect('dashboard.php');
}
if (isset($_POST['btn-signup']))
{
$uname = trim($_POST['txt_uname']);
$umail = trim($_POST['txt_umail']);
$upass = trim($_POST['txt_upass']);
if ($uname= = "") {
$error[] = "provide username !";
}
else if ($umail= = "") {
$error[] = "provide email id !";
}
else if (!filter_var($umail, FILTER_VALIDATE_EMAIL)) {
$error[] = 'Please enter a valid email address !';
}
else if ($upass= = "") {
$error[] = "provide password !";
}
else if (strlen($upass) < 6){
$error[] = "Password must be atleast 6 characters";
}
else
{
try
{
$stmt = $DB_con->prepare("SELECT user_name,user_email FROM users WHERE user_name=:uname OR user_email=:umail");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if ($row['user_name']==$uname) {
$error[] = "sorry username already taken !";
}
else if ($row['user_email']==$umail) {
$error[] = "sorry email id already taken !";
}
else
{
if ($user->register($fname,$lname,$uname,$umail,$upass))
{
$user->redirect('sign-up.php?joined');
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>
<!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>Sign up : cleartuts</title>
<link rel = "stylesheet" href = "bootstrap/css/bootstrap.min.css" type = "text/css" />
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>
<body>
<div class = "container">
<div class = "form-container">
<form method = "post">
<h2>Sign up.</h2><hr />
<?php
if (isset($error))
{
foreach($error as $error)
{
?>
<div class = "alert alert-danger">
<i class = "glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?>
</div>
<?php
}
}
else if (isset($_GET['joined']))
{
?>
<div class = "alert alert-info">
<i class = "glyphicon glyphicon-log-in"></i> Successfully registered <a href='index.php'>login</a> here
</div>
<?php
}
?>
<div class = "form-group">
<input type = "text" class = "form-control" name = "txt_uname" placeholder = "Enter Username" value = "<?php if (isset($error)){echo $uname;}?>" />
</div>
<div class = "form-group">
<input type = "text" class = "form-control" name = "txt_umail" placeholder = "Enter E-Mail ID" value = "<?php if (isset($error)){echo $umail;}?>" />
</div>
<div class = "form-group">
<input type = "password" class = "form-control" name = "txt_upass" placeholder = "Enter Password" />
</div>
<div class = "clearfix"></div><hr />
<div class = "form-group">
<button type = "submit" class = "btn btn-block btn-primary" name = "btn-signup">
<i class = "glyphicon glyphicon-open-file"></i> SIGN UP
</button>
</div>
<br />
<label>have an account ! <a href = "index.php">Sign In</a></label>
</form>
</div>
</div>
</body>
</html>
это мой пользовательский php файл
user.php
<?php
class USER
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function register($fname,$lname,$uname,$umail,$upass)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->db->prepare("INSERT INTO users(user_name,user_email,user_pass)
VALUES(:uname, :umail, :upass)");
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":umail", $umail);
$stmt->bindparam(":upass", $new_password);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function login($uname,$umail,$upass)
{
try
{
$stmt = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname OR user_email=:umail LIMIT 1");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0)
{
if (password_verify($upass, $userRow['user_pass']))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function is_loggedin()
{
if (isset($_SESSION['user_session']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}
public function logout()
{
session_destroy();
unset($_SESSION['user_session']);
return true;
}
}
?>
это моя домашняя страница для пользователя
<?php
include_once 'dbconfig.php';
if (!$user->is_loggedin())
{
$user->redirect('index.php');
}
$user_id = $_SESSION['user_session'];
$stmt = $DB_con->prepare("SELECT * FROM users WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
?>
<!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" />
<link rel = "stylesheet" href = "bootstrap/css/bootstrap.min.css" type = "text/css" />
<link rel = "stylesheet" href = "style.css" type = "text/css" />
<title>welcome - <?php print($userRow['user_email']); ?></title>
</head>
<body>
<div class = "header">
<div class = "left">
<label><a href = "http://www.codingcage.com/">Coding Cage - Programming Blog </a></label>
</div>
<div class = "right">
<label><a href = "logout.php?logout=true"><i class = "glyphicon glyphicon-log-out"></i> logout</a></label>
</div>
</div>
<div class = "content">
welcome : <?php print($userRow['user_name']); ?>
</div>
</body>
</html>
$user->redirect('homee.php'); - homee?
Нет, мистер Блю, его home.php
вы предоставляете весь этот «материал», который имеет отношение к ошибке, а затем не показываете нам, что делает redirect(). Вы должны вызвать exit после перенаправления заголовка, вы не можете выводить до вызова заголовка. Это два правила. Мы даже не знаем названия этих файлов, вероятно, это проблема с корпусом, потому что Linux чувствителен к регистру, а Windows - нет. По сути, вы даете нам все это, чтобы преодолеть трудности, и не можете дать то, что нам действительно нужно.
"" хеширование паролей ""
В ArtisticPhoenix я не получаю сообщения об ошибке, он возвращается на index.php
несколько вещей: детали mysql меняются для каждого местоположения, поэтому детали local + dev mysql будут разными (я заметил, что вы указываете порт - этот порт может измениться на вашем сервере) - также, если вы разрабатываете в среде Windows и тестируете на Linux во-первых, убедитесь, что имена ваших файлов / таблиц чувствительны к регистру, Windows по некоторым причинам решила не учитывать регистр, в Linux index.php - это другой файл, чем Index.php - также и, наконец, если это среда Linux убедитесь, что права доступа к файлам правильные (775 для каталогов и 664 для файлов) и что эти файлы принадлежат вашему пользователю.






Любой может получить доступ к вашей базе данных, если он знает имя домена / хоста.