views:

552

answers:

1

I'm trying to make a php cURL script that should act like a bridge/proxy (like "man in the middle" but nothing hacking ), make a POST to a url (example.com) and redirect the client to that link after it gets the response . I'm not sure if it's possible so please advise. Basically the client will pass 2 values through our site (e.g examplecurl.com) and after the values are passed the client must be redirected to that specific site (example.com) logged-in like it have passed the values directly through example.com. I need to mention that "example.com" site doesn't use cookies and I can successfully pass the values through the cURL script, i set follow_location option but the only problem is the redirection.

Thank you in advance for your help ! any solution would be appreciated !

+1  A: 

I'm going to assume you're writing this in PHP (looking at the tags):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_POSTFIELDS,"a=hello&b=world");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
curl_close($ch);

That's how you make a POST request to example.com with cURL. A website cannot 'log you in' without cookies so you would probably need to specify a cooke jar like so:

curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");

Now, all requests you make through cURL will keep you 'logged in' on example.com using the session you just created (through cURL) until you call curl_close().

Your question was a bit confusing, I hope I answered it.

David Titarenco