upgrade to website server to php 5.4.30 caused website not to work

Error Notices
Fatal error: Call to undefined function session_is_registered() in /home/cctvug/public_html/member_auth_fns.php on line 28
Fatal error: Call to undefined function session_is_registered() in /home/cctvug/public_html/member_auth_fns.php on line 28

I appreciate 5.4.30 no longer contains the session_is_registered type of function. Have tried to use $_SESSION etc but I have little knowledge on php, so that didn’t work !!

The Code attached is taken from a download I did before all this happened so should be how it was before 5.4.30 – Can any of you experts point me in the right direction on both member login to site, and admin login to amend the contents, both use similar code.

Thanks in advance for your help
Learner

[php][/php]

<? function login ($member_name, $password) // check member and password with db // if yes, return true //else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = MySQL_query(“select * from people where username='$member_name' and password = '$password' "); if (!$result) return 0; if (MySQL_num_rows($result)>0) return 1; else return 0; } function check_auth_member Some text here global $auth_member; if ( (session_is_registered("auth_member")) && (isset($auth_member)) ) return true; else return false; } ?>

Hello,

You can put session_register(); on the first line of every script that uses $_SESSION (I prefer to use this on all scripts since I don’t know if I’m going to be using it later or not). Then, assign ‘auth_member’ to a SESSION variable: $_SESSION[‘auth_member’] = ‘foo’. Then just use the following:

[php]if(isset($_SESSION[‘auth_member’]))[/php]

…in your check_auth_member function. This should stop the errors and allow your script to work as you want it.

Cheers!

[PHP]

<? //I always set an action such as do or fetch and then the type such as login, data etc function doLogin($member_name, $password) // check member and password with db // if yes, return true //else return false { // connect to db // You should be using an upto date query method I prefer PDO others like MySQLi $statement = $dbconn->prepare(" SELECT id, username, email, password FROM users WHERE username = :username "); $statement->execute([ ":username" => $member_name ]); //Result into array $row = $statement->fetchAll(PDO::FETCH_ASSOC); //Check user exists if (!$row){ //User does not exist echo "User does not exist"; return false; }else { //Check if password is correct //How to verify a password: http://php.net/manual/en/function.password-verify.php //How to hash a password: http://php.net/manual/en/function.password-hash.php if (password_verify($row['password'], password_hash($password, PASSWORD_DEFAULT))) { //User is authenticated get their details and create a session session_start(); //Set session variables that you may need to use while ($row){ $_SESSION['USERID'] = $row['id']; $_SESSION['USERNAME'] = $row['username']; $_SESSION['USEREMAIL'] = $row['email']; if (isset($_SESSION) && ($_SESSION ! == '')){ echo "You have been logged in"; return true; }else { //Session was not set echo "There was a technical problem logging you in"; return false; }//End check session } //End while row } else { //Password was incorrect echo "Your password was incorrect"; return false; } //End password verify }//End check if user exists }//End doLogin //Usage if (doLogin($_POST['member_name'],$_POST['password'])){ //Proceed }else { echo "

Please try again

"; showLogin(); } ?>

[/PHP]

Thanks to the two respondents

I have tried both and neither have worked with the following errors when anyone logs in
but most probably my lack of knowledge and experience on php.

For members log in Parse error: syntax error, unexpected ‘return’ (T_RETURN), expecting ‘,’ or ‘;’ in member_auth_fns.php on line 42

The line 42 reads “return false;”

For users of contacts log in :- Parse error; syntax error, unexpected ‘if’ (T_IF) in user_auth_fns.php on line 29

Line 29 reads if(isset($_SESSION[‘user_auth’]))

Full code that errors relate to are

