function error problem

+1 lakshya pal · July 11, 2014
stuck in this error..please help 


<!--?php</font-->
 $user_ip = $_SERVER('REMOTE_ADDR');


function echo_ip(){
global $user_ip;
$string ='Your ip address is:'.$user_ip;
echo $string;

echo_ip();
?>




OUTPUT: Fatal error: Function name must be a string in C:\xampp\htdocs\series\firstfile\global_var.php on line 2

Post a Reply

Replies

Oldest  Newest  Rating
+2 Franz Schmidt · July 11, 2014
You need to use square brackets "[]" instead of normal brackets "()":

<?php
$user_ip = $_SERVER['REMOTE_ADDR'];

function echo_ip(){
global $user_ip;
$string = 'Your ip address is:'.$user_ip;
echo $string;
}
echo_ip();
?>

+1 Alan Johnson · July 12, 2014
$user_ip = $_SERVER['REMOTE_ADDR'];

$_SERVER is a global array.
+1 Chathula Sampath · July 12, 2014

 $user_ip = $_SERVER('REMOTE_ADDR');


is wrong.. it should be


$user_ip = $_SERVER['REMOTE_ADDR'];


0 Shamal Sandeep · August 8, 2014
Best options is to use ip as global


$GBLOBALS['ip'] = $_SERVER['REMOTE_ADDR'];

echo $GBLOBALS['ip'];
0 Shamal Sandeep · August 8, 2014
@Linguist llama  Yup Indeed! They're so great when we are creating init.php file for our app. We can use it anywhere is classes methods and most commonly in procedural coding!
-1 Samuel Oloruntoba · July 14, 2014
WOW!!!
  • 1

PHP

107,104 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators