I understand an example of a complete system of authorization, registration, change of mail, password and its recovery. The code was posted in a large foreign blog, surprised by the fact that it does not work for me. If I can solve my problem, then most likely many more people from that blog will get help. The article stated that the functions for generating a hash in PHP 5.5 are different, but I tested it on both the new and the old. The account is added to the database, it is successfully activated after the letter arrives at the post office, but when I try to log in, I get errors: Errors Classs.User.php:

<?php require_once 'dbconfig.php'; class USER { private $conn; public function __construct() { $database = new Database(); $db = $database->dbConnection(); $this->conn = $db; } public function runQuery($sql) { $stmt = $this->conn->prepare($sql); return $stmt; } public function lasdID() { $stmt = $this->conn->lastInsertId(); return $stmt; } public function register($uname,$email,$upass,$code) { try { $password = md5($upass); $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode) VALUES(:user_name, :user_mail, :user_pass, :active_code)"); $stmt->bindparam(":user_name",$uname); $stmt->bindparam(":user_mail",$email); $stmt->bindparam(":user_pass",$password); $stmt->bindparam(":active_code",$code); $stmt->execute(); return $stmt; } catch(PDOException $ex) { echo $ex->getMessage(); } } public function login($email,$upass) { try { $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id"); $stmt->execute(array(":email_id"=>$email)); $userRow=$stmt->fetch(PDO::FETCH_ASSOC); if($stmt->rowCount() == 1) { if($userRow['userStatus']=="Y") { if($userRow['userPass']==md5($upass)) { $_SESSION['userSession'] = $userRow['userID']; return true; } else { header("Location: index.php?error"); exit; } } else { header("Location: index.php?inactive"); exit; } } else { header("Location: index.php?error"); exit; } } catch(PDOException $ex) { echo $ex->getMessage(); } } public function is_logged_in() { if(isset($_SESSION['userSession'])) { return true; } } public function redirect($url) { header("Location: $url"); } public function logout() { session_destroy(); $_SESSION['userSession'] = false; } function send_mail($email,$message,$subject) { require_once('mailer/class.phpmailer.php'); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPDebug = 0; $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; $mail->Host = "smtp.yandex.ru"; $mail->Port = 465; $mail->AddAddress($email); $mail->Username="mail"; $mail->Password="pass"; $mail->SetFrom('name','Coding Cage'); $mail->AddReplyTo("name","Coding Cage"); $mail->Subject = $subject; $mail->MsgHTML($message); $mail->Send(); } } ?> 

signup.php:

 <?php session_start(); require_once 'class.user.php'; $reg_user = new USER(); if($reg_user->is_logged_in()!="") { $reg_user->redirect('home.php'); } if(isset($_POST['btn-signup'])) { $uname = trim($_POST['txtuname']); $email = trim($_POST['txtemail']); $upass = trim($_POST['txtpass']); $code = md5(uniqid(rand())); $stmt = $reg_user->runQuery("SELECT * FROM tbl_users WHERE userEmail=:email_id"); $stmt->execute(array(":email_id"=>$email)); $row = $stmt->fetch(PDO::FETCH_ASSOC); if($stmt->rowCount() > 0) { $msg = " <div class='alert alert-error'> <button class='close' data-dismiss='alert'>&times;</button> <strong>Sorry !</strong> email allready exists , Please Try another one </div> "; } else { if($reg_user->register($uname,$email,$upass,$code)) { $id = $reg_user->lasdID(); $key = base64_encode($id); $id = $key; $message = " Hello $uname, <br /><br /> Welcome to Coding Cage!<br/> To complete your registration please , just click following link<br/> <br /><br /> <a href='http://vh159953.eurodir.ru/test/verify.php?id=$id&code=$code'>Click HERE to Activate :)</a> <br /><br /> Thanks,"; $subject = "Confirm Registration"; $reg_user->send_mail($email,$message,$subject); $msg = " <div class='alert alert-success'> <button class='close' data-dismiss='alert'>&times;</button> <strong>Success!</strong> We've sent an email to $email. Please click on the confirmation link in the email to create your account. </div> "; } else { echo "sorry , Query could no execute..."; } } } ?> <!DOCTYPE html> <html> <head> <title>Signup | Coding Cage</title> <!-- Bootstrap --> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"> <link href="assets/styles.css" rel="stylesheet" media="screen"> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script> </head> <body id="login"> <div class="container"> <?php if(isset($msg)) echo $msg; ?> <form class="form-signin" method="post"> <h2 class="form-signin-heading">Sign Up</h2><hr /> <input type="text" class="input-block-level" placeholder="Username" name="txtuname" required /> <input type="email" class="input-block-level" placeholder="Email address" name="txtemail" required /> <input type="password" class="input-block-level" placeholder="Password" name="txtpass" required /> <hr /> <button class="btn btn-large btn-primary" type="submit" name="btn-signup">Sign Up</button> <a href="index.php" style="float:right;" class="btn btn-large">Sign In</a> </form> </div> <!-- /container --> <script src="vendors/jquery-1.9.1.min.js"></script> <script src="bootstrap/js/bootstrap.min.js"></script> </body> </html> 

