...

View Full Version : PHP4 to PHP5 question



kyle422
02-27-2010, 06:59 PM
I'm not a very experience coder. I know very little about php except simple commands. I need to change these two scripts from PHP4 to PHP5. Please help. Thanks. (The functions.php script doesn't have any issues.)

<?
include "functions.php";
echo "max_execution_time set to 500 seconds, was set to: " . ini_set("max_execution_time", "500") . "<br>";

$_con = getConnected();

$result = MySQL_Query("
SELECT o.mlsNo, b.mlsNo, b.latitude, b.longitude
FROM b_fla_data_backup b
LEFT JOIN b_fla_data o ON b.mlsNo = o.mlsNo
WHERE o.mlsNo IS NOT NULL
");
while ( $row = MySQL_Fetch_Assoc($result) ){
if ( $row['latitude'] != '-1' AND $row['longitude'] != '-1' ){
$query = "UPDATE b_fla_data SET latitude = '" . $row['latitude'] . "', longitude = '" . $row['longitude'] . "' WHERE mlsNo = '" . $row['mlsNo'] . "' LIMIT 1";
$uResult = MySQL_Query($query);
if ( !$uResult ){
echo $query . '<br>' . MYSQL_Error() . '<br><br>';
}
}
}

MySQL_Close($_con);

?>


Second Script


<?
include "functions.php";
echo "max_execution_time set to 1000 seconds, was set to: " . ini_set("max_execution_time", "1000") . "<br>";

define("GMAPS_KEY", "ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ");
// code for google maps
define("GMAPS_URL", "http://maps.google.com/maps/geo?");
// url of responder
define("GMAPS_OUTPUT", "csv");
// select type of output

$_con = getConnected();

$result = MySQL_Query("SELECT uid, streetNo, streetDir, streetName, streetSuffix, city, state FROM b_fla_data WHERE longitude = '0' AND latitude = '0' LIMIT 1000");

$delay = 0;
while ( $row = MySQL_Fetch_Assoc($result) ){
$address = '';
if ( !empty ( $row['streetNo'] ) ){
$address .= $row['streetNo'];
}
if ( !empty( $row['streetDir'] ) ){
// $address .= ' ' . $row['streetDir'];
}
if ( !empty( $row['streetName'] ) ){
$address .= ' ' . $row['streetName'];
}
if ( !empty( $row['streetSuffix'] ) ){
if ( $row['streetSuffix'] == 'LA' ){
$row['streetSuffix'] = 'Ln';
}
if ( $row['streetSuffix'] == 'AV' ){
$row['streetSuffix'] = 'AVE';
}
$address .= ' ' . $row['streetSuffix'];
}
if ( !empty( $row['city'] ) ){
if ( $row['city'] == "MERRITT ISL" ){
$row['city'] = eregi_replace("MERRITT ISL", "MERRITT ISLAND", $row['city']);
}
if ( $row['city'] == "BAREFOOT BAY" ){
$row['city'] = eregi_replace("BAREFOOT BAY", "SEBASTIAN", $row['city']);
}
if ( $row['city'] == "W MELBOURNE" ){
$row['city'] = eregi_replace("W MELBOURNE", "MELBOURNE", $row['city']);
}
if ( $row['city'] == "INDIAN HARB BCH" ){
$row['city'] = eregi_replace("INDIAN HARB BCH", "INDIAN HARBOUR BEACH", $row['city']);
}

$row['city'] = eregi_replace("PT ST JOHN", "PORT ST JOHN", $row['city']);
$address .= ', ' . $row['city'];
}
if ( !empty( $row['state'] ) ){
$address .= ', ' . $row['state'];
}


$done = false;
while ( !$done ){
$response = file_get_contents(GMAPS_URL . "q=" . urlencode($address) . "&output=" . GMAPS_OUTPUT . "&key=" . GMAPS_KEY . "&sensor=false" );
usleep(300000);
$response = explode(",", $response);
if ( $response[0] == "200" ){
$update_result = MySQL_Query("UPDATE b_fla_data SET latitude = '" . $response[2] . "', longitude = '" . $response[3] . "' WHERE uid = '" . $row['uid'] . "'");
$done = true;
} else if ( $response[0] == "620" ){
$delay = $delay + 100000;
} else {
echo 'problem s geocodovanim adresy: <strong>' . $address . '</strong>, kod: <strong>' . $response[0] . '</strong><br>';
$done = true;
$update_result = MySQL_Query("UPDATE b_fla_data SET latitude = '-1', longitude = '-1' WHERE uid = '" . $row['uid'] . "'");
}
usleep($delay);
}

}

MySQL_Close($_con);
?>

bdl
02-27-2010, 08:16 PM
Why is it you feel you need to change the scripts to be "PHP5 compatible"? Is there an error or some other reason?

thekyle422
02-28-2010, 12:45 AM
It is a script to Geocode addresses and I get an error (only on the second script, I forgot the first one is PHP 5 compatible.)
Here is the error I get when I try to run the script when the .htaccess is set to PHP 5:

max_execution_time set to 1000 seconds, was set to: 50000
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents(http://maps.google.com/maps/geo?q=%2C+COCOA%2C+FL&output=csv&key=ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ&sensor=false) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found
problem s geocodovanim adresy: , COCOA, FL, kod:
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents(http://maps.google.com/maps/geo?q=%2C+ROCKLEDGE%2C+FL&output=csv&key=ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ&sensor=false) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found
problem s geocodovanim adresy: , ROCKLEDGE, FL, kod:
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents(http://maps.google.com/maps/geo?q=2195+HIGHWAY+A1A%2C+SATELLITE+BEACH%2C+FL&output=csv&key=ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ&sensor=false) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found
problem s geocodovanim adresy: 2195 HIGHWAY A1A, SATELLITE BEACH, FL, kod:
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents(http://maps.google.com/maps/geo?q=465+RIVER+MOORINGS+DR%2C+MERRITT+ISLAND%2C+FL&output=csv&key=ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ&sensor=false) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found
problem s geocodovanim adresy: 465 RIVER MOORINGS DR, MERRITT ISLAND, FL, kod:
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents(http://maps.google.com/maps/geo?q=25+FLORIDELPHIA+AVE%2C+ROCKLEDGE%2C+FL&output=csv&key=ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ&sensor=false) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found
problem s geocodovanim adresy: 25 FLORIDELPHIA AVE, ROCKLEDGE, FL, kod:
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration
/homepages/37/d110455442/htdocs/mls-new/import_geocoder.php :: 61 :: file_get_contents(http://maps.google.com/maps/geo?q=8707+BAY+CT%2C+CAPE+CANAVERAL%2C+FL&output=csv&key=ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ&sensor=false) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found

P.S. I am the same person who posted the thread, but I had to create a different formum account name. The password reset email on the forum wasn't getting through the email server. Sorry for any confusion.

bdl
02-28-2010, 01:44 AM
From the errors you've posted:


[function.file-get-contents]: URL file-access is disabled in the server configuration


Do you have access to the server configuration? Or is this (as I suspect) on a shared web host?

This isn't so much a "PHP4 to PHP5" issue as a "old server config was changed when they updated" issue. They may have also purposefully changed the config for security reasons.

thekyle422
02-28-2010, 06:44 AM
Shared server. Would switching to a VPS (virtual private server) make any difference? Any work around solution besides switching servers?

The weird thing is, the script works fine unless I change the .htaccess to PHP 5. So if it is a security issue, why does the script continue to work in PHP 4?

bdl
02-28-2010, 07:51 AM
Shared server. Would switching to a VPS (virtual private server) make any difference? Any work around solution besides switching servers?


Well, using a VPS will allow you to use your own php.ini config file, which seems to be the issue here. OTOH, you're responsible for your server config and security.



The weird thing is, the script works fine unless I change the .htaccess to PHP 5. So if it is a security issue, why does the script continue to work in PHP 4?
Most hosts now offer both PHP4 and PHP5 on the same server. They typically run PHP4 by default, and if you alter the .htaccess file you can switch all your scripts to PHP5. You can tell this quite easily by using a script that displays the output of phpinfo(). One of the hosts I deal with does this, and they allow you to have your own php.ini config file; you simply choose which version of PHP you want to use and you link to the php.ini config file. So to answer your question in a round-about way, if the php.ini config for PHP4 allows file_get_contents() to access a URL / remote file, then you have no problem. As soon as you switch the .htaccess to use PHP5, it's likely reading a different config file, that has file_get_contents disabled by default.

So, long story made longer; ask your host. They may have simply overlooked this option, and may change it for you. Or they may give you the ability to link to your own php.ini file.

MattyUK
02-28-2010, 02:28 PM
I believe bdl is exactly correct.

I think the one you are looking for is: allow_url_fopen
http://us.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Note: This setting can only be set in php.ini due to security reasons.

thekyle422
02-28-2010, 05:41 PM
Thanks for the helpfull information.
I'll see if they can alter the php.ini file for me. I doubt they will though. I've been considering changing to a shared server but this has been the only issue I've had as a result of being on a shared server.
Any good suggestions on VPS servers? I want to stay under $40 a month. I found these two companies that seem to fit my needs: hostv.com and spry.com. Any input would be greatly appreciated. Thanks again.

bdl
03-01-2010, 12:14 AM
I've been using linode.com, I've had good luck thus far.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum