0

I use the following script as my check login and login:

<?php
        
   include('../db_connections/aardb_conn.php'); 
   session_start(); 
   
         #***********************************
         # get info from form.
         #***********************************
        
            $myusername=$_POST['email']; 
            $mypassword=$_POST['pass']; 
            
             
                 $sql="SELECT * FROM users WHERE email='$myusername' and password='$mypassword'";
               
      $result=mysql_query($sql, $db_conn);
      $count=mysql_num_rows($result);

       if ($count==1)
       {
         session_register("my_username");
         session_register("userid");
         $row = mysql_fetch_assoc($result) ;
         $_SESSION['my_username']= $row[fname]." ".$row[lname] ;
         $_SESSION['userid']=$row[autoid] ;
         
          mysql_free_result($result);
              
              header("location:../account.php");
             }#end of if
        else 
           {  
              header("location:../attempt.php");
        }#end of else
?>

But I get the following error:

Deprecated: Function session_register() is deprecated in /home/content/80/11429180/html/admin/logs/checklogin.php on line 35

Deprecated: Function session_register() is deprecated in /home/content/80/11429180/html/admin/logs/checklogin.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at /home/content/80/11429180/html/admin/logs/checklogin.php:35) in /home/content/80/11429180/html/admin/logs/checklogin.php on line 43

Community
  • 1
  • 1
Billeh Sarkozy
  • 53
  • 1
  • 3
  • 9
  • 3
    It may be unexpected, but.. this function is really deprecated. – Alma Do Nov 06 '13 at 11:12
  • possible duplicate of [How to fix the session\_register() DEPRECATED problem?](http://stackoverflow.com/questions/3682615/how-to-fix-the-session-register-deprecated-problem) – lonesomeday Nov 06 '13 at 11:13

4 Answers4

2

Instead of using session_register, use:

$_SESSION["my_variable"] = 'Hello';

Its the recommended way of creating session variables and I think you'll agree that it is cleaner than using session_register:

$test = "Hello";
session_register("test");
Wayne Whitty
  • 19,088
  • 5
  • 43
  • 65
1

From the manual page:

// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";
Clart Tent
  • 1,339
  • 2
  • 9
  • 11
1

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

In older version of PHP 5.3

    session_register("nameofthesession");

New PHP version 5.3(After)

    $_SESSION['nameofthesession'] = $nameofthesession;
Krish R
  • 22,188
  • 7
  • 49
  • 57
0

just avoid session_register()

use directly this

$_SESSION['name']=$name;
ddb
  • 2,405
  • 7
  • 26
  • 36
Manoj Gupta
  • 63
  • 1
  • 9