header-location vom curl auslesen

Paspirgilis

Weißer Powerranger
Hi,
Ich hole mir mit curl eine Page,
diese Page redirected mich mit header('location: ...') woanders hin.
In dieser neuen url steht eine id, die ich auslesen möchte.
PHP:
$ch = curl_init();

$data = array('playerSearch' => 'username');

curl_setopt($ch, CURLOPT_URL, 'http://www.website.com/player_stats.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$page = curl_exec($ch);
Damit folgt er zum mindest mal dem redirect,
Aber ich würde vielieber die location von dem hier auslesen:
PHP:
$ch = curl_init();

$data = array('playerSearch' => 'username');

curl_setopt($ch, CURLOPT_URL, 'http://www.website.com/player_stats.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$page = curl_exec($ch);
und darin steht dann als get-parameter die id auf die ich hinaus möchte.
Ist hier irgendeiner der sich mit curl besser auskennt?

MfG
Mark Paspirgilis
 
Also wenn ich dich jetzt richtig verstanden habe, möchtest Du mittels cURL das Redirect-Ziel auswerten?

Wenn dem so ist, schau dir mal
PHP:
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "callback")
Damit kannst du eine Callbackfunktion angeben, mit deren Hilfe du den HTTP-Response-Header auswerten kannst. In diesem sollte das Ziel der Umleitung angegeben sein.

Grüße!
 
mit diesem unorganisiertem haufen code:
PHP:
<?php
$headerString = 'start';

function read_header($ch, $string)
{
    echo $string;
    global $location; #keep track of location/redirects
    global $cookiearr; #store cookies here
    global $ch;
       # ^overrides the function param $ch
       # this is okay because we need to
       # update the global $ch with
       # new cookies

    $length = strlen($string);
    if(!strncmp($string, "Location:", 9))
    { #keep track of last redirect
      $location = trim(substr($string, 9, -1));
    }
    if(!strncmp($string, "Set-Cookie:", 11))
    { #get the cookie
      $cookiestr = trim(substr($string, 11, -1));
      $cookie = explode(';', $cookiestr);
      $cookie = explode('=', $cookie[0]);
      $cookiename = trim(array_shift($cookie));
      $cookiearr[$cookiename] = trim(implode('=', $cookie));
    }
    $cookie = "";
    if(trim($string) == "")
    {  #execute only at end of header
      foreach ($cookiearr as $key=>$value)
      {
        $cookie .= "$key=$value; ";
      }
      curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }

    return $length;
}

ob_start();
$ch = curl_init();

$data = array('playerSearch' => 'fichte');

curl_setopt($ch, CURLOPT_URL, 'http://www.heroesofnewerth.com/player_stats.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); 

$page = curl_exec($ch);

$contents = ob_get_contents();
ob_end_clean();

echo preg_replace('/\<html.+/is', '', $contents);

//var_dump($GLOBALS);
?>
kommt das heraus:
Code:
HTTP/1.1 100 Continue HTTP/1.1 302 Found Date: Tue, 14 Sep 2010 12:39:34 GMT Server: S2 Games http/html Server X-Powered-By: Awesomesauce Set-Cookie: PHPSESSID=d3630b739f2a3437c4bd6d830ad5f7d2; expires=Tue, 21 Sep 2010 12:39:34 GMT; path=/; domain=.heroesofnewerth.com Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache location: http://www.heroesofnewerth.com/player_stats.php?aid=3012251 Vary: Accept-Encoding,User-Agent Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 HTTP/1.1 200 OK Date: Tue, 14 Sep 2010 12:39:35 GMT Server: S2 Games http/html Server X-Powered-By: Awesomesauce Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8
Nun kann ich mich durch arbeiten druch die hon ajax requests xD
Hab alle ajax schnittstellen von denen gefudnen und man braucht dann immer die user id.
Nun kann cih z.B. alle spielen von einem user auslesen, udn somit geanuere analysierungen unter anderem mit meinem profil durchführen :)
Is mein nächstes project nach P-DL.eu
Da DotA leider gestroben is :(
Aber DotA lebt ja in HoN weiter.. sry ich quassel zu viel :D
Auf jeden fall für alle die probleme mit sowas haben, hab den "funktionierenden" code ja gepostet.

MfG
Mark Paspirgilis
 

Neue Beiträge

Zurück