<? function doLogin($member_name, $password) // check member and password with db // if yes, return true // else return false { // connect to db // use PDO query method $statement=$dbconn->prepare(" SELECT id, username, email, password FROM people WHERE username= :username "); $statement->execute([ ":username" => $member_name ]); //Result into array $row = $statement->fetchAll(PDO::FETCH_ASSOC); //Check user exists if(!$row){ //User does not exist echo "User does not exist" return false; }else{ //check if password is correct //How to verify password: http://php.net/manual/en/function.password-verify.php //How to hash a password: http://php.net/manual/en/function.password-hash.php if(password_verify($row['password'], password_hash($password, PASSWORD_DEFAULT) )){ //User is authenticated get their details and create a session session_start(); //Set session variables that may need to use while($row){ $_SESSION['USERID'] = $row['id']; $_SESSION['USERNAME'] = $row['username']; if(isset($_SESSION)&&($_SESSION! == ")){ echo "You have been logged in"; return true; }else{ //Session was not set echo "There was a technical problem logging you in"; return false; }//End check session }//End while row }else{ //Password was incorrect echo "Your password was incorrect"; return false; }//End password verify }//End check if user exists }//End doLogin //Usage if(doLogin($_POST['member_name'],$_POST['password'])){ //Proceed }else{ echo"

Please try again

"; showLogin(); } ?>

Please advise me where I am going wrong or any better way of doing it

I am

learning (albeit slowly!)

Apologies

the current code for User_auth_fns is below

<? function login($username, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("select * from users where username='$user_auth' and password = ('$password'"); if (!$result) return 0; if (mysql_num_rows($result)>0) return 1; else return 0; } function check_user_auth() // see if somebody is logged in and notify them if not { session_register(); global $user_auth; $_SESSION['user_auth']='foo' if(isset($_SESSION['user_auth'])) return true; else return false; } ?>

Two different approaches
Learning (Very Very slowly)

Coding as it is now Gives error message

Parse error: syntax error, unexpected ‘!’ in /home/cctvug/public_html/contacts/user_auth_fns.php on line 36

HELP DEEPLY WELCOMED

<? function doLogin($username, $password) // check username and password with db // if yes, return true // else return false { // connect to db // Use PDO uptodate query method $statement = $dbconn->prepare(" SELECT username, password FROM users WHERE username = :username "); $statement->execute([ "username" =>$username ]); //Result into array $row = $statement->fetchAll(PDO::FETCH_ASSOC); //Check user exists if (!$row){ This is the only other Line with ! No idea what it does //does not exist echo "User does not exist"; return false; }else { //Check if password is correct //Verify a password:http:php.net/manual/en/function.password-verify.php //Hash a password: http:php.net/manual/en/function.password-hash.php if (password_verify($row['password'], password_hash($password,PASSWORD_DEFAULT))){ session_start(); //set session variables that you might need to use while ($row){ $_SESSION['USERNAME'] = $row['username']; if (isset($_SESSION) && ($_SESSION ! == ")){ THIS IS LINE 36 With the unexpected ! echo "You have been logged in"; return true; }else { //Session was not set echo "There was a technical problem logging you in"; return false }//End check session }//End while row }else{ //Password was incorrect echo "Your password was incorrect"; return false }//End password verify }//End check if user exists }//End doLogin //Usage if (doLogin($_POST['username'],$_POST['password'])){ //Proceed }else{ echo "

Please try again

"; showLogin(); } ?>

Learning?


~$min login auth user As at 21 July.doc (162 Bytes)

First, PLEASE USE THE PROPER CODE TAGS WHEN POSTING CODE! They are the # and php buttons above the smileys, they are there for a reason.

Get rid of the space between the ! and == on line 36

Thanks fastsol

Apologies about the format I used

I deleted the space and then got Parse error: syntax error, unexpected ‘You’ (T_STRING) in /home/cctvug/public_html/contacts/user_auth_fns.php on line 37

So getting nearer!

Hope I have the presentation is right this time
[php] if (isset($_SESSION) && ($_SESSION !==")){
echo “You have been logged in”;
return true;
}else{
//Session was not set
echo “There was a technical problem logging you in”;
return false
}//End check session
}//End while row
}else{
//Password was incorrect
echo “User password was incorrect”;
return false
}//End password verify
}//End check if user exists
}//End doLogin

