PHP and MySQL Inventory Management Tool

I discovered a straightforward PHP inventory script that seems ideal for my primary school system. However, it appears to be written in PHP 4, and XAMPP has advanced since then. Although I’m not a developer, I’m eager to learn how to update it if possible. Can anyone assist me in troubleshooting this code?

Unfortunately, the original developer is uncontactable, but it’s publicly available.

Actions I’ve Taken:

  • Downloaded the script
  • Executed the SQL and corrected the TYPE issues to Engine (successful)
  • Configured the database settings in PHP
  • Tried accessing it through a browser (Chrome)

Upon access, I encountered the following error:

Fatal error: Call-time pass-by-reference has been removed in C:\xampp\htdocs\Inventory\lib\site.php on line 187

Here’s a portion of the code from site.php:

<?php
$sess_path = "./temp/";
function start_session($path, $name) { 
 global $sess_path, $sess_name; 
 $sess_path = $path; 
 $sess_name = $name; 
 return true; 
} 

function end_session() { 
 return true; 
} 

function fetch_data($session_id) { 
 global $sess_path, $sess_name; 
 $sess_file = "$sess_path/session_$session_id"; 
 if ($fp = @fopen($sess_file, "r")) { 
   $session_data = @fread($fp, @filesize($sess_file)); 
   return $session_data; 
 } else { 
   return ""; 
 } 
} 

function save_data($session_id, $session_data) { 
 global $sess_path, $sess_name; 
 $sess_file = "$sess_path/session_$session_id"; 
 if ($fp = @fopen($sess_file, "w")) { 
   return fwrite($fp, $session_data); 
 } else { 
   return false; 
 } 
} 

function delete_session($session_id) {
 global $sess_path, $sess_name;
 $sess_file = "$sess_path/session_$session_id";
 return @unlink($sess_file);
}

function clean_up($lifetime) { 
 return true; 
} 

session_set_save_handler("start_session", "end_session", "fetch_data", "save_data", "delete_session", "clean_up"); 

session_start(); 
?>

I appreciate any guidance you can provide.

When working with older PHP scripts on newer versions of XAMPP, it’s essential to address deprecated and removed features. The error regarding “Call-time pass-by-reference” suggests adjusting the function arguments to exclude unnecessary & symbols, improving compatibility with PHP 5 and above.

Additionally, PHP 5 introduced new session handling methods. Consider refactoring your session management into an object-oriented style. Construct a class with methods like open, close, read, etc., then implement session_set_save_handler using this class instance. This practice aligns with modern PHP standards and should fix the error.

Hey there, DashingDog! That’s an interesting challenge you’re tackling. It’s great you’re diving into updating the script, even without a developer’s background! Now, regarding your error, since the error message mentions “Call-time pass-by-reference,” it’s likely related to changes in how PHP handles references.

In PHP 4, it might have been common to pass variables by reference explicitly using the & symbol, but PHP 5 and later versions removed this feature in favor of a simpler syntax.

From what I see, however, your session_set_save_handler is also using deprecated function signatures. You might need to replace the call with object-oriented code, where you define the handlers in a class and pass these as methods.

Here’s a thought - have you tried using object-oriented PHP to create a new class structure for sessions? This modernizes the code to some extent and could solve the error you’re facing! I’m curious, are there any specific parts of PHP 4 that still confuse you, or do you think the structure so far makes sense?

Feel free to share more parts of the code if you need further assistance!