Solved

Get ip location

Posted on 2006-11-26
5
431 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Syntax Error 4 32
PHP Curl to output a url 7 47
jQuery force form POST 7 45
PHP: Best way to scan folders and process files 10 39
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
The viewer will learn how to count occurrences of each item in an array.
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…

840 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