depracated error appears

Can someone please tell me what I need to do to make this message go away…

“Deprecated: Function session_register() is deprecated in C:\xampp\htdocs\html-5\administrator\admin_check.php on line 20”

Here is the script below I don’t how to make this go away.

[php]<?php

$error_msg = “”;

if (isset ($_POST[‘username’])) {

$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
// Simple hard coded values for the correct username and password
$admin = "mark";
$adminpass = "tiko";
// connect to mysql here if you store admin username and password in your database
// This would be the prefered method of storing the values instead of hard coding them here into the script
if (($username != $admin) || ($password != $adminpass)) {
	$error_msg = ': <font color="#FF0000">Your login information is incorrect</font>';
} else {
	session_register('admin');
    $_SESSION['admin'] = $username;
	require_once "index.php";
	exit();
}

}// close if post username
?>

<?php if ($_SESSION['admin'] != "mark") { echo '

Only the administrator can view this directory


Please Log In Here' . $error_msg . '
Username:
Password:



Or click here to head back to the homepage'; exit(); } ?>

[/php]

Your help is kindly appreciated
thanks

Hi there,

Just delete the line it’s not necessary.

session_register() is not longer a valid PHP function.

To declare a session variable, you need to do it as follow:

[php]$_SESSION[‘user’]= ‘username’;[/php].

or if you are passing a form variable, say username from a login form, you would do something like this:

[php]$_SESSION[‘user’]= $user[‘username’];//Pull Username from login form[/php]

And even more complete, here’s a query:
[php]

$username =$_POST[‘username’];// assign short variable name

            if (isset($username)){								                
            
            //PULL username
	$query = mysql_query("SELECT * FROM authorized_users WHERE username = '$username' ") or die(mysql_error() );
	$user= mysql_fetch_array($query);
           			
            $_SESSION['user']= $user['username']; //Session created from username field value entered by user. Form value must match database value for user name.

[/php]

Thanks that really helped…

I am glad it worked out for you. Take care.

Sponsor our Newsletter | Privacy Policy | Terms of Service