如何在php格式的IP地址之前添加链接地址

时间:2015-02-26 05:54:00

标签: php forms

我正在尝试使用链接发布用户IP地址以跟踪IP位置,我有以下PHP代码。我想在此http://whatismyipaddress.com/ip/108.44.33.225

的超链接链接中包含用户IP
<?php 
if(isset($_POST['submit'])){
    $to = "email@example.com";
    $from = $_POST['email'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $ip=$_SERVER['REMOTE_ADDR'];
    $subject = "Email IP submission as link";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message .= "IP Address:" <a href="http://whatismyipaddress.com/ip/. $ip .">. $ip</a>";

    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you ";
    }
?>

2 个答案:

答案 0 :(得分:1)

您的代码存在串联问题,请尝试使用

$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/".$ip."'>$ip</a>";

而不是

$message .= "IP Address:" <a href="http://whatismyipaddress.com/ip/. $ip .">. $ip</a>";

答案 1 :(得分:1)

请更正此行:

$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/". $ip ."'>". $ip."</a>";

或者你可以尝试

$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/$ip'>$ip</a>";