Problem with simple script
Posted by: intergrated (---.dyn.iinet.net.au)
Date: March 01, 2014 02:31PM

Hi all smiling smiley

I have this very simple script which runs well on my other Linux server but just won't execute on my Windows 8 WAMP.

<?php

$geoplugin = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']) );

if ( is_numeric($geoplugin['geoplugin_latitude']) && is_numeric($geoplugin['geoplugin_longitude']) ) {

$lat = $geoplugin['geoplugin_latitude'];
$long = $geoplugin['geoplugin_longitude'];
//set farenheight for US
if ($geoplugin['geoplugin_countryCode'] == 'US') {
$tempScale = 'fahrenheit';
$tempUnit = '&deg;F';
} else {
$tempScale = 'celsius';
$tempUnit = '&deg;C';
}
require_once('ParseXml.class.php');

$xml = new ParseXml();
$xml->LoadRemote("[api.wunderground.com]{$lat},{$long}", 3);
$dataArray = $xml->ToArray();

$html = "<center><h2>Weather forecast for " . $geoplugin['geoplugin_city'];
$html .= "</h2><table cellpadding=5 cellspacing=10><tr>";

foreach ($dataArray['simpleforecast']['forecastday'] as $arr) {

$html .= "<td align='center'>" . $arr['date']['weekday'] . "<br />";
$html .= "<img src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />";
$html .= "<font color='red'>" . $arr['high'][$tempScale] . $tempUnit . " </font>";
$html .= "<font color='blue'>" . $arr['low'][$tempScale] . $tempUnit . "</font>";
$html .= "</td>";


}
$html .= "</tr></table>";

echo $html;
}

?>

Any help would be appreciated.

Thank you smiling smiley

Options: ReplyQuote
Re: Problem with simple script
Posted by: RiggsFolly (---.as13285.net)
Date: March 01, 2014 06:25PM

What is the error?

Try looking on the PHP error log!

Of course the obvious first thing to check is that you have 'allow url foprn' set on this server.

left click wampmanager -> PHP settings -> allow url fopen

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: Problem with simple script
Posted by: intergrated (---.dyn.iinet.net.au)
Date: March 01, 2014 10:46PM

Thanks for your reply smiling smiley

Allow url fopen is set.
There is no errors in error log but this is the error displayed when I run it from localhost:

( ! ) Notice: Undefined index: geoplugin_latitude in C:\wamp\www\weather.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 145328 {main}( ) ..\weather.php:0

As I mentioned it works well on Linux box and on hosted services.

Options: ReplyQuote
Re: Problem with simple script
Posted by: RiggsFolly (---.as13285.net)
Date: March 02, 2014 01:15AM

Oh ok, so its just bad code and you need to ignore all the problems

Try changing the php.ini ( use wampmanager menus to edit this so you get the right on)


Change

display_errors = On

to

display_errors = Off


It might be a good idea to compare all the php config from the live site and you test site just in case there are any other differences.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 1 time(s). Last edit at 03/02/2014 01:16AM by RiggsFolly.

Options: ReplyQuote
Re: Problem with simple script
Posted by: intergrated (---.dyn.iinet.net.au)
Date: March 02, 2014 01:33AM

Unfortunately it's not that simple, the code works fine elsewhere, WAMP just doesn't executes it.

Try it in your installation.

I have turned errors off so now all I get when I run the script is a blank page.

Note, this is a brand new install of WAMP, I previously used Abyss without any issues but I like WAMP smiling smiley

Options: ReplyQuote
Re: Problem with simple script
Posted by: Otomatic (Moderator)
Date: March 02, 2014 11:10AM

Hi,

With a local server like Wampserver, the result of $SERVER['REMOTE_ADDR'] is :

- ""::1" (Without quote) with IPv6 support
or
- 127.0.0.1

So, with this IP, www.geoplugin.net is totaly unable to give a valid and correct result.

The script is poorly written because it does not test if the result is valid or if the return is "false" and the only tests are: is it digital, on which index can not exist because unserialize connot make these index !

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Problem with simple script
Posted by: intergrated (---.dyn.iinet.net.au)
Date: March 02, 2014 11:17AM

So how do I resolve this?

Merci smiling smiley

Options: ReplyQuote
Re: Problem with simple script
Posted by: Otomatic (Moderator)
Date: March 02, 2014 11:24AM

Hi,

- 1 - You use scripts that are not written with the feet winking smiley
- 2 - You send the public IP, not the local one.

Note: The role of this forum is to help you to run WampServer, not to correct PHP scripts of the whole earth.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Problem with simple script
Posted by: intergrated (---.dyn.iinet.net.au)
Date: March 02, 2014 11:28AM

You'd think WAMP would be able to handle calls to $SERVER['REMOTE_ADDR'] just like linux and other windows servers do, it's a regular PHP function afterall.

Thank you for your help anyway, much appreciated but I think I'll go back to Abyss smiling smiley

Options: ReplyQuote
Re: Problem with simple script
Posted by: Otomatic (Moderator)
Date: March 02, 2014 12:14PM

Hi,

$SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR' is the IP address from which the user is viewing the current page.
If the current page is viewing from "localhost" the IP adress of localhost is ::1 or 127.0.0.1, no offense to other servers on Linux or Windows !

Nevertheless, even with Abyss, your script is very poorly written. This is not because "it works" somewhere, it is necessarily well written.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote


Sorry, only registered users may post in this forum.