所以我正在开发一个脚本,它最终将作为 shell 运行,通过比较当前的 ip 来检测 ip 地址的变化(
//get_ip.php
<?php
$current_ip = file_get_contents('http://www.ipaddresscheck.comlu.com/ip.php');
?>
)
(如果有人感兴趣,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 = "justinmarmorato@gmail.com";
$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 = "no-reply@http://mar-remote-net.dns2.us";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
?>
有什么建议么?