Getting Fatal error: Call to undefined function session_register()

can anyone help me with this code i’m new with PHP?

<?php 
include("db.php");
global $dbServer, $dbUser, $dbPass, $dbName;
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
session_start();
include("sessions.php");
$domain_name="";
$domain_name=$_SERVER['HTTP_HOST'];

global $domain_name;
$auth="";
$cookie=split('@', $_COOKIE['customers_ID']);
$customers_id=$cookie[1];

$_SESSION['customers_id']=$customers_id;

if(!session_is_registered("lang") ||  $content=="lan"){
session_register("lang");
session_register("txt");
if($id=="" || $id=="3"){
$_SESSION['lang']="ch";
$_SESSION['txt']="3";
}else if($id==1){
$_SESSION['lang']="en";
$_SESSION['txt']="1";
}else{
$_SESSION['lang']="ch";
$_SESSION['txt']="3";
}
header("Location: ".$_SERVER['HTTP_REFERER']);
}
$lan=$_SESSION['txt'];
$lang=$_SESSION['lang'];
global $lan;
global $lang;

if(!file_exists($content.".php")){
$content="home";
}

if($content=="account"  || $content=="order" || $content=="edit_profile" || $content=="show_order" || $content=="orders" ){

include("includes/chk_sign_in.php");
if(chk_login()==false){
header("Location: ".$domain."index.php/login");
}
}

$get_info=@mysql_query("select * from sessions where sesskey='".GetCartId()."'");
$row_get_info=mysql_fetch_array($get_info); 

define('SERVER_ADDRESS', 'http://www.ups.com/using/services/rave/qcostcgi.cgi?accept_UPS_license_agreement=yes&10_action=4&13_product=3DS&14_origCountry=US&15_origPostal=11354&');	
?>

This code is way out of date. Session_register() and related functions were removed 7 yeas ago. The mysql_ database extension was removed 3 and a half years ago.

The code is also using @ error suppressors, global statements where they don’t mean anything, header() redirects without any exit/die statements to stop program execution, and static user identifiers in a cookie. It’s also referencing variables that don’t exist in the posted code, so it is probably dependent on register globals, which were removed 7 years ago too, nor is it validating values and so is probably open to cross site scripting and directory transversal.

It would take going through all the code, rewriting it to current standards, and adding validation and security.

2 Likes

yes the site folder was very old was using old PHP 5.2 below. Is there a better way to convert 5.2 to maybe 5.6+ PHP instead go every php file and modify them?

If you are expecting an ‘automated’ way of converting old code, the answer is no. It takes finding out where values are ‘magically’ coming from, such as the $id and $content variables in the posted code, in order to get the code to work again.

The php.net documentation contains migration appendixes that list the major changes made to php over time. You would need to go through all the removed and backward incompatible changes and update the code as needed.

thank you for quick reply. This is someone else website they just asked for my help to set this up for them. Will you able to help fix if i send you those files?.

We are not here fix code for you. If it is beyond your skill level to update the code, you will need to find different code or pay someone to do the work.

1 Like

If you don’t want to do your test over and over again manually you should considering automatic tests.

where the automatic tools?

i would recommend starting with PHPUnit.

Thanks. I will take a look. :sunglasses:

Sponsor our Newsletter | Privacy Policy | Terms of Service