isee Posted August 15, 2017 Share Posted August 15, 2017 PHP Fatal error: Call to undefined function session_register() - From error log this is for a login page. $mode = $_GET['mode']; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $encrypted_mypassword=md5($mypassword); $result = mysql_query("SELECT * FROM user WHERE username='" . $myusername . "' and password='" . $encrypted_mypassword . "'",$db); if(!$result) { echo mysql_error(); } else { $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count == 1) { $row = mysql_fetch_assoc($result); // Register $myusername, $mypassword session_register("myusername"); session_register("mypassword"); $_SESSION['user_id'] = $row['username']; $_SESSION['user_type'] = $row['usertype']; $_SESSION['logged_in'] = TRUE; header("location:index.php?level=1"); } else { if($mode == "new") { header("location:../beta2/AdvisorLogin.php?error=wrong"); } else { header("location:login.php?error=wrong"); } } } I believe this is because of php version any advise on changing the code to work with newer versions ? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 15, 2017 Share Posted August 15, 2017 These are deprecated session_register("myusername"); session_register("mypassword"); use $_SESSION["myusername"]=$myusername; $_SESSION["mypassword"]=$mypassword; Link to comment Share on other sites More sharing options...
isee Posted August 15, 2017 Author Share Posted August 15, 2017 @dsonesuk Thank you for that i have already implemented that but for some reason when i try to login it doesn't login but display this error <?php $error = $_GET["error"]; if ($error == "wrong") { echo "Wrong Username and Password entered. Please try again!"; } else if ($error == "nouser") { echo "You are trying to access a secured page. Please provide your Username and Password to continue."; } else { echo "Please login to proceed."; } ?> The above php code is in the login page. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 15, 2017 Share Posted August 15, 2017 I presume you have session_start(); at top of pages that use sessions? Then i suggest you check value of $count and $mode either of which can cause this error to appear, also clear all history etc, that may stored failed results. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 15, 2017 Share Posted August 15, 2017 Session_register hasn't been there since PHP 5.4: Quote Warning This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. Your code won't work in PHP 7 either, because you're using the old mysql extension, which is not in PHP 7. You need to update that to something modern, and you need to use prepared statements so that your code isn't vulnerable to SQL injection attacks. You should also consider using PHP's built-in password hashing functions, md5 hasn't been considered cryptographically secure since the mid 90s. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now