Skip to content

Instantly share code, notes, and snippets.

@nyom
Forked from 0x46616c6b/gist:849598
Created March 1, 2011 20:09
Show Gist options
  • Save nyom/849785 to your computer and use it in GitHub Desktop.
Save nyom/849785 to your computer and use it in GitHub Desktop.
<?php
$debug = 1;
function fetchsite($url = NULL, $matrikel = NULL, $password = NULL) {
global $debug;
if ($debug) {
$matrikel = $_GET['matrikel'];
$password = $_GET['password'];
}
$login_url = "http://www.ba-dresden.de/index2.php?menu=5";
$cookie = "/tmp/cookie.txt";
if ($debug) {
if(file_exists($cookie)) {
unlink($cookie);
}
}
if ( $url && $matrikel && $password ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "matrikelnr=" . $matrikel . "&passwort=" . $password);
ob_start(); // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
if ($debug) {
if (file_exists($cookie)) {
$f = fopen($cookie, "r");
echo "<pre>+ + + C O O K I E + + +</pre>";
while (!feof($f)) {
$buffer = fgets($f);
echo "<pre>" + $buffer + "</pre>";
}
fclose($f);
echo "<pre>+ + + + + + + + + + + +</pre>";
} else {
echo "<pre>+ + + N O C O O K I E + + +</pre>";
}
}
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
return html_entity_decode(htmlentities($result));
} else {
if ($debug) echo "Worst!";
}
}
// $url = "http://www.ba-dresden.de/index2.php?menu=5&item=20";
// $matrikel = "0009999";
// $password = "csbsbJzhvhj"
// $html = fetchsite($url, $matrikel, $password);
$html = fetchsite("http://www.ba-dresden.de/index2.php?menu=5&item=20");
if($debug) echo "<pre>" + $html + "</pre>";
// Einträge aus den News ziehen und formatiert wiedergeben
$ret = preg_match_all("/<td width=\"60\" class=\"line.*.\">(.+)<td width=\"15\"class=\"line.*.\">/siU", $html, $events);
foreach($events[1] as $event) {
//print_r ($event);
$html = $event;
$ret = preg_match_all("/(.+)<\/td><td width=\"90\" class=\"line.*.\">(.+)<\/td><td class=\"line.*.\">(.+)<\/td>" .// auslesen in data1-3 datum,person,inhalt
"/siU", $html, $data, PREG_SET_ORDER);
$content = $data[0][3];
$date = $data[0][2];
$name = $data[0][1];
echo $name . "<br />" . $date . "<br />" . $content . "<br /><hr /><br />";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment