用php提取IP作为JAVASCRIPT变量用提示"缺少';'"
<script type="text/javascript" language="javascript">
<?php
function GetIP(){
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$cip = $_SERVER["HTTP_CLIENT_IP"];
}
elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
elseif(!empty($_SERVER["REMOTE_ADDR"])){
$cip = $_SERVER["REMOTE_ADDR"];
}
else{
$cip = "无法获取!";
}
return $cip;
}
?>
var frip=<?php echo GetIP()?>;
</script>
如果不用
var frip=<?php echo GetIP()?>;
是正常的
否则提示
function GetIP(){
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
缺少“;”
[解决办法]
var frip="<?php echo GetIP()?>";