Solved

Get ip location

Posted on 2006-11-26
5
426 Views
Last Modified: 2012-08-14
i got java script which can fetch the ip location

<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity"></script><script language="Javascript">document.write(" "+sGeobytesCity+", "+sGeobytesCountry);</script>';

so i want to pass those variables into an email ,, wt i did is :

 <?php
 function get_loc()
        {
          $get = '<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity"></script><script language="Javascript">document.write(" "+sGeobytesCity+", "+sGeobytesCountry);</script>';


         return $get;
        }

            $message = "user info:". get_loc();

                 // Send E-mail
                 mail('email', 'subject', $message);
  ?>

so when someone opens that page it will send an email but it didnt work, the mail shows this

user info:<script language="Javascript"
src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity"></script><script
language="Javascript">document.write(" "+sGeobytesCity+",
"+sGeobytesCountry);</script>
==========
any help would be much appreciated...
0
Comment
Question by:GeniousRus
  • 3
5 Comments
 
LVL 11

Expert Comment

by:ch2
ID: 18015818
You cannot execute a javascript inside a php script, no sense

Try this in PHP

<?php

function get_loc()
{
      if (($handle = 'http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity'))
      {
            return $handle;
      }
      else
      {
            return false;
      }
}

$message = "user info:". get_loc();

mail('email', 'subject', $message);
?>
0
 
LVL 11

Expert Comment

by:ch2
ID: 18015868
Now i realized that i forget a couple of things. Try this code.

<?php

function get_loc()
{
      if (($handle = file('http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity')))
      {
            return $handle;
      }
      else
      {
            return 'Could not get geobytes location';
      }
}

$ar = get_loc();

$array = explode(';', $ar[0]);

$message = "user info:". chr(32) . $array[1] . chr(32) . $array[2];

mail('email', 'subject', $message);
?>
0
 

Author Comment

by:GeniousRus
ID: 18015946

i guess it works now ..but not in proper way..

user info: var sGeobytesCountry="Malaysia" var sGeobytesCity="Petaling Jaya"

so how do i just show "Malaysia Petaling Jaya"
0
 
LVL 1

Expert Comment

by:spdaniel91
ID: 18015959
var sGeobytesCountry="Malaysia"
var sGeobytesCity="Petaling Jaya"
var something = sGeobytesCountry + " " + sGeobytesCity

That should work.
0
 
LVL 11

Accepted Solution

by:
ch2 earned 250 total points
ID: 18016262
Try this one. is in the proper way now?

<?php

function get_loc()
{
      if (($handle = file('http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity')))
      {
            return $handle;
      }
      else
      {
            return 'Could not get geobytes location';
      }
}

$ar = get_loc();

$message = '';
$matches = array();

preg_match_all('/"([^"]*?)"/', $ar[0], $matches);
for($intm = 1; $intm < count($matches[1]); $intm++) {
    $message .= $matches[1][$intm] . chr(32);
}

$message = "user info: \"$message\"";

mail('email', 'subject', $message);
?>
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now