Hallo Leute,

ich habe einen Snippet gefunden im Internet, allerdings endet der in einer Endlosschleife. Weiß bzw. findet jemand zufällig den Fehler, denn der Autor hat leider nichts mehr geschrieben dazu.

PHP-Code:
<?php
  
function process_cookies ($httpobj$cookiejar = array()) {
    
// Function get the cookies that should be sent in the next request
    
if (!count($cookies $httpobj->getResponseCookies())) return $cookiejar;
    foreach (
$cookies as $key => $data) {
      if (
$data+++91;'value'+++93; !== '' && (!isset($data+++91;'expirestime'+++93;) || $data+++91;'expirestime'+++93; > time())) {
        
$cookiejar+++91;$key+++93; = $data+++91;'value'+++93;;
      } else if (isset(
$cookiejar+++91;$key+++93;)) {
        unset(
$cookiejar+++91;$key+++93;);
      }
    }
    return 
$cookiejar;
  }

  
$url1 'http://www.facebook.com/';
  
$url2 'https://login.facebook.com/login.php';

  
// Fetch the class
  
require('class.httprequest.php');

  
// Create an object and get the main page of facebook.com
  
$request1 = new httprequest;
  if (!
$request1->setRequestURL($url1)) exit("Error setting request 1 URL: ".$request1->getLastErrorStr()."<br>\r\n");
  if (!
$request1->sendRequest()) exit("Error sending request 1: ".$request1->getLastErrorStr()."<br>\r\n");

  
// Create an object for the POST request
  
$request2 = new httprequest;

  
// Set request method and URL      
  
$request2->setRequestMethod('POST');
  if (!
$request2->setRequestURL($lastLocation $url2)) exit("Error setting request URL: ".$request2->getLastErrorStr()."<br>\r\n");

  
// All the other headers will be built by the class but we need
  // set this one explicitly
  
$request2->setRequestHeader('Referer',$url1);

  
// Get the cookies sent by the last request and forward them on
  
$cookiejar process_cookies($request1);
  if (
count($cookiejar)) $request2->setRequestCookies($cookiejar);

  
// Set the request body
  
$data = array(
    
'email'=>'testemail',
    
'pass'=>'testpass'
  
);
  
$request2->setRequestControls($data);

  
// We need to handle redirects ourselves to make sure the cookies are sent correctly
  
$request2->setHandleRedirects(FALSE);

  
// Keep looping until we get a 2xx response
  
while (TRUE) {
    if (!
$request2->sendRequest()) exit("Error sending request: ".$request2->getLastErrorStr()."<br>\r\n");
    if (
$request2->getResponseCode() >= 200 && $request2->getResponseCode() < 300) break;
    if (
$request2->getResponseCode() >= 300 && $request2->getResponseCode() < 400) {
      
$nextLocation $request2->getResponseHeader('location');
      if (!
$nextLocation) exit("Error: Server responded with redirect response code ".$request2->getResponseCode().", but did not send a valid location header<br>\r\n");
      
$cookiejar process_cookies($request2,$cookiejar);
      
$request2->resetRequestCookies();
      
$request2->setRequestCookies($cookiejar);
      
$request2->setRequestHeader('Referer',$lastLocation);
      if (!
$request2->setRequestURL($lastLocation $nextLocation)) exit("Error setting request URL: ".$request2->getLastErrorStr()."<br>\r\n");
      continue;
    }
    exit(
"Server responded with unhandled HTTP response code: ".$request2->getResponseCode()."<br>\r\n");
  }

  
// validate and display the response
  
if (!$response $request2->getResponseBodyData(TRUE)) exit('Error: No body data returned<br>'."\r\n");
  exit(
$response);

?>
Die dazugehörige Klasse findet man hier:
Code:
http://download.networkm.net/code/php/class.httprequest.1.3.php.tar.gz
Und hier die Quelle:
Code:
http://stackoverflow.com/questions/7699764/php-https-post-request/7700213#7700213
Also ich hab als Beispiel nun mal Facebook genommen, aber es sollte auch bei anderen Seiten funktionieren. Ich will damit nichts böses anstellen natürlich, ich möchte einen Auto-Login realisieren auf Seiten, die die Redirect-URL checken

Ich selbst habe nicht viel Ahnung von PHP, aber ich brauche dieses Script, um in meinem Gesamtprojekt weiterzukommen

Wenn jemand helfen könnte, wäre ich wirklich dankbar.

Gruß & Danke,
Jannik