Page 1 of 1

PHP Deprecated

Posted: Mon Aug 18, 2014 5:15 am
by latifhamzah
Hi All,

I am new to this forum and also to PHP programming, i am fixing a PHP based website build in 2012 by another developer. (No technical documentation)

I have this http://creativecontent.my/controllers/public/index.php for me to display my frontpage.
UNFORTUNATELY, it just show me blank page.

Now i do a VM to test the website before i do a publish, but i got into trouble with this.

Error_Log i got from local server is:-
[text] /var/www/html/controllers/public/.htaccess: Options not allowed here
[error] [client xxxxxxxx] PHP Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/html/controllers/controllers.php on line 13
[error] [client xxxxxx] PHP Stack trace:
[error] [client xxxxxx] PHP 1. {main}() /var/www/html/controllers/public/index.php:0
[error] [client xxxxxxx] PHP 2. require() /var/www/html/controllers/public/index.php:6
[error] [client xxxxxxxx] PHP Fatal error: Call to undefined function display_page_title() in /var/www/html/configs/connections.php on line 41
[error] [client xxxxx] PHP Stack trace:
[error] [client xxxxx] PHP 1. {main}() /var/www/html/controllers/public/index.php:0
[error] [client xxxxx] PHP 2. require() /var/www/html/controllers/public/index.php:6
[error] [client xxxxx] PHP 3. include() /var/www/html/controllers/controllers.php:158
[/text]
-------------------------------------------------------------------------------------
/var/www/html/controllers/public/.htaccess: Options not allowed here
I have rename the file to avoid these error and i got others error.

controllers.php on line 13

Code: Select all

set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
connections.php on line 41

Code: Select all

$configs['page_title'] = display_page_title();
Please help, the website should be looking like this http://creativecontent.my

Thanks in advance for any help.

Re: PHP Deprecated

Posted: Mon Aug 18, 2014 5:52 am
by pbs
Your testing VM has latest PHP version, whereas the script is done according to old PHP version.
Since PHP 5.3 set_magic_quotes_runtime() function has been deprecated
http://php.net/manual/en/function.set-m ... untime.php

Re: PHP Deprecated

Posted: Mon Aug 18, 2014 9:23 pm
by latifhamzah
Any idea how can i fix this?

controllers.php

Code: Select all

<?php
//error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
error_reporting(E_ALL & ~E_NOTICE);
ini_set("max_execution_time",0);
if ( !defined('IN_PLATFORM') )
{
	die("Hacking attempt");
}


//error_reporting  (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
//error_reporting(E_ALL);
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime

// The following code (unsetting globals)
// Thanks to Matt Kavanagh and Stefan Esser for providing feedback as well as patch files

// PHP5 with register_long_arrays off?
if (@phpversion() >= '5.0.0' && (!@ini_get('register_long_arrays') || @ini_get('register_long_arrays') == '0' || strtolower(@ini_get('register_long_arrays')) == 'off'))
{
	$HTTP_POST_VARS = $_POST;
	$HTTP_GET_VARS = $_GET;
	$HTTP_SERVER_VARS = $_SERVER;
	$HTTP_COOKIE_VARS = $_COOKIE;
	$HTTP_ENV_VARS = $_ENV;
	$HTTP_POST_FILES = $_FILES;

	// _SESSION is the only superglobal which is conditionally set
	if (isset($_SESSION))
	{
		$HTTP_SESSION_VARS = $_SESSION;
	}
}

// Protect against GLOBALS tricks
if (isset($HTTP_POST_VARS['GLOBALS']) || isset($HTTP_POST_FILES['GLOBALS']) || isset($HTTP_GET_VARS['GLOBALS']) || isset($HTTP_COOKIE_VARS['GLOBALS']))
{
	die("Hacking attempt");
}

// Protect against HTTP_SESSION_VARS tricks
if (isset($HTTP_SESSION_VARS) && !is_array($HTTP_SESSION_VARS))
{
	die("Hacking attempt");
}

if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
{
	// PHP4+ path
	$not_unset = array('HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_SERVER_VARS', 'HTTP_SESSION_VARS', 'HTTP_ENV_VARS', 'HTTP_POST_FILES', 'phpEx', 'phpbb_root_path');

	// Not only will array_merge give a warning if a parameter
	// is not an array, it will actually fail. So we check if
	// HTTP_SESSION_VARS has been initialised.
	if (!isset($HTTP_SESSION_VARS) || !is_array($HTTP_SESSION_VARS))
	{
		$HTTP_SESSION_VARS = array();
	}

	// Merge all into one extremely huge array; unset
	// this later
	$input = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES);

	unset($input['input']);
	unset($input['not_unset']);

	while (list($var,) = @each($input))
	{
		if (in_array($var, $not_unset))
		{
			die('Hacking attempt!');
		}
		unset($$var);
	}

	unset($input);
}

//
// addslashes to vars if magic_quotes_gpc is off
// this is a security precaution to prevent someone
// trying to break out of a SQL statement.
//
if( !get_magic_quotes_gpc() )
{
	if( is_array($HTTP_GET_VARS) )
	{
		while( list($k, $v) = each($HTTP_GET_VARS) )
		{
			if( is_array($HTTP_GET_VARS[$k]) )
			{
				while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
				{
					$HTTP_GET_VARS[$k][$k2] = addslashes($v2);
				}
				@reset($HTTP_GET_VARS[$k]);
			}
			else
			{
				$HTTP_GET_VARS[$k] = addslashes($v);
			}
		}
		@reset($HTTP_GET_VARS);
	}

	if( is_array($HTTP_POST_VARS) )
	{
		while( list($k, $v) = each($HTTP_POST_VARS) )
		{
			if( is_array($HTTP_POST_VARS[$k]) )
			{
				while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
				{
					$HTTP_POST_VARS[$k][$k2] = addslashes($v2);
				}
				@reset($HTTP_POST_VARS[$k]);
			}
			else
			{
				$HTTP_POST_VARS[$k] = addslashes($v);
			}
		}
		@reset($HTTP_POST_VARS);
	}

	if( is_array($HTTP_COOKIE_VARS) )
	{
		while( list($k, $v) = each($HTTP_COOKIE_VARS) )
		{
			if( is_array($HTTP_COOKIE_VARS[$k]) )
			{
				while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
				{
					$HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
				}
				@reset($HTTP_COOKIE_VARS[$k]);
			}
			else
			{
				$HTTP_COOKIE_VARS[$k] = addslashes($v);
			}
		}
		@reset($HTTP_COOKIE_VARS);
	}
}

//
// Define some basic configuration arrays this also prevents
// malicious rewriting of language and otherarray values via
// URI params
//

$userdata = array();

                              
include('../../libraries/common.php');  
include('../../configs/constants.php'); 
include('../../libraries/mysql.php');     
include('../../configs/connections.php');
include('../../libraries/sessions.php');
require '../../libraries/Smarty.class.php';

$user_ip = $_SERVER['REMOTE_ADDR']; 
$userdata = p_session_pagestart($user_ip, $SubTitle);  
          
// We do not need this any longer, unset for safety purposes
unset($dbpasswd);

$views = new Smarty;
$views->template_dir = "../../views/";
$views->compile_dir = "../../cache/";
$views->assign('base_url', BASE_URL);
$views->assign('base_admin_url', BASE_ADMIN_URL);
$views->assign('base_member_url', BASE_MEMBER_URL);
$views->assign('base_mobile_url', BASE_MOBILE_URL);

$views->assign('base_aduan_url', BASE_ADUAN_URL);

$currentlang = getLang();
$currenttheme = themes();

$lang = lang($currentlang);

if (CONTROLLER=='member'){
	$userdata['session_theme'] = 'member';
	$views->assign('page_theme' , 'member'); 
	$currenttheme = 'member';
}

