Merhaba arkadaşlar, PHP cURL ile bir siteye giriş yapıp veri çekmeye çalışıyorum. Deneme amaçla <title> etiketlerini çekmeye çalıştım. Fakat "Notice: Undefined offset: 0 in example.php on line 28" hatası alıyorum. Sanırım veri çekme işlemi başarısız olduğu için değer atamıyor.

Login olmaya çalıştığım sayfanın html kodları:

<form method="post" name="login" action="takelogin.php">
<p>Önemli :Bu siteye girmek için çerezler (Cookies) etkin olmalidir.</p>
<table border="0" class="test" cellpadding="5" width="220">
<tbody><tr><td class="rowhead">Kullanici:</td><td align="left"><input type="text" size="20" name="username"></td></tr>
<tr><td class="rowhead">?ifre:</td><td align="left"><input type="password" size="20" name="password"></td></tr>

<tr><td colspan="2" align="center"><input type="submit" value="Gir!" class="btn"></td></tr>
</tbody></table>
</form>

ve bunlar da veri çekmeye çalıştığım php kodları:

<?php
	function siteConnect($site){
		$username="username"; 
		$password="password"; 
		$loginpage="takelogin.php"; 
		$cookie="cookie.txt";
		
		$postdata = "username=$username&password=$password&submit=Gir!";
		
		$ch = curl_init();
		$hc = "YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; Yahoo! Search - Web Search)";
		curl_setopt($ch, CURLOPT_URL, $loginpage);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_USERAGENT, $hc);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
		curl_setopt($ch, CURLOPT_REFERER, 'http://r10.net');
		curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
		curl_setopt ($ch, CURLOPT_POST, 1);
		$loginpage = curl_exec($ch);
		curl_close($ch);

		
		preg_match_all('@<title>(.*?)</title>@si',$site,$veri_derece1);

		echo $veri_derece1[0][0];
	}

	$giris = siteConnect('http://siteadresi.com');
	echo $giris;


?>
Nerede hata yapıyorum bulamadım. Yardımlarınız için teşekkür ederim.

EDİT: Hataları düzelttim, yardımcı olabilir diye kodumu buraya bırakıyorum

<?php
		$username="username"; 
		$password="username"; 
		$loginpage="takelogin.php"; 
			
		$postdata = "username=".$username."&password=".$password."&login";
		
		$ch = curl_init();
		$hc = "YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; Yahoo! Search - Web Search)";
		curl_setopt($ch, CURLOPT_URL, $loginpage);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_USERAGENT, $hc);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
		curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
		curl_setopt($ch, CURLOPT_REFERER, 'http://r10.net');
		curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata );
		curl_setopt ($ch, CURLOPT_POST, 1);
		$loginpage = curl_exec($ch);
	

		$site="loginden sonra veri çekilecek adres";
		curl_setopt($ch, CURLOPT_URL ,$site);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

		$output = curl_exec($ch);
		echo $output;
		curl_close($ch);
		
		
?>