M
M
maiskiykot2018-03-14 14:57:19
PHP
maiskiykot, 2018-03-14 14:57:19

What is the cause of PHP glitches?

The locale is Vertrigoserv latest version. Everything seems to work, but ran into oddities.
1. I define IP. I take it out to check - everything works. Next comes a couple of cycles, the IP variable is not overwritten, does not change, there are no PHP errors. BUT!!! I open the next cycle and the IP variable is gone! Moreover, even the new definition of IP does not help. Silently disappears!
What could it be?
2. There is a regular link in html like page.php?page=5. Those. when it is sent to the browser, the $_GET['page'] variable should appear. However, trying to intercept it before loading the page code does nothing! Only at random it was possible to determine that it only works when the code is placed at the bottom of the page.
What could it be?
3. The code for forced definition of the $_GET['address'] variable does not work. I declare it at the beginning of the code, and at the end it should intercept and include the received address. Silence!
What could it be?
I exclude errors in the code, because I checked everything 100 times. Maybe the PHP settings are weird? What could cause such a poltergeist?
ps missing code.

if (isset($_GET))
{
foreach ($_GET as $key=>$value)
{
$anchor = $key;
break;
}

$IP = $_SERVER["REMOTE_ADDR"];

if (!file_exists("./stats-ip.dat"))
{
$fp = fopen("./stats-ip.dat","a+");
$puts = $IP."::".$anchor."\n";
}
else
{
$file = file("./stats-ip.dat");
$file1 = "./stats-ip.dat";
$file2 = "./admin/stats-bak.dat";
if (@filesize($file1 >= $file2))
copy ($file1,$file2);

if (!in_array($IP,$file))
{
$file[] = $IP."::".$anchor."\n";
$puts = implode("",$file);
}
else
{
$puts = '';

foreach ($file as $value)
{
echo $IP;

if(preg_match("!".$IP."!",$value)) // Вот здесь уже IP пропал!!!
{
echo "Match!";
$puts .= trim($value)." ".$anchor."\n";
}
else
$puts .= $value;
}
}
$fp = fopen("./stats-ip.dat","r+");
}
fputs($fp,$puts);
fclose($fp);
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
imhuman, 2018-03-14
@maiskiykot

The value does not disappear, just that part of the code in which the output is echonot processed by the condition

I
Ildar Saribzhanov, 2018-03-14
@Bluz

See what you have in the array that you get from the file, and what you are looking for.
In the file, you put a line in the format And look for an entry only ip. Actually, the code never goes along the branch where ip "disappears" Well, at least divide your code into functions, not to mention OOP.

P
Pavel Novikov, 2018-03-14
@paulfcdd

I exclude errors in the code, because I checked everything 100 times

But I would not rule out errors in the code, so throw it here and we'll watch. Your question is meaningless without code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question