Jump to content

Error With Php Proxy Script


jbach
 Share

Recommended Posts

Hi

having problems getting a proxy script to work.

 

Getting the following error message

 

"function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden..."

 

Can someone help?

 

this is the script

//SCRIPT BEGINS

 

<?php

// PHP Proxy

 

$url = 'http://';

if (isset($_GET['sd']) && $_GET['sd'] != '')

{

$url .= $_GET['sd'].'.';

}

//ensure only twitter domains are used

$url .= 'twitter.com/';

 

if (isset($_GET['path']) && $_GET['path'] != '')

{

$url .= $_GET['path'];

}

//you can change this to set mimeType via parameters, but

//chances are you want xml

$mimeType = 'application/xml';

$response = file_get_contents($url);

 

if ($mimeType != "")

{

header("Content-Type: ".$mimeType);

}

 

echo $response;

?>

//SCRIPT ENDS

Link to comment
Share on other sites

A 403 means that the server you are requesting (in this instance twitter) is denying your request. They have possibly blocked your IP or User Agent.

 

Doesn't Twitter offer an API for this sort of thing? What is it you are trying to do with the script exactly?

Link to comment
Share on other sites

Yes, thought I posted in the wrong forum but didn't know how to delete my original post.

 

In a nutshell

I'm building a Twitter client in actionscript and using OAuth for authentication.

 

 

The initial login (directing the user to twitter's OAuth sign in) works when I compile on the desktop, but NOT so far in a web browser (which requires the php proxy).

 

A php proxy is required because

1- flash has strict security requirements and requires just a crossdomain.xml file to be defined on the remoter server

2-BUT Twitter doesn't allow this crossdomain.xml file

 

 

The basic steps for OAuth authentication are

1-User first registers their application and obtains a key and secret

2-User requests a REQUEST token(on sign-log in) from Twitter

3-Twitter replies with the request token key

4-This request token is then appended to the Twitter OAuth sign in url at http://twitter.com/oauth/authorize?oauth_token=<insert request key here>

5-On successful sign in, Twitter marks the original request token as user-authorized.

 

 

The whole process seems a bit convoluted, but OAuth has a number of advantages and is Twitter's recommended scheme for authorization moving forward.

Where I seem to be stumbling is step 4, the request token key is not being appended to the OAuth sign in url.

Edited by jbach
Link to comment
Share on other sites

Unfortunately I am not a flash developer nor an OAuth expert so I can't really help out there I am afraid.

 

 

ok

But would you be able to tell me if the following should work?

 

<?php

 

$url = 'http://';

//ensure only twitter domains are used

$url .= 'twitter.com/';

 

if (isset($_GET['path']) && $_GET['path'] != '')

{

$url .= $_GET['path'];

}

 

$mimeType = 'application/xml';

$response = file_get_contents($url);

if ($mimeType != "")

{

header("Content-Type: ".$mimeType);

}

echo $response;

?>

Link to comment
Share on other sites

ok getting close...I may start a new post as Im really trying to get this to work this morning

 

 

My php so far

<?php

$content = 'http://';

$content .= file_get_contents($_GET['path']);

 

if ($content !== false)

{

 

echo($content);

}

else

{

// there was an error

}

?>

 

 

The browser error message I get:

 

Warning: file_get_contents(twitter.com/oauth/authorize?oauth_token=) [function.file-get-contents]: failed to open stream: No such file or directory in /home/bitstre/public_html/twitter/proxy.php on line 3

http://

 

 

Any feedback welcome!

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...