2013-06-26 90 views
0

所以我开发最终将运行一个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; 
?> 

有什么建议?

+0

你可以检查你的代码获取IP工作正常,即在get_ip.php文件中 –

+0

只是在将邮件发送给邮件之前对邮件进行回显。前面提到的 –

回答

0

毫无疑问,这是不行的,因为你使用的是错误的变量名:

$message = "Hello! ..."; 
//why is it called message1? 
$message1 = 'Old IP:'.$old_ip. 'New IP:'.$current_ip; 

//here you are sending $message 
mail($to,$subject,$message,$headers); 
+0

,我试图让每条消息行变量并将它们加在一起。它看起来像$ message1,$ message2 $ message3 ...但基本上,弓我试图让邮件脚本的IP(获得该页面的源代码),消除了get_ip.php,但我仍然无法获得任何东西工作... –

+0

,没有工作 –

+0

@JustinMarmorato把var_dump($ message); var_dump($ message1); exit;在$ from =“no-reply @ http://mar-remote-net.dns2.us”之前;并让我知道,它打印什么。 – user4035

0

我想通了......

$finalmessage = <<< EOT 
    Hello! This is an automated message from the IPMS. An IP address change has been detected. 
    <html> 
    <style> 
    table, th, td 
    { 
    border: 2px solid black; 
    border-color:grey; 
    } 
     </style> 
    <table class='table'> 
    <tr> 
    <td>Old IP</td><td>New IP</td><td>Time Detected</td> 
    </tr> 
    <tr> 
    <td>$old_ip</td><td>$new_ip</td><td>$date $time</td> 
    </tr> 
    </table> 
    </html> 
EOT;