SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to post ip address AND city

    How would I be able to get not only the ip address of user but also the city to post in form-mail script?

    brief part where I thought it would work
    Code:
    // Mail contents config
    $return_ip[0]="yes";
         $return_ip[0]= $_SERVER['REMOTE_ADDR'];
        $details = json_decode(file_get_contents("http://ipinfo.io/{$return_ip}/json"));
        $details[0]="";
    Code:
    // build verticle table format
    	function buildVertTable($fields, $intro, $to, $send_ip)
    	{
    		$message=htmlHeader();
    		if($intro != "")
    			$message.="<tr>\n<td align=\"left\" valign=\"top\" colspan=\"2\">".$intro."</td>\n</tr>\n";
    		$fields_check=preg_split('/,/',$fields);
    		$run=sizeof($fields_check);
    		for($i=0;$i<$run;$i++)
    		{
    			$cur_key=$fields_check[$i];
    			$cur_value=$_POST[$cur_key];
    			if(is_array($cur_value))
    			{
    				$cur_value=parseArray($cur_key);
    			}
    			$cur_value=parseValue($cur_value);
    			if($allow_html[$config]=="no")
    				$cur_value=htmlspecialchars(nl2br($cur_value));
    			else
    				$cur_value=nl2br($cur_value);
    			$message.="<tr>\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>".$cur_key."</b></td>\n<td align=\"left\" valign=\"top\" width=\"100%\">".$cur_value."</td>\n</tr>\n";
    		}
    		if($send_ip=="yes" && $to=="recipient")
    		{
    			$user_ip=getIP();
    			$message.="<tr>\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>Sender IP</b></td>\n<td align=\"left\" valign=\"top\" width=\"100%\">".$user_ip."</td>\n</tr>\n";
    		}
    		$message.=htmlFooter();
    		return $message;
    	}
    I am new at php so dummy it down, please

    Thanks

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,832
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by lukkas View Post
    How would I be able to get not only the ip address of user but also the city to post in form-mail script?
    You are assuming the city to be returned is accurate when odds are it will not be. The IP lookup may return the city the person is in, the metropolitan area their traffic is routed through which can be many miles away, or another region entirely. That site is returning the metro area for me, which is 20 miles away from where I am.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •