Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0

    Call to undefined function session_register()


    Hi Everyone

    I am hoping someone can help me, I have been put in charge of sorting this out, so please excuse my lack of knowledge

    Apparently, the admin person can't login to the admin side of the website because of the above message. The error points to line 41.

    Line 41 is this
    PHP Code:
      session_register("MM_Username"); 
    Any suggestions would be very grateful.

    Kind regards

    Phil
    PHP Code:
    <?php require_once('../Connections/website_forms.php'); ?>
    <?php
    mysql_select_db
    ($database_website_forms$website_forms);
    $query_Recordset1 "SELECT * FROM applicants";
    $Recordset1 mysql_query($query_Recordset1$website_forms) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
    ?>
    <?php
    // *** Validate request to login to this site.
    session_start();

    $loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $accesscheck)) {
      
    $GLOBALS['PrevUrl'] = $accesscheck;
      
    session_register('PrevUrl');
    }

    if (isset(
    $_POST['name'])) {
      
    $loginUsername=$_POST['name'];
      
    $password=$_POST['email'];
      
    $MM_fldUserAuthorization "";
      
    $MM_redirectLoginSuccess "success.php";
      
    $MM_redirectLoginFailed "index.php";
      
    $MM_redirecttoReferrer false;
      
    mysql_select_db($database_website_forms$website_forms);
      
      
    $LoginRS__query=sprintf("SELECT username, password FROM applicants WHERE username='%s' AND password='%s'",
        
    get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername), get_magic_quotes_gpc() ? $password addslashes($password)); 
       
      
    $LoginRS mysql_query($LoginRS__query$website_forms) or die(mysql_error());
      
    $loginFoundUser mysql_num_rows($LoginRS);
      if (
    $loginFoundUser) {
         
    $loginStrGroup "";
        
        
    //declare two session variables and assign them
        
    $GLOBALS['MM_Username'] = $loginUsername;
        
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;          

        
    //register the session variables
        
    session_register("MM_Username");
        
    session_register("MM_UserGroup");

        if (isset(
    $_SESSION['PrevUrl']) && false) {
          
    $MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
    header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
    header("Location: "$MM_redirectLoginFailed );
      }
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <p>&nbsp;</p>
    <form ACTION="<?php echo $loginFormAction?>" method="POST" name="login_form" id="login_form">
    <table width="400"  border="0" align="center" cellpadding="1" cellspacing="0">
      <tr>
        <td>Username</td>
        <td><input name="name" type="text" id="name"></td>
      </tr>
      <tr>
        <td>Email</td>
        <td><input name="email" type="text" id="email"></td>
      </tr>
      <tr>
        <td>Login</td>
        <td><input name="login" type="submit" id="login" value="Login"></td>
      </tr>
    </table></form>
    <p>&nbsp;</p>

    </body>
    </html>
    <?php
    mysql_free_result
    ($Recordset1);
    ?>
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,333
    Rep Power
    9645
    Take a look at the documentation to see if you can spot what the reason might be.

    Really, the whole file uses old code (session_register, the mysql_* functions, and it checks for magic_quotes) and needs to be rewritten.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Location
    Germany
    Posts
    2
    Rep Power
    0
    Thanks for the documentation!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    Hi Requinix
    Thanks for the information. I have looked through it, but it doesn't make a lot of sense. I am happy to learn and experiment with small code changes to the original code, so if you can help in anyway, that would be great.
    Phil
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,322
    Rep Power
    630
    Start with removing the deprecated mysql* code. Use PDO or at least mysqli*.
    Last edited by gw1500se; July 31st, 2017 at 01:33 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,333
    Rep Power
    9645
    Originally Posted by philweb
    Hi Requinix
    Thanks for the information. I have looked through it, but it doesn't make a lot of sense. I am happy to learn and experiment with small code changes to the original code, so if you can help in anyway, that would be great.
    Phil
    The important bit on that page I linked to was
    This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
    The example above it shows the correct way to manage session values.
    PHP Code:
    <?php
    // Use of session_register() is deprecated
    $barney "A big purple dinosaur.";
    session_register("barney");

    // Use of $_SESSION is preferred
    $_SESSION["zim"] = "An invader from another planet.";
    ?>
    Replace each of your calls to session_register() with an assignment using the variable and $_SESSION, then make sure you don't modify the variable later in the script - or if you do, that you update what's in $_SESSION.

    If you're having a problem with that then post your code.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    The important bit on that page I linked to was


    The example above it shows the correct way to manage session values.
    PHP Code:
    <?php
    // Use of session_register() is deprecated
    $barney "A big purple dinosaur.";
    session_register("barney");

    // Use of $_SESSION is preferred
    $_SESSION["zim"] = "An invader from another planet.";
    ?>
    Replace each of your calls to session_register() with an assignment using the variable and $_SESSION, then make sure you don't modify the variable later in the script - or if you do, that you update what's in $_SESSION.

    If you're having a problem with that then post your code.
    Hi
    I get what you are saying about the session_register() being depreciated. I guess my hosting company have updated their PHP!
    I have replaced the session_register with $_SESSION, and the good news is I don't get a fatal error, but it doesn't go to the success.php either.
    Any clues?
    Here is the code so far -
    PHP Code:
    <?php require_once('../Connections/website_forms.php'); ?>
    <?php
    mysql_select_db
    ($database_website_forms$website_forms);
    $query_Recordset1 "SELECT * FROM applicants";
    $Recordset1 mysql_query($query_Recordset1$website_forms) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
    ?>
    <?php
    // *** Validate request to login to this site.
    session_start();

    $loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $accesscheck)) {
      
    $GLOBALS['PrevUrl'] = $accesscheck;
      
    $_SESSION['PrevUrl'];
    }

    if (isset(
    $_POST['name'])) {
      
    $loginUsername=$_POST['name'];
      
    $password=$_POST['email'];
      
    $MM_fldUserAuthorization "";
      
    $MM_redirectLoginSuccess "success.php";
      
    $MM_redirectLoginFailed "index.php";
      
    $MM_redirecttoReferrer false;
      
    mysql_select_db($database_website_forms$website_forms);
      
      
    $LoginRS__query=sprintf("SELECT username, password FROM applicants WHERE username='%s' AND password='%s'",
        
    get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername), get_magic_quotes_gpc() ? $password addslashes($password)); 
       
      
    $LoginRS mysql_query($LoginRS__query$website_forms) or die(mysql_error());
      
    $loginFoundUser mysql_num_rows($LoginRS);
      if (
    $loginFoundUser) {
         
    $loginStrGroup "";
        
        
    //declare two session variables and assign them
        
    $GLOBALS['MM_Username'] = $loginUsername;
        
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;          

        
    //register the session variables
        
    $_SESSION["MM_Username"];
        
    $_SESSION["MM_UserGroup"];

        if (isset(
    $_SESSION['PrevUrl']) && false) {
          
    $MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
    header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
    header("Location: "$MM_redirectLoginFailed );
      }
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <p>&nbsp;</p>
    <form ACTION="<?php echo $loginFormAction?>" method="POST" name="login_form" id="login_form">
    <table width="400"  border="0" align="center" cellpadding="1" cellspacing="0">
      <tr>
        <td>Username</td>
        <td><input name="name" type="text" id="name"></td>
      </tr>
      <tr>
        <td>Email</td>
        <td><input name="email" type="text" id="email"></td>
      </tr>
      <tr>
        <td>Login</td>
        <td><input name="login" type="submit" id="login" value="Login"></td>
      </tr>
    </table></form>
    <p>&nbsp;</p>

    </body>
    </html>
    <?php
    mysql_free_result
    ($Recordset1);
    ?>
  14. #8
  15. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,333
    Rep Power
    9645
    Look at your code.
    PHP Code:
    $_SESSION['PrevUrl']; 
    Now the example code.
    PHP Code:
    $_SESSION["zim"] = "An invader from another planet."
    Now back to yours.
    PHP Code:
    $_SESSION['PrevUrl']; 
    Now back to the example's.
    PHP Code:
    $_SESSION["zim"] = "An invader from another planet."
    Sadly, it isn't yours, but if you learned what it was doing and fixed your code appropriately, it could look like the example.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    Ok, so the session is an instruction to do something, yes? If so, I need to tell it to go to the success.php page somehow. Am I on the right track?

    Regards
    Phil
    PHP Code:
    $_SESSION["prevUrl"] = "go and do something" 
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    So; Session variables hold information about one single user, and are available to all pages in one application. I am the single user, so how can I change the code so the $_SESSION holds my user information?

    Kind regards

    Phil
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,322
    Rep Power
    630
    You need to understand how sessions work. The $_SESSION variable is an associative array. That is, it is a variable that holds values not an instruction to do something. The session variable only applies to the session for which it was started. Any other session (different user) becomes an entirely different set of values independent of each other.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    Hi
    Thanks for explaining that.
    So I still need to login to the website. So I need to code the $_SESSION so it holds the value of my login from the session_start()? If so, how can I find out what the value of session_start() is?
    Kind regards
    Phil
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,322
    Rep Power
    630
    You don't need to worry about it. The session manager keeps track of that for you. The session_start() will reconnect the client, from the same source, to the appropriate session. All the session data will be preserved unless session_destroy() is called.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    Thanks for reply. I am still non the wiser in fixing things myself. Are you able to help me fix the problem please?
    Kind regards
    Phil
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,322
    Rep Power
    630
    This is a help forum, not a free programming forum. I suggest you make this request on the Hire A Programmer forum.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo