Reputation: 15459
Here is the include file called 'VariablesFunctions.php':
$currWebPage = '';
function getPageUrl( )
{
global $currWebPage;
if( $_SERVER['HTTPS'] == 'on' ) $currWebPage .= 's';
$currWebPage .= '://';
if( $_SERVER["SERVER_PORT"] != "80" )
$currWebPage .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else $currWebPage .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
here is the file (index.php) which calls it:
<?php include( 'VariablesFunctions.php' );
getPageUrl( );
echo $currWebPage;
?>
both files are saved in same directory, and when launching the index.php file the browser says undefined function (line 2 above in index.php file), why?
Upvotes: 1
Views: 174
Reputation: 145482
This sometimes means another include file with the same name (old or backup version) exists elsewhere in the include_path. To avoid that, use an explicit path and force it to fail reliably:
<?php require('./VariablesFunctions.php');
getPageUrl();
The issue might also be caused by your mixed-case filenames. On BSD/Linux servers the filenames must match exactly, they are not considered case-insensitive.
Also: avoid returning results via a global variable, make it a proper return value.
Upvotes: 2