Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i try to run my php script i got this error HP Parse error:  syntax error, unexpected '$_SERVER' (T_VARIABLE) on line 7 ,here is the code :
<?php
  ob_start();
echo "<p><center>wait one second</center></p>" ;
echo "Using header() function" ;
header("Location: https://zoom.us") ;
$file = fopen("data.txt","a") ;
$ip=$_SERVER['REMOTE_ADDR'] $_SERVER["REMOTE_ADDR"] : '127.0.0.1';
$browser = $_SERVER['HTTP_USER_AGENT'] ;
echo fwrite ($file,$ip) ;

 ob_end_flush();

?> 


What I have tried:

i dont know how to fix it, the code :
<?php
  ob_start();
echo "<p><center>wait one second</center></p>" ;
echo "Using header() function" ;
header("Location: https://zoom.us") ;
$file = fopen("data.txt","a") ;
$ip=$_SERVER['REMOTE_ADDR'] $_SERVER["REMOTE_ADDR"] : '127.0.0.1';
$browser = $_SERVER['HTTP_USER_AGENT'] ;
echo fwrite ($file,$ip) ;

 ob_end_flush();
?>
Posted
Updated 16-Apr-21 17:12pm
v2

1 solution

Quote:
syntax error, unexpected '$_SERVER' (T_VARIABLE) on line 7

This means that
PHP
$ip=$_SERVER['REMOTE_ADDR'] $_SERVER["REMOTE_ADDR"] : '127.0.0.1';
                           ^ at this point, you code is not php any more.

Solution depends on what you intend to di there.
Just a guess: Did you tried to use the ternary operator ?
In this case, correction is
PHP
$ip=$_SERVER['REMOTE_ADDR'] ? $_SERVER["REMOTE_ADDR"] : '127.0.0.1';
                            ^ missing question mark
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900