Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get ip location

Posted on 2006-11-26
5
Medium Priority
?
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 count occurrences of each item in an array.

610 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