Jump to content


Photo

get_file_contents()


  • Please log in to reply
2 replies to this topic

#1 tobes

tobes
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNH

Posted 18 June 2006 - 07:56 PM

Hello. I'm working on a PHP project and I want it to accomplish the following tasks:

1. A user copies and pastes a URL into a form and submits it.
2. The PHP code validates the URL based on preset credentials and proceeds to grab the page contents of the URL.
3. If the URL and the contents pass set critera, the PHP code then grabs and stores certain elements of the page into a file.

I've got most of it done. I'm experienced with PHP and it should work fine. The only problem is that the URLs that are submitted into the form require preauthorization for their contents to be extracted, otherwise get_file_contents just returns the login page. Now, I do have a username and password for the site the submitted URLs are hosted on, and I can easily grab the contents of the pages manually (if I sign in and navigate to them), but I would love for it to be done automatically. Is there anyway this can be done?

This is the code of my page with the form on it that users enter the URL in:
<form method="post" action="checkproof.php">
<font face="verdana" size="3">
Proof URL: <input type="text" name="proofurl" size="100">
</font>
<br><br>
<input type="submit" value=" - - - Check my proof! - - - ">
</form>

This is the beginning of the code for checkproof.php that fails:
<?php
$proofurl = $_POST["proofurl"];
$urlcontents = file_get_contents($proofurl);
?>
Instead of containing the content of $proofurl, $urlcontents ends up containing the main site sign in form page (several elements of which I have removed).
<form action="[CFN Validation Location]" method="post" name="..." id="...">
<input type="hidden" name="NextPage" value="...">
<input type="text" name="email" size="20">
<input type="password" name="password" size="20">
<input type="image" src="..." id="..." name="..." onclick="return doSubmit();">
</form>

Is it possible to use PHP to login to this form with my e-mail and password before calling on $urlcontents allowing access to the page contents?

Thanks.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 18 June 2006 - 08:04 PM

I think it's possible to do this with cURL (libcurl) and PHP. Search Google for "cURL tutorial" the official site should be at the top, or check out the curl functions in the PHP manual (I think there's some in there)

#3 tobes

tobes
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNH

Posted 18 June 2006 - 08:05 PM

[!--quoteo(post=385406:date=Jun 18 2006, 04:04 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 18 2006, 04:04 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think it's possible to do this with cURL (libcurl) and PHP. Search Google for "cURL tutorial" the official site should be at the top, or check out the curl functions in the PHP manual (I think there's some in there)
[/quote]
Thanks much for the quick reply. I will check that out.

--Toby

EDIT: I just wanted to say thanks for the kick in the right direction. I found everything I needed as you suggested. Thanks again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users