SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast the dooode's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with port number reading file contents

    I am trying to open a remote file and read the contents using the following code:

    PHP Code:
    $file 'http://www.domainname.com:82/file.xml';
    if (
    $data file_get_contents($file)) {
        echo 
    $data;
    } else {
        echo 
    'could not read file';

    This is working on my local wamp machine but when I try on the server i can't read the file. I have another file that is on port 80 so the url is like this "http://www.domainname.com/anotherfile.xml" and this one works. How do i get round this port issue?

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is the sever listens on port 82?
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Enthusiast the dooode's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean the server with the file i am trying to read on (i have no access to this server)? This file is displaying fine in the browser and when i use file_get_contents on my local machine.

  4. #4
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The URL file-access is disabled in the server configuration.
    in php.ini
    allow_url_fopen = Off
    my mobile portal
    ghiris.ro

  5. #5
    SitePoint Enthusiast the dooode's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope definitely on....

    also this works:

    PHP Code:
    $file 'http://www.domainname.com/anotherfile.xml';
    if (
    $data file_get_contents($file)) {
        echo 
    $data;
    } else {
        echo 
    'could not read file';


  6. #6
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    enable error reporting and try phpinfo()
    see the output
    my mobile portal
    ghiris.ro

  7. #7
    SitePoint Enthusiast the dooode's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just been trying out the cURL method:

    PHP Code:
    $ch curl_init();
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_URL$file);
    $data curl_exec($ch);
    curl_close($ch);
    echo 
    $data
    No luck here either.... Is the problem the port number specified on the url?

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try setting CURLOPT_PORT to 82 and removing the port from the URL.

    If that doesn't work, use sockets directly to make the connection.

  9. #9
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Does the server have a firewall set up which might be blocking that port?
    Salathe
    Software Developer and PHP Manual Author.

  10. #10
    SitePoint Enthusiast the dooode's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having spoken to my hosting company it was my server that was blocking any outgoing connections to non-standard ports. After opening port 82 this now works.

    Thanks for your time guys!


Bookmarks

Posting Permissions

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