sigmahokies Posted November 17, 2015 Share Posted November 17, 2015 Hi everyone, I am trying to set up the login system in PHP, seem function in PHP is not correctly, maybe I am missing something. Message from error said : Fatal error: Call to undefined function session_register() in. on line 20 Here my script in PHP: <?php require_once('require.php'); $username = $_POST['user']; $password = $_POST['pass']; $username = stripslashes($username); $password = stripslashes($password); $username = mysqli_real_escape_string($Garydb, $username); $password = mysqli_real_escape_string($Garydb, $password); $log = "SELECT username, password, type FROM username WHERE username ='".$username."' AND password = '".$password."'"; $result = mysqli_query($Garydb, $log); $count = mysqli_num_rows($result); if ($count == 1) { session_register('user'); <-- 20 line session_register('pass'); header('register.php'); } else { header("<p>Wrong or not exist username and password <a href='login.php'>Return to Login page.</a></p>"); } ?> <!doctype type> <html> </html> Is there something is missing that i should add in this script? Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 17, 2015 Share Posted November 17, 2015 (edited) You didnt use session_start at the top of your code. And all this: $username = $_POST['user']; $password = $_POST['pass']; $username = stripslashes($username); $password = stripslashes($password); Could simply be: $username = stripslashes( $_POST['user']); $password = stripslashes($_POST['pass']); Dont create variables for no reason. Edited November 17, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted November 17, 2015 Solution Share Posted November 17, 2015 session_register() function is deprecated and removed as of PHP5.4. You should not be using this function for registering session variables at all. Instead you should be assigning the value to the $_SESSION superglobal variable $_SESSION['user'] = $username; // add the username to the session variable, named user Make sure you are calling session_start() at the top of all your pages which uses $_SESSION variables, in order for session values to persist between pages. Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 17, 2015 Share Posted November 17, 2015 (edited) Also Use of session_register() is deprecated, use $_SESSION DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. Edited November 17, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
sigmahokies Posted November 17, 2015 Author Share Posted November 17, 2015 (edited) It is working now, but I need to load to other file that allow user view this website with approved username. I thought: load('register.php'); or file_get_contents('register.php'); - after $_SESSION['user']; and $_SESSION['pass']; Also, I labelled session_start() at top of script. Do you know code that will load to other page if correct username and password? Edited November 17, 2015 by sigmahokies Quote Link to comment Share on other sites More sharing options...
sigmahokies Posted November 17, 2015 Author Share Posted November 17, 2015 Never mind about my last comment, i found a way to do that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.