Can someone please help me to figure out why the following code is returning an error message, " Fatal error: Call to undefined function session_register()
if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(“myusername”);
session_register(“mypassword”);
header(“location:login_success.php”);
}
else {
echo “Wrong Username or Password”;
}
Post the rest of your code.
What version of PHP are you running?
And why would you register a password?
Warning
This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
Okay, I was unfamiliar with how to add to my previous post, but this is a continuation of what was posted the other day. To give more information, I am a student learning PHP and we were working on creating login forms but when I am attempting to log in with the correct name and password, i am getting the error "Fatal error: Call to undefined function session_register() in on line 26. I did the tutorial and typed everything the tutorial has though so I am not understanding why it is giving the error. Can you please help?
here is the full code:
<?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?>You could register?
And my question still stands, what version of PHP are you using?
Find a new tutorial, you are starting with bad habits and depricated , ie removed code, which is most likely your problem.
I am using version 5.4.7…Do you have a link or something to where I can get a better understanding of building login pages with php?
Stop opening New topics for the same issues. You cannot use the session function because it does not exist in the version you are using. I am on the run and do not have a tutorial off the top of my head.
Dia,
Yes, register on this site and you can do more than visit as a “guest” ! ! !
Now, you are calling a function. Since you did not post where you got this tutorial from, we can only
guess that you had a library in the tutorial that you forgot to add to your code. It appears that you are
attempting to use session variables. Session variables are handled in this manner…
session_start(); // first line of code inside your PHP code…
$_SESSION[“some-variable”]=“some-value”; // Sets the session variable…
$some-other-variable=$_SESSION[“some-variable”]; // assigns the value of a session variable…
Hope that is what you were looking for…
Here is a tutorial on this subject. I also suggest looking at many of the other tutorials on this site.
It is one of the best tutorial sites and explains everything simply. (Just click on the Next-Chapter buttons
to move page to page or click on the left side to explore other areas…) Good luck!
http://www.w3schools.com/php/php_sessions.asp