Dennis Wronka
Soulcollector
2 Fragen:
- Welche Version von HTTPConnection nutzt Du?
- Was steht in $_SESSION['cookie']?
Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
<?php
session_start();
//$url="http://www2.htlwrn.ac.at/d05044/sbnk/buecher.php";
if(empty($_POST['stichwort'])){
$ch = curl_init();
$url="http://www.bibliotheken.at/woload.asp?startart=1&startland=31818001";
$proxy="193.170.149.182";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookies.txt");
/*//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch,CURLOPT_PROXYPORT,8080);
curl_setopt($ch,CURLOPT_PROXY,$proxy);
//curl_setopt($ch,CURLOPT_REFERER,$referer);
//curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');*/
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
$header = $output;
$end = strpos($header, "Content-Type");
$start = strpos($header, "Set-Cookie");
$parts = split("Set-Cookie: ",substr($header, $start, $end-$start));
$cookies = array();
foreach ($parts as $co)
{
$cd = split(";",$co);
if (!empty($cd[0]))
$cookies[] = $cd[0];
}
//file_put_contents ("cookies.txt", "test");
if ($output == false /*|| $info['http_code'] != 200*/) {
$output = "No cURL data returned for $url [". $info['http_code']. "]<br/>";
if (curl_error($ch))
$output .= "\n". curl_error($ch);
echo 'Es ist ein Fehler aufgetreten!<br/>';
// echo $output;
echo implode(";",$cookies);
file_put_contents("cookies.txt",implode(";",$cookies));
}
else {
// 'OK' status; format $output data if necessary here:
echo 'Hat funktioniert!<br/>';
//echo $output;
echo implode(";",$cookies);
echo $output;
file_put_contents("cookies.txt",implode(";",$cookies));
}
curl_close($ch);
$_SESSION['cookie']=implode(";",$cookies);
// then return or display the single string $output
}
else{
/*
$ch = curl_init();
$url="http://www.bibliotheken.at/results.asp";
echo $url."<br/>";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookies.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 61440);
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 20);
curl_setopt($ch,CURLOPT_TIMEOUT,6580);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"Stichwort=".$_POST['stichwort']."&ZST=31818001");
//curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
//curl_setopt($ch,CURLOPT_PROXYPORT,8080);
//curl_setopt($ch,CURLOPT_PROXY,$proxy);
//curl_setopt($ch,CURLOPT_REFERER,$referer);
//curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');*/
//curl_setopt($ch, CURLOPT_HEADER, 1);
/*
$output = curl_exec($ch);
$info = curl_getinfo($ch);
if ($output == false /*|| $info['http_code'] != 200) {
$output = "No cURL data returned for $url [". $info['http_code']. "]<br/>";
if (curl_error($ch))
$output .= "\n". curl_error($ch);
echo 'Es ist ein Fehler aufgetreten!<br/>';
echo $output;
}
else {
// 'OK' status; format $output data if necessary here:
echo 'Hat funktioniert!<br/>';
echo $output;
file_put_contents("test.txt",$output);
}
curl_close($ch); */
//2---
/** $opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: ".$_SESSION['cookie']."\r\n"
)
);
echo $_SESSION['cookie'];
$context = stream_context_create($opts);
$link = "http://www.bibliotheken.at/results.asp?Stichwort=".$_POST['stichwort']."&ZST=31818001"; //Beispiel
$data = fopen($link, 'r', false, $context);
$data = fgets($data);
echo $data;**/
//3---
require("httpconnection.class.php");
/*$http=new httpconnection("www.bibliotheken.at");
$data=$http->post("results.asp","Stichwort=".$_POST['stichwort']."&ZST=31818001",$_SESSION['cookie'],"","","","");
echo nl2br(print_r($data['head'],true));
$output= $data['body'];
file_put_contents("test.txt",$output);
unset($http);*/
$http=new httpconnection("www.bibliotheken.at");
$data=$http->get("results.asp","Stichwort=".$_POST['stichwort']."&ZST=31818001",$_SESSION['cookie'],"","");
echo nl2br(print_r($data['head'],true));
echo $data['body'];
unset($http);
}
?>
<form name="aha" method="post" action="<? echo $_SERVER['SCRIPT_NAME'];?>">
<span style="margin-top: 5px; color: black;">Stichwort:</span>
<input type="text" name="stichwort" size="15" />
<input type="submit" value="suchen" title="Suchen" />
</form>
<?php
session_start();
require("httpconnection.class.php");
if(empty($_POST['stichwort'])){
$http=new httpconnection("www.bibliotheken.at");
$data=$http->get("woload.asp","startart=1&startland=31818001","","","");
//echo nl2br(print_r($data['head'],true));
echo $data['head']['cookies'][0]['name']."=".$data['head']['cookies'][0]['value'];
$_SESSION['cookie']=$data['head']['cookies'][0]['name']."=".$data['head']['cookies'][0]['value'];
unset($http);
}
else{
$http=new httpconnection("www.bibliotheken.at");
$data=$http->post("results.asp","Stichwort=".$_POST['stichwort']."&ZST=31818001",$_SESSION['cookie'],"","","","");
echo nl2br(print_r($data['head'],true));
echo $data['body'];
unset($http);
}
?>
<?php
require_once('../php-classes/php5/tcpconnection.class.php');
require_once('../php-classes/php5/httpconnection.class.php');
$stichwort='Baum';
$http=new httpconnection('www.bibliotheken.at');
$data=$http->get('woload.asp',array('startverbund=','startart=','startland='));
$cookies=array($data['head']['cookies'][0]['name'].'='.$data['head']['cookies'][0]['value']);
$data=$http->get('woload.asp',array('startverbund=','startart=','startland='),$cookies);
$data=$http->get('results.asp',array('STICH1='.$stichwort),$cookies);
var_dump($data['head']);
echo $data['body'];
unset($http);
?>