Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,584 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,956 people online right now. Registration is fast and FREE... Join Now!




CURL Project

 
Reply to this topicStart new topic

CURL Project

JBrace1990
6 Oct, 2008 - 05:37 PM
Post #1

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
With the below code, i'm working on making a proxy. The main problem is, however, that it doesn't work right. A lot of sites use relative links (IE: <a href=main.php>).

So, there's a few problems I need help with.
1. I need to find a way to somehow fix the links. I need it to go through the same proxy, so it would be to "mysite.com/index.php?url=(site here)".
2. I need a way to post data to another page, but still have it appear (IE: login somewhere without going to that actual site).

php
<?php
$url = $_GET['url'];
$socket = curl_init();
CURL_SETOPT($socket, CURLOPT_URL, $url);
CURL_SETOPT($socket, CURLOPT_RETURNTRANSFER, 1);
CURL_SETOPT($socket, CURLOPT_FOLLOWLOCATION, 1);
CURL_SETOPT($socket, CURLOPT_HEADER, 0);
CURL_SETOPT($socket, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
$result = CURL_EXEC($socket);
CURL_CLOSE($socket);
echo $result;
?>

User is offlineProfile CardPM
+Quote Post

akozlik
RE: CURL Project
7 Oct, 2008 - 07:13 AM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Feb, 2008
Posts: 614



Thanked: 24 times
Dream Kudos: 750
My Contributions
Hey man, can you clarify #2 a bit? What do you mean by you want to login, but not go to the actual site? There's a post setting you can set

php

<?php
$c = curl_init();
$url = $_GET['url'];
CURL_SETOPT($c, CURLOPT_URL, $url);
CURL_SETOPT($c, CURLOPT_RETURNTRANSFER, 1);
CURL_SETOPT($c, CURLOPT_FOLLOWLOCATION, 1);
CURL_SETOPT($c, CURLOPT_HEADER, 0);
CURL_SETOPT($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

curl_setopt($c, CURLOPT_POST, 1);

$postfield = "field=answer1&field2=answer2";
// Change 'field' to whatever the variable is in the form you're posting to
// answer would contain the data to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);

$result = CURL_EXEC($socket);
CURL_CLOSE($socket);
echo $result;
?>


That's how you send some post data to another site, and is what you would do to login.

Remember that sites like MySpace use a token to keep track of your session. Often times you'll need to do some regex to find that token on the next page, and pass it through the postfields as well.

Actually, explaining #1 a bit better might be beneficial too.

This post has been edited by akozlik: 7 Oct, 2008 - 07:13 AM
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: CURL Project
7 Oct, 2008 - 11:34 AM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
I know how to post, but they're related to each other...

for #1, most sites use relative links (meaning it goes to main.php, not google.com/main.php). So when viewed on my page, it links to mysite.com/main.php, and since the main.php doesn't exist, people end up with a 404 error. I need to figure out how to fix the links so that they point to the correct URL (mysite.com/index.php?url=XXXXX).

#2 is about the same problem, i need to know how to post, though I think you just answered my question. I'll add that in if(isset($_POST)).

#3 is a new one, I need to know how to keep sessions from another site. Keeping a session on my site is perfectly fine, but I need it to keep a session from a page like myspace.

Also, i think this is related to #1, but all of the links appear broken, and most of the format (if any) doesn't appear correctly.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:45AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month