Log in

Coyote's Coding
Livejournal & Writing Related Coding Projects
Fixed comment checker revamping brainstorm; Fetch LJ Page PHP function 
9th-Feb-2006 12:05 am
Turns out I was being a silly billy and I introduced a bug into my community check scripts. But the error's now fixed and I'm back to fetching.

Still, it's time to revamp the comment checker:
  1. One page for all checking and displaying of latest comments.
  2. One page managing all the communities I check.
  3. Make it into a class so it can be presented to somewhere like lj_nifty.

Here's my PHP function (simplified) for fetching a pages from LJ with auth digest, with the $url being just a simple one, such as "community.livejournal.com/write_away/2006/01":

function fetchLJPage( $url )
  $passwd_string = "$ljUsername:$ljUserpass"; 
  $url = "http://$passwd_string@$url?auth=digest";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_VERBOSE, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_USERPWD, $passwd_string);
  curl_setopt($ch, CURLOPT_URL, $url);

  $returned = curl_exec($ch);
  if( curl_error( $ch ))
    print "<p><b>CURL ERROR (". curl_errno($ch) ."):</b> " . curl_error( $ch ) . "</p>";
  return $returned;

Note that if you want to add extra options at the end, like style=mine, or use a URL with a #ending, you'll have to change the code and take the "?auth=digest" off the end of $url and add it yourself, like I do.
This page was loaded Jul 22nd 2017, 10:32 am GMT.