if (CONTROLLER=='mobile'){
	$userdata['session_theme'] = 'mobile';
	$views->assign('page_theme' , 'mobile'); 
	$currenttheme = 'mobile';
}

getTheme();
$client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
//$user_ip = encode_ip($client_ip);
$user_ip = $client_ip;
$configs['setting']=configs_setting();
?>
Do i need to re-code my whole websites?

Re: PHP Deprecated

Posted: Tue Aug 19, 2014 7:08 am
by Celauran
latifhamzah wrote:I have this http://creativecontent.my/controllers/public/index.php for me to display my frontpage.
Seeing the word controllers in the URL suggests that may not be the intended public route.
latifhamzah wrote:[error] [client xxxxxxxx] PHP Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/html/controllers/controllers.php on line 13
You will definitely need to do some refactoring to remove any instances of that function call.
latifhamzah wrote:[error] [client xxxxxxxx] PHP Fatal error: Call to undefined function display_page_title() in /var/www/html/configs/connections.php on line 41
As the error indicates, you're calling a function that doesn't exist. You'll either need to track down where the function is defined and why it isn't being included, write your own implementation of the function, or replace the function call with something else.

Re: PHP Deprecated

Posted: Tue Aug 19, 2014 7:11 am
by Celauran
latifhamzah wrote:Do i need to re-code my whole websites?
The code you showed isn't great, but I'd still try and salvage it through some refactoring before starting on a complete rewrite. If that isn't possible, or if it ends up being more work than a complete rewrite, then maybe rewrite is the way to go. Another consideration is whether the site has to be up and running in the meantime. Rewrites are a lot of work and obviously take a long time.

Re: PHP Deprecated

Posted: Wed Aug 20, 2014 3:33 am
by latifhamzah
Celauran, great comment.

Re-factoring will also take time as this code originally is not coded by me. Unfortunately, the person who coded it has left the company and i am picking up what's left.
Since our server upgrade to the most current version, this issues has been my most problem at the moment.

The website has to be up and running, now it's not running fully.

Re: PHP Deprecated

Posted: Wed Aug 20, 2014 6:40 am
by Celauran
Refactoring is definitely a long, slow process. The advantage over a full rewrite here is that it allows you to focus on the parts that are actually broken, get those fixed to get the site back up and running, and then slowly work on improving the code over time. I don't know what state the codebase as a whole is in, but my general approach is to try to clean up any code I touch as I work on it. As you implement new features or perform maintenance tasks, you can add in missing abstractions, start documenting existing functionality, and introduce some unit tests. I'd recommend trying to do some sort of code review on the project as a whole and, depending on the severity, talk to your PM about getting some hours just for cleaning this up.

Re: PHP Deprecated

Posted: Wed Aug 20, 2014 11:03 pm
by Weirdan
Celauran wrote:
latifhamzah wrote:I have this http://creativecontent.my/controllers/public/index.php for me to display my frontpage.
Seeing the word controllers in the URL suggests that may not be the intended public route.
No wonder, the OP has removed .htaccess file:
/var/www/html/controllers/public/.htaccess: Options not allowed here
I have rename the file to avoid these error and i got others error.

Re: PHP Deprecated

Posted: Sun Aug 24, 2014 11:34 pm
by latifhamzah
Hi,

Thanks for the reply, feedback and suggestion.

at the moment most of the issues i have manage to resolve, but most of the issues still there.
I have made a copy of the whole website and database to another hosting server (for test), a lot of improvement from the original server.

http://lynxhexagon.com/CCAM/controllers ... /index.php

at-least in here i can see some part of the landing page.

the "Deprecated: Function set_magic_quotes_runtime() is deprecated" still happening. Any help to guide me?

Re: PHP Deprecated

Posted: Mon Aug 25, 2014 5:43 am
by Celauran
As I mentioned above, you need to remove calls to that function.