所以我开发最终将运行一个shell通过比较当前的IP(广东话邮寄了几个变量和字符串
//get_ip.php
<?php
$current_ip = file_get_contents('http://www.ipaddresscheck.comlu.com/ip.php');
?>
)
来检测IP地址更改脚本(如果任何人有兴趣,http://www.ipaddresscheck.comlu.com/ip.php将只返回您的机器/路由器的公共IP)
到最新的一个记录在mysql中。现在,我甚至不能通过电子邮件发送虚假的旧IP和真正的当前IP。当我尝试通过电子邮件发送新旧IP时,它只会工作,我将旧的ip变量放在当前位置或根本没有。它应该说
The old IP adresss was --- ".$old_ip."
The new IP address is --- ".$current_ip."
但这是行不通的。唯一可行的就是
The old IP adresss was --- ".$old_ip."
The new IP address is --- ".$old_ip."
或
The old IP adresss was --- ".$old_ip."
The new IP address is ---
<?php
//Get IP
include 'get_ip.php';
//Connect to SQL
mysql_connect('localhost','root','root');
//Select database
mysql_select_db("ip_changes") or die(mysql_error());
//Get Date Info
$date = date("D M Y");
$time = date("H i s");
//Generate SQL query
$sql="INSERT INTO ip (date, time, current_ip)
VALUES ('$date', '$time', '$current_ip')";
//Execute SQL
mysql_query($sql);
//$sqlcurrent = mysql_query(SELECT current_ip FROM ip ORDER BY id DESC LIMIT 1);
echo $current_ip;
$new_ip = $current_ip;
//Send Mail
$old_ip = '192.168.0.1';
$to = "[email protected]";
$subject = "IP Address Change";
$message = "Hello! This is an automated message from the IPMS. An IP address chamge has been
detected.
//Right here, I can only send out $old_ip, and nothing else. The date and time at the bottom does work.
The old IP adresss was --- ".$old_ip."
The new IP address is --- ".$old_ip."
The IP address change was detected at ---". $date. ' , '. $time;
$message1 = 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
$from = "[email protected]://mar-remote-net.dns2.us";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
?>
有什么建议?
你可以检查你的代码获取IP工作正常,即在get_ip.php文件中 –
只是在将邮件发送给邮件之前对邮件进行回显。前面提到的 –