Any solution to this error in php?

Discussion in 'PHP' started by hope2life, Aug 25, 2011.

  1. #1
    Hi,

    this below php coding is not working and the browser gives error


    <?php

    function locateIp($ip){
    $ip = $_SERVER['REMOTE_ADDR'];
    $xmldata = 'www.api.ipinfodb.com/v3/ip-country/?key=0ce7f3d044df78597ce89d651afbce43cc852c5b4be15b28cf37549cb8fd832f&ip=$ip';
    $open = fopen($xmldata, 'r');
    $content = stream_get_contents($open);





    $data = explode(";",$content);

    return $data;
    }

    $ip_data = locateIp($ip);

    if($ip_data[3] == "IN"){
    header('Location: http://www.webhostingleader.com/client/cart.php?currency=5');}

    else{
    header('Location: http://www.webhostingleader.com/client/cart.php?currency=1');}

    ?>

    browser gives following error

    Warning: fopen(www.api.ipinfodb.com/v3/ip-country/?key=0ce7f3d044df78597ce89d651afbce43cc852c5b4be15b28cf37549cb8fd832f&ip=$ip) [function.fopen]: failed to open stream: No such file or directory in /home/web1host/public_html/currency.php on line 6

    Warning: stream_get_contents() expects parameter 1 to be resource, boolean given in /home/web1host/public_html/currency.php on line 7

    Warning: Cannot modify header information - headers already sent by (output started at /home/web1host/public_html/currency.php:6) in /home/web1host/public_html/currency.php on line 24





    Any help to correct this error will be greatly appreciated.
     
    hope2life, Aug 25, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    When your posting codes here on DP choose the advanced mode and select the php tags, anyway heres your solution

    
    $xmldata = 'http://www
    
    PHP:
    You neglected to include http://
     
    MyVodaFone, Aug 25, 2011 IP
  3. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Hi,
    I included http://

    still it gives below error






    Warning: fopen() [function.fopen]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/web1host/public_html/currency.php on line 6

    Warning: fopen(http://www.api.ipinfodb.com/v3/ip-country/?key=0ce7f3d044df78597ce89d651afbce43cc852c5b4be15b28cf37549cb8fd832f&ip=$ip) [function.fopen]: failed to open stream: no suitable wrapper could be found in /home/web1host/public_html/currency.php on line 6

    Warning: stream_get_contents() expects parameter 1 to be resource, boolean given in /home/web1host/public_html/currency.php on line 7

    Warning: Cannot modify header information - headers already sent by (output started at /home/web1host/public_html/currency.php:6) in /home/web1host/public_html/currency.php on line 24
     
    hope2life, Aug 25, 2011 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    This new error "allow_url_fopen=0" is a problem with your host, if you have access to php.ini you can just add the line
    allow_url_fopen = 1
    Code (markup):
    or
    allow_url_fopen = On
    Code (markup):
     
    MyVodaFone, Aug 25, 2011 IP
  5. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #5
    The answer is stated, you have no permission (or php) to include external data. So email your hosting company or alter php.ini
     
    EricBruggema, Aug 25, 2011 IP
  6. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #6
    where can I find php.ini?
     
    hope2life, Aug 25, 2011 IP
  7. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #7
    do you host your own site or is it hosted by a company?

    if 1, search your computer lol
    if 2, contact your hosting company! :)
     
    EricBruggema, Aug 25, 2011 IP
  8. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #8
    I contacted the hosting company
     
    hope2life, Aug 25, 2011 IP
  9. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Thanks for your help guys. You people are kind.
     
    hope2life, Aug 25, 2011 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    Is your host web1host.net ? according there FAQ you can create your own php.ini file to override previously set values

    So you simple create a php.ini file and enter the content as above

    allow_url_fopen = 1

    or

    allow_url_fopen = On

    ////Before I confuse you its possible that you might need to rename the php.ini to php4.ini or php5.ini , best to see what your host advises first.
     
    MyVodaFone, Aug 25, 2011 IP
  11. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #11
    No my host is not web1host
     
    hope2life, Aug 25, 2011 IP