List Info

Thread: note 61723 added to reserved.variables




note 61723 added to reserved.variables
user name
2006-02-10 11:02:55
Man, I hate lazy programmers.  Let's have no more excuses
for requiring your viewers to fill in their City and
Country, okay?

PART ONE - The Lookup

$ip = get_remote_ip();
$location = http_get( "http://api.hostip.info/?i
p=$ip" );

$contents = get_tag_contents( $location, "Hostip"
);
$city = trim( get_tag_contents( $contents,
"gml:name" ) );
$country = trim( get_tag_contents( $contents,
"countryAbbrev" ) );

if( stristr( $city, "private" ) ) {
  $city = "";
}

if( stristr( $country, "xx" ) ) {
  $country = "US";
}

PART TWO - The Functions

function get_remote_ip() {
  return $_SERVER['REMOTE_ADDR'];
}

function http_get( $url ) {
  $request = fopen( $url, "rb" );
  $result = "";

  while( !feof( $request ) ) {
    $result .= fread( $request, 8192 );
  }
  
  fclose( $request );
  
  return $result;
}

function get_tag_contents( $xml, $tag ) {
  $result = "";
  $s_tag = "<$tag>";
  $s_offs = strpos( $xml, $s_tag );

  // If we found a starting offset, then look for the
end-tag.
  //
  if( $s_offs ) {
    $e_tag = "</$tag>";
    $e_offs = strpos( $xml, $e_tag, $s_offs );

    // If we have both tags, then dig out the contents.
    //
    if( $e_offs ) {
      $result = substr(
        $xml,
        $s_offs + strlen( $s_tag ),
        $e_offs - $s_offs - strlen( $e_tag ) + 1 );
    }
  }

  return $result;
}

PART THREE - The HTML Form

<input type="text" name="city"
id="city" value="<? echo $city;
?>" size="40" maxlength="50"
/>

<option value="AU" <? if( $country ==
"AU" ) echo "SELECTED='true'"
?>>Australia</option>
<option value="CA" <? if( $country ==
"CA" ) echo "SELECTED='true'"
?>>Canada</option>
<option value="GB" <? if( $country ==
"GB" ) echo "SELECTED='true'"
?>>United Kingdom</option>
<option value="US" <? if( $country ==
"US" ) echo "SELECTED='true'"
?>>United States</option>

etc.
----
Server IP: 66.207.199.35
Probable Submitter: 209.121.101.232
----
Manual Page -- h
ttp://www.php.net/manual/en/reserved.variables.php
Edit        -- http://master.php.net/manage/user-notes.php?action=
edit+61723
Delete: added to the manual -- htt
p://master.php.net/manage/user-notes.php?action=delete+61723
&report=yes&reason=added+to+the+manual
Delete: bad code            -- http://master.
php.net/manage/user-notes.php?action=delete+61723&report
=yes&reason=bad+code
Delete: spam                -- http://master.php.
net/manage/user-notes.php?action=delete+61723&report=yes
&reason=spam
Delete: useless             -- http://master.p
hp.net/manage/user-notes.php?action=delete+61723&report=
yes&reason=useless
Delete: non-english         -- http://mast
er.php.net/manage/user-notes.php?action=delete+61723&rep
ort=yes&reason=non-english
Delete: already in docs     -- http://
master.php.net/manage/user-notes.php?action=delete+61723&
;report=yes&reason=already+in+docs
Delete: other reasons       -- http://master.php.net/manage/user-
notes.php?action=delete+61723&report=yes
Reject      -- http://master.php.net/manage/user-
notes.php?action=reject+61723&report=yes
Search      -- http://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

note 61723 modified in reserved.variables by nforbes
user name
2006-06-24 18:10:17
[Editor's note: As much as you may hate us lazy
programmers, we highly recommend the use of DOM (http://php.net/dom) or
SimpleXML (http://php.net/simplexml
) for handling XML data. It's much, much, much, much safer
than your method. ]

Man, I hate lazy programmers.  Let's have no more excuses
for requiring your viewers to fill in their City and
Country, okay?

PART ONE - The Lookup

$ip = get_remote_ip();
$location = http_get( "http://api.hostip.info/?i
p=$ip" );

$contents = get_tag_contents( $location,
"Hostip" );
$city = trim( get_tag_contents( $contents,
"gml:name" ) );
$country = trim( get_tag_contents( $contents,
"countryAbbrev" ) );

if( stristr( $city, "private" ) ) {
  $city = "";
}

if( stristr( $country, "xx" ) ) {
  $country = "US";
}

PART TWO - The Functions

function get_remote_ip() {
  return $_SERVER['REMOTE_ADDR'];
}

function http_get( $url ) {
  $request = fopen( $url, "rb" );
  $result = "";

  while( !feof( $request ) ) {
    $result .= fread( $request, 8192 );
  }
  
  fclose( $request );
  
  return $result;
}

function get_tag_contents( $xml, $tag ) {
  $result = "";
  $s_tag = "<$tag>";
  $s_offs = strpos( $xml, $s_tag );

  // If we found a starting offset, then look for the
end-tag.
  //
  if( $s_offs ) {
    $e_tag = "</$tag>";
    $e_offs = strpos( $xml, $e_tag, $s_offs );

    // If we have both tags, then dig out the contents.
    //
    if( $e_offs ) {
      $result = substr(
        $xml,
        $s_offs + strlen( $s_tag ),
        $e_offs - $s_offs - strlen( $e_tag ) + 1 );
    }
  }

  return $result;
}

PART THREE - The HTML Form

<input type="text" name="city"
id="city" value="<? echo $city;
?>" size="40"
maxlength="50" />

<option value="AU" <? if( $country ==
"AU" ) echo "SELECTED='true'"
?>>Australia</option>
<option value="CA" <? if( $country ==
"CA" ) echo "SELECTED='true'"
?>>Canada</option>
<option value="GB" <? if( $country ==
"GB" ) echo "SELECTED='true'"
?>>United Kingdom</option>
<option value="US" <? if( $country ==
"US" ) echo "SELECTED='true'"
?>>United States</option>

etc.

--was--
Man, I hate lazy programmers.  Let's have no more excuses
for requiring your viewers to fill in their City and
Country, okay?

PART ONE - The Lookup

$ip = get_remote_ip();
$location = http_get( "http://api.hostip.info/?i
p=$ip" );

$contents = get_tag_contents( $location,
"Hostip" );
$city = trim( get_tag_contents( $contents,
"gml:name" ) );
$country = trim( get_tag_contents( $contents,
"countryAbbrev" ) );

if( stristr( $city, "private" ) ) {
  $city = "";
}

if( stristr( $country, "xx" ) ) {
  $country = "US";
}

PART TWO - The Functions

function get_remote_ip() {
  return $_SERVER['REMOTE_ADDR'];
}

function http_get( $url ) {
  $request = fopen( $url, "rb" );
  $result = "";

  while( !feof( $request ) ) {
    $result .= fread( $request, 8192 );
  }
  
  fclose( $request );
  
  return $result;
}

function get_tag_contents( $xml, $tag ) {
  $result = "";
  $s_tag = "<$tag>";
  $s_offs = strpos( $xml, $s_tag );

  // If we found a starting offset, then look for the
end-tag.
  //
  if( $s_offs ) {
    $e_tag = "</$tag>";
    $e_offs = strpos( $xml, $e_tag, $s_offs );

    // If we have both tags, then dig out the contents.
    //
    if( $e_offs ) {
      $result = substr(
        $xml,
        $s_offs + strlen( $s_tag ),
        $e_offs - $s_offs - strlen( $e_tag ) + 1 );
    }
  }

  return $result;
}

PART THREE - The HTML Form

<input type="text" name="city"
id="city" value="<? echo $city;
?>" size="40"
maxlength="50" />

<option value="AU" <? if( $country ==
"AU" ) echo "SELECTED='true'"
?>>Australia</option>
<option value="CA" <? if( $country ==
"CA" ) echo "SELECTED='true'"
?>>Canada</option>
<option value="GB" <? if( $country ==
"GB" ) echo "SELECTED='true'"
?>>United Kingdom</option>
<option value="US" <? if( $country ==
"US" ) echo "SELECTED='true'"
?>>United States</option>

etc.

http:
//php.net/manual/en/reserved.variables.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

note 61723 deleted from reserved.variables by philip
user name
2007-02-21 10:00:38
Note Submitter: nospam at joot dot com 

----

[Editor's note: As much as you may hate us lazy programmers,
we highly recommend the use of DOM (http://php.net/dom) or
SimpleXML (http://php.net/simplexml
) for handling XML data. It's much, much, much, much safer
than your method. ]

Man, I hate lazy programmers.  Let's have no more excuses
for requiring your viewers to fill in their City and
Country, okay?

PART ONE - The Lookup

$ip = get_remote_ip();
$location = http_get( "http://api.hostip.info/?i
p=$ip" );

$contents = get_tag_contents( $location, "Hostip"
);
$city = trim( get_tag_contents( $contents,
"gml:name" ) );
$country = trim( get_tag_contents( $contents,
"countryAbbrev" ) );

if( stristr( $city, "private" ) ) {
  $city = "";
}

if( stristr( $country, "xx" ) ) {
  $country = "US";
}

PART TWO - The Functions

function get_remote_ip() {
  return $_SERVER['REMOTE_ADDR'];
}

function http_get( $url ) {
  $request = fopen( $url, "rb" );
  $result = "";

  while( !feof( $request ) ) {
    $result .= fread( $request, 8192 );
  }
  
  fclose( $request );
  
  return $result;
}

function get_tag_contents( $xml, $tag ) {
  $result = "";
  $s_tag = "<$tag>";
  $s_offs = strpos( $xml, $s_tag );

  // If we found a starting offset, then look for the
end-tag.
  //
  if( $s_offs ) {
    $e_tag = "</$tag>";
    $e_offs = strpos( $xml, $e_tag, $s_offs );

    // If we have both tags, then dig out the contents.
    //
    if( $e_offs ) {
      $result = substr(
        $xml,
        $s_offs + strlen( $s_tag ),
        $e_offs - $s_offs - strlen( $e_tag ) + 1 );
    }
  }

  return $result;
}

PART THREE - The HTML Form

<input type="text" name="city"
id="city" value="<? echo $city;
?>" size="40" maxlength="50"
/>

<option value="AU" <? if( $country ==
"AU" ) echo "SELECTED='true'"
?>>Australia</option>
<option value="CA" <? if( $country ==
"CA" ) echo "SELECTED='true'"
?>>Canada</option>
<option value="GB" <? if( $country ==
"GB" ) echo "SELECTED='true'"
?>>United Kingdom</option>
<option value="US" <? if( $country ==
"US" ) echo "SELECTED='true'"
?>>United States</option>

etc.

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )