Link to home
Start Free TrialLog in
Avatar of GeniousRus
GeniousRusFlag for Oman

asked on

Get ip location

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...
Avatar of ch2
ch2

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);
?>
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);
?>
Avatar of GeniousRus

ASKER


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"
var sGeobytesCountry="Malaysia"
var sGeobytesCity="Petaling Jaya"
var something = sGeobytesCountry + " " + sGeobytesCity

That should work.
ASKER CERTIFIED SOLUTION
Avatar of ch2
ch2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial