Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP4 to PHP5 question

    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.)
    PHP Code:
    <?
        
    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

    PHP Code:
    <?
        
    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);    
    ?>

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Why is it you feel you need to change the scripts to be "PHP5 compatible"? Is there an error or some other reason?

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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.

  • #4
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #6
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by thekyle422 View Post
    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.

  • Users who have thanked bdl for this post:

    thekyle422 (02-28-2010)

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Posts
    301
    Thanks
    7
    Thanked 2 Times in 2 Posts
    I believe bdl is exactly correct.

    I think the one you are looking for is: allow_url_fopen
    http://us.php.net/manual/en/filesyst...llow-url-fopen

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

  • Users who have thanked MattyUK for this post:

    thekyle422 (02-28-2010)

  • #8
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #9
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I've been using linode.com, I've had good luck thus far.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •