[英]php script does not work. but if I include it in other file, it works?
I have this half-written script, and it will not work at all 我有这个半写的脚本,它根本不起作用
<?php
function hit_count() {
echo $ip_address = $_SERVER['REMOTE_ADDR'];
$ip_file = file('ip.txt');
foreach ($ip_file as $ip) {
$ip_single = trim($ip);
if ($ip_address==$ip_single) {
$found = false;
} else {
$found = true;
}
}
if ($found==false) {
echo 'IP not found.';
}
}
?>
even the first line will not display anything. 即使第一行也不会显示任何内容。 but lo and behold, if I include it in this file
但请注意,如果我将其包含在此文件中
<?php
include 'unique-counter.php';
hit_count();
?>
the "echo" displays my ip. “回声”显示我的IP。
how does that happen? 怎么发生的?
Your script by itself only defines a function, it does not call it. 您的脚本本身仅定义一个函数,而不会调用它。
Add hit_count();
添加
hit_count();
to the standalone script. 独立脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.