verify.php:

 <?php require_once 'class.user.php'; $user = new USER(); if(empty($_GET['id']) && empty($_GET['code'])) { $user->redirect('index.php'); } if(isset($_GET['id']) && isset($_GET['code'])) { $id = base64_decode($_GET['id']); $code = $_GET['code']; $statusY = "Y"; $statusN = "N"; $stmt = $user->runQuery("SELECT userID,userStatus FROM tbl_users WHERE userID=:uID AND tokenCode=:code LIMIT 1"); $stmt->execute(array(":uID"=>$id,":code"=>$code)); $row=$stmt->fetch(PDO::FETCH_ASSOC); if($stmt->rowCount() > 0) { if($row['userStatus']==$statusN) { $stmt = $user->runQuery("UPDATE tbl_users SET userStatus=:status WHERE userID=:uID"); $stmt->bindparam(":status",$statusY); $stmt->bindparam(":uID",$id); $stmt->execute(); $msg = " <div class='alert alert-success'> <button class='close' data-dismiss='alert'>&times;</button> <strong>WoW !</strong> Your Account is Now Activated : <a href='index.php'>Login here</a> </div> "; } else { $msg = " <div class='alert alert-error'> <button class='close' data-dismiss='alert'>&times;</button> <strong>sorry !</strong> Your Account is allready Activated : <a href='index.php'>Login here</a> </div> "; } } else { $msg = " <div class='alert alert-error'> <button class='close' data-dismiss='alert'>&times;</button> <strong>sorry !</strong> No Account Found : <a href='signup.php'>Signup here</a> </div> "; } } ?> <!DOCTYPE html> <html> <head> <title>Confirm Registration</title> <!-- Bootstrap --> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"> <link href="assets/styles.css" rel="stylesheet" media="screen"> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script> </head> <body id="login"> <div class="container"> <?php if(isset($msg)) { echo $msg; } ?> </div> <!-- /container --> <script src="vendors/jquery-1.9.1.min.js"></script> <script src="bootstrap/js/bootstrap.min.js"></script> </body> </html> 

index.php:

 <?php session_start(); require_once 'class.user.php'; $user_login = new USER(); if($user_login->is_logged_in()!="") { $user_login->redirect('home.php'); } if(isset($_POST['btn-login'])) { $email = trim($_POST['txtemail']); $upass = trim($_POST['txtupass']); if($user_login->login($email,$upass)) { $user_login->redirect('home.php'); } } ?> <!DOCTYPE html> <html> <head> <title>Login | Coding Cage</title> <!-- Bootstrap --> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"> <link href="assets/styles.css" rel="stylesheet" media="screen"> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script> </head> <body id="login"> <div class="container"> <?php if(isset($_GET['inactive'])) { ?> <div class='alert alert-error'> <button class='close' data-dismiss='alert'>&times;</button> <strong>Sorry!</strong> This Account is not Activated Go to your Inbox and Activate it. </div> <?php } ?> <form class="form-signin" method="post"> <?php if(isset($_GET['error'])) { ?> <div class='alert alert-success'> <button class='close' data-dismiss='alert'>&times;</button> <strong>Wrong Details!</strong> </div> <?php } ?> <h2 class="form-signin-heading">Sign In.</h2><hr /> <input type="email" class="input-block-level" placeholder="Email address" name="txtemail" required /> <input type="password" class="input-block-level" placeholder="Password" name="txtupass" required /> <hr /> <button class="btn btn-large btn-primary" type="submit" name="btn-login">Sign in</button> <a href="signup.php" style="float:right;" class="btn btn-large">Sign Up</a><hr /> <a href="fpass.php">Lost your Password ? </a> </form> </div> <!-- /container --> <script src="bootstrap/js/jquery-1.9.1.min.js"></script> <script src="bootstrap/js/bootstrap.min.js"></script> </body> </html> 

