?
Solved

Get ip location

Posted on 2006-11-26
5
Medium Priority
?
435 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 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