SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble Reading a URL

    Hi. I'm trying to read the contents of a URL (which, interestingly, is in turn reading contents of a URL on the server where the script is located). I get the following error messages:

    Warning: php_hostconnect: connect failed in /home/httpd/vhosts/domain.com/httpdocs/directory/page.php on line 13

    Warning: fopen("http://www.domain.com/?variable=valu...variable=value", "r") - Bad file descriptor in /home/httpd/vhosts/domain.com/httpdocs/directory/page.php on line 13

    Here is the relevant code:

    PHP Code:
    $fullurl=http://www.domain.com/?variable=value&variable=value&url=http://www.otherdomain.com/directory/page.php?variable=value;
    $fp=fopen($fullurl,"r"); 
    Any ideas? Thanks!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Hey Phil,
    I think it's because PHP can't differentiate between the ampersand that joins your varous variables in the first URL and the ampersands that are in the second url.

    Meaning that it looks like one long querystring with many GET variables.

    I ran into this the other day but can't for the life of me figure out what the easiest fix is. Well the easiest fix would be to read the second url into a string and then pass it in the querystring of the first I suppose but can you do that?

    I've used CURL before but without more info I'm not sure it'll help.

    What's the end result?
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  3. #3
    SitePoint Member
    Join Date
    Apr 2004
    Location
    US
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    You forgot to quote it!

    You might want to try:

    PHP Code:
    $fullurl='http://www.domain.com/?variable=value&variable=value&url=http://www.otherdomain.com/directory/page.php?variable=value'
    Hope this helps,

    -Aubrey
    _________________________________________
    If you want to Read Articles, Buy and Sell on the
    Classifieds, Play Games, or anything else, please
    visit my web site at AllThingsInteresting.com !

  4. #4
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, in my actual script I have the quotes. Not sure why they got left off in my post.

  5. #5
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by awasson
    Hey Phil,
    I think it's because PHP can't differentiate between the ampersand that joins your varous variables in the first URL and the ampersands that are in the second url.
    Actually, there aren't any ampersands in the second URL.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm I had to take a second look and ya there are no ampersands. I wonder if the ? is causing the trouble.

    Can you test the script by running it with a url that doesn't take arguments? Just for the test?

    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •