Jump to content

Why does this connection time out?


HaLo2FrEeEk

Recommended Posts

I'm writing a quick little script to grab some information from Stickam.com, specifically using the "API" they have set up to get a user id from a provided username, and a username from a provided userid.  These are both publically accessible pieces of information, so I'm not getting into anything I shouldn't, I'm just using the publically accessible API instead of scraping the HTML.

 

For some reason I can't explain though, I can't seem to get the contents of the page using PHP.  Here's my code:

 

$username = @$_GET['username'];
if(!$username) {
  die("no username");
  }

$url = "http://www.stickam.com/servlet/ajax/getLiveUser?uname=".$username;
$html = file_get_contents($url, false, $context);

echo "<pre>";
echo $html;
echo "</pre>";

 

But everytime I load this page on my server, I get this response:

 

Warning: file_get_contents(http://www.stickam.com/servlet/ajax/getLiveUser?uname=[username]) [function.file-get-contents]: failed to open stream: Connection timed out in [file] on line 7

 

I can load it just fine on my Apache server running on my personal computer, and in my browser (both IE9 and Firefox), but not on my website.  I've tried mimicking the headers that my browser sends and creating a stream context to send with the file_get_contents() call, but so far nothing seems to work.

 

Any ideas?

Link to comment
Share on other sites

does it make any difference if you do this

 

$url = "http://www.stickam.com/servlet/ajax/getLiveUser?uname=$username";
$html = file_get_contents('$url', false, $context);

 

 

Why on earth would that work? Variables are not interpolated within single quotes, nor do they need to be within quotes at all.

 

Op: Have you tried the url in a browser? It's not working for me.

Link to comment
Share on other sites

The URL does work in a browser, you just have to provide a username for an online user.  If the user is not currently online, the return will simply be:

 

[

]

 

if the usr doesn't exist, or no name is provided, then you'll get an error page with an "HTTP Status 409" message.  Try going here:

 

http://www.stickam.com/servlet/ajax/sessionMembers?sessionType=live

 

And getting a username from the list, it'll be the first value in each of the arrays.  Put that username after the URL:

 

http://www.stickam.com/servlet/ajax/getLiveUser?uname=

 

And it should work.  Like I said, I can do it just fine using the same script on my local computer's Apache server.  I literally wrote the script on my local server, got it working, then saved the same script to my FTP and tried to load it.

 

Is there some way to create a stream context using an exact copy of the header data that the browser requesting the page used?  Come to think of it, is there actually any way to view the header data that my browser sent?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.