Fatal error: Call to undefined function session_register() in C:\xampp\htdocs\4\admin\checklogin.php on line 33

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="phplogin"; // 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 

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";

// Mysql_num_row is counting table row

// If result matched $myusername and $mypassword, table row must be 1 row

// Register $myusername, $mypassword and redirect to file "login_success.php"
else {
echo ( " <script language='JavaScript'>  
             if(confirm('Error logging in: The Username & Password does not match.'))
             window.location = 'login.php';
Member Avatar



Fatal error: Call to undefined function session_register() in C:\xampp\htdocs\4\admin\checklogin.php on line 33

You can't used session_register() because it's outdated

Read this:


If you are using PHP 5.4.0 then this function is no longer available.

Please update to PHP 5.4.7

If you want still want to used that

Then do this : $_SESSION['username'] = '$username';

My advice right now learn the current code because you will get alot of errors later on and it's getting harder for you to make the code work.

commented: To Rectify what some retard did to LastMitch +0


Thank you, thank you, thank you!

Am currently testing Ubuntu 12.10 as my new develop environment. I found some on advice online suggesting one check logs with this particular error (cat /var/log/apache2/error.log). Accordingly; I searched on the PHP Fatal error found in these logs & ended up here. I guess it is to be expected that certain functions etc get deprecated with time, but it can be a hassle finding out the hard way! Once again thanks!

Member Avatar


Before assigning any session variables like $_SESSION['username'] = ...
ensure that you have session_start(); at the top of every page.


I'm not sure if you are replying to me, but if you are firstly, thank you and rest assured I have session_start(); at the top of pages where required. My problem was just getting caught out by the deprecation of session_register();. Everthing is cool now.

Member Avatar


Sure, no problem. As it wasn't in your original code, I thought I'd add it 'just in case'.

Everthing is cool now.


but now how do you check if the session is created?
on the other pages

 //This dosn't work :S

Hi joshf97,

You set a session variable with:

$_SESSION['myusername'] = "Zagga";

you can check if it's set with:


See the PHP Manual for more info.