home.php:

 <?php session_start(); require_once 'class.user.php'; $user_home = new USER(); if(!$user_home->is_logged_in()) { $user_home->redirect('index.php'); } $stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid"); $stmt->execute(array(":uid"=>$_SESSION['userSession'])); $row = $stmt->fetch(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html class="no-js"> <head> <title><?php echo $row['userEmail']; ?></title> <!-- Bootstrap --> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"> <link href="assets/styles.css" rel="stylesheet" media="screen"> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container-fluid"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <a class="brand" href="#">Member Home</a> <div class="nav-collapse collapse"> <ul class="nav pull-right"> <li class="dropdown"> <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-user"></i> <?php echo $row['userEmail']; ?> <i class="caret"></i> </a> <ul class="dropdown-menu"> <li> <a tabindex="-1" href="logout.php">Logout</a> </li> </ul> </li> </ul> <ul class="nav"> <li class="active"> <a href="http://www.codingcage.com/">Coding Cage</a> </li> <li class="dropdown"> <a href="#" data-toggle="dropdown" class="dropdown-toggle">Tutorials <b class="caret"></b> </a> <ul class="dropdown-menu" id="menu1"> <li><a href="http://www.codingcage.com/search/label/PHP OOP">PHP OOP</a></li> <li><a href="http://www.codingcage.com/search/label/PDO">PHP PDO</a></li> <li><a href="http://www.codingcage.com/search/label/jQuery">jQuery</a></li> <li><a href="http://www.codingcage.com/search/label/Bootstrap">Bootstrap</a></li> <li><a href="http://www.codingcage.com/search/label/CRUD">CRUD</a></li> </ul> </li> <li> <a href="http://www.codingcage.com/2015/09/login-registration-email-verification-forgot-password-php.html">Tutorial Link</a> </li> </ul> </div> <!--/.nav-collapse --> </div> </div> </div> <!--/.fluid-container--> <script src="bootstrap/js/jquery-1.9.1.min.js"></script> <script src="bootstrap/js/bootstrap.min.js"></script> <script src="assets/scripts.js"></script> </body> </html> 

Closed due to the fact that off-topic participants Dmitriy Simushev , Nick Volynkin 30 Oct '16 at 14:59 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Dmitriy Simushev, Nick Volynkin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    And the path, which is registered in session.save_path, exists and is available for recording? - cronfy
  • one
    PCP (php.ini) is not configured correctly. session.save_path Or does not exist or is not writable by the www-data user. A strange question you just wrote what is wrong in the error. - E_p
  • sorry, can I link to the blog? - Ep1demic
  • @ Ep1demic codingcage.com/2015/09/… - Stas Mackarow
  • @E_p This is the actual entry I found in php.ini. [session] session.save_path = "/ var / www / vh159953 / data / bin-tmp" - Stas Mackarow

1 answer 1

Found a solution to the problem. It turns out the home folder (server root) - this is already a directory called "data", and I have created another "data" in this root and already made bin-tmp there.

It turned out like this: session.save_path said that the session is written in data / bin-tmp And in fact I did not have this folder, because the path was: data / data / bin-tmp

Who will face a similar problem - carefully look at the name of your home directory.