//Usage
if (doLogin($_POST[‘username’],$_POST[‘password’])){
//Proceed
}else{
echo “

Please try again

”;
showLogin();
}
?>[/php]

Learning

It’s always hard to tell in a forum post but are these single or double quotes?
[php]($_SESSION !==")[/php]
If they are double, then you’re missing one. You should be using a text editor that has proper highlighting of language code. If you are then you should have seen the syntax being highlighted wrong on the page, you can even see it on the forum post you just made.

Very good question

The script came from one of your colleagues the 2nd to replies below, scottlpool2003. I was confused and tried it both as " and ’ ’ which also explains my extra space between !and ==. Doing it as ’ ’ seems to have resolved that error , it has now moved to line 43!!!

I am a total newbie and greatly appreciate your support I think it is one of many, many mistakes. The tortal text is now but a problem with line 43 End check session

[php]<?
function doLogin($username, $password)
// check username and password with db
// if yes, return true
// else return false
{
// connect to db
// Use PDO uptodate query method
$statement = $dbconn->prepare("
SELECT username, password
FROM users
WHERE username = :username
");
$statement->execute([
“username” =>$username
]);
//Result into array
$row = $statement->fetchAll(PDO::FETCH_ASSOC);

//Check user exists
if (!$row){
//does not exist
echo “User does not exist”;
return false;
}else {
//Check if password is correct
//Verify a password:http:php.net/manual/en/function.password-verify.php
//Hash a password: http:php.net/manual/en/function.password-hash.php

if (password_verify($row[‘password’], password_hash($password,PASSWORD_DEFAULT))){

session_start();
//set session variables that you might need to use
while ($row){
$_SESSION[‘USERNAME’] = $row[‘username’];
if (isset($_SESSION) && ($_SESSION !==’’ )){
echo “You have been logged in”;
return true;
}else{
//Session was not set
echo “There was a technical problem logging you in”;
return false
}//End check session
}//End while row
}else{
//Password was incorrect
echo “User password was incorrect”;
return false
}//End password verify
}//End check if user exists
}//End doLogin

//Usage
if (doLogin($_POST[‘username’],$_POST[‘password’])){
//Proceed
}else{
echo “

Please try again

”;
showLogin();
}
?>[/php]

This is the latest position with all the script having thanks to your help sorted many of the other errors, but when one is solved another turns up!!

With Fatal error Call to member function prepare() on a non-object in public_html/contacts/user_auth_fns.php on line 9 - this is actually line 10 on attachment

Hope I managed to send this in the correct format

If anyone can see other problems please let me know

Learning all the time

You need to make sure that the PDO drivers are installed and it is listed as an extension, it may not be.

Run this at the top of the page:

[PHP]

<?php echo phpinfo();?>

[/PHP]

CTRL & F “PDO” what are you seeing?

You can use this too:

[PHP]

<?php if ( extension_loaded('pdo') ) { echo "PDO Loaded"; } ?>

[/PHP]

Trying it

First I put it on line one and calling up the site no error code but lots of details about php 5.4.30

So then kept the <? on line one and your first suggestion line 2 got an error code

Tried it as below and page is the The php info re 5.4.30 again

[php] ?>

<?php echo phpinfo();?>

if ( extension_loaded(‘pdo’) ) {
echo “PDO Loaded”;
}
function doLogin($username, $password)
// check username and password with db
// if yes, return true
// else return false
{
// connect to db
// Use PDO uptodate query method
$statement = $dbconn->prepare("
SELECT username, password
FROM users
WHERE username = :username
");
$statement->execute([
“username” =>$username
[/php]

Just put a php file onto the server containing this:

[PHP]

<?php echo phpinfo(); ?>

[/PHP]

mysql_free_result
mysql_fetch_object
mysql_num_rows

hello
i use this function but in php 5.4.30 i cant use anymore, how can i replace/change with another who can work in php 5.4.30 ?

thks

Sponsor our Newsletter | Privacy Policy | Terms of Service