• 18-11-2013, 20:48:57
    #1
    Merhaba. Ben bir siteden bilgi almaya çalışıyorum CURL ile. Giriş ve gerekli sayfanın açılması hatta bilginin çekilmeside tamam. Ancak şöyle bir sorunum var, sistem cookie kaydettiği için ben hesabımdan çıkıp başka bir hesabın bilgileriyle girsemde curldan gelen sonuç eski hesaba ait oluyor. Yani sistem bir kez cookie oluşturuyor ve hep onu okuyor.

    Bunu aşmak için cookie dosyasına random sayılar ekledim ancak bu seferde yeni bir hesabın bilgisi girildiğinde sistem önce kabul etmiyor, tekrar aynı bilgilerle denediğinizde kabul ediyor.

    Bunu nasıl çözebilirim? Aslında cookie olmasada olur ama bir türlü yapamadım. Yardımlarınızı bekliyorum.

    Kod:
    <?php 
    	$id = trim(htmlspecialchars(@$_GET["id"])); 
    	$pw = trim(htmlspecialchars(@$_GET["pass"])); 
     
    	//empty id or pass
    	if(!empty($id) && !empty($pw)){
    					
    			$id = $_GET["id"]; 
    			$pw = $_GET["pass"]; 
    			
    			$ch = curl_init(); 
    				curl_setopt($ch, CURLOPT_HEADER, 0);
    				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    				curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    				curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); 
    				curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); 
    				curl_setopt($ch, CURLOPT_POST, true); 
    				curl_setopt($ch, CURLOPT_POSTFIELDS, "student_no=".$id."&student_pass=".$pw.""); 
    				curl_setopt($ch, CURLOPT_URL, "http://xxxx.com/login_student.php");
    				$veri = curl_exec($ch);
    				
    				curl_setopt($ch, CURLOPT_URL, "http://xxxx.com/student.php?cat=preparatory");
    				$veri = curl_exec($ch);
    
    				@preg_match('#Module Grade: (.*?)</td></tr></table><br /><br />#',$veri,$end_of_the_module);
    				@preg_match_all('#<span class="content">W-(.*?)</span></td>#',$veri,$weeks);
    				@preg_match_all('#<span class="content">(.*?)</span>#',$veri,$devamsiz);
    
    				$kactan = array_search('W-1',$devamsiz[1]) + 2;
    				$son_array = end($weeks[1]);
    				$sonuncu = $kactan+$son_array*3;
    
    				for ($i=$kactan;$i<=$sonuncu;$i+=3)
    				$devamtop[] = @$devamsiz["1"][$i];
    				$toplamdev = array_sum($devamtop);
    				$end_of = @$end_of_the_module["1"];
    				
    				
    				echo"
    				<label> Total Absent Hours: {$toplamdev} Hours </label>
    				<label> End Of The Module: {$end_of} Points </label>
    				";
    				
    			curl_close($ch);
    
    		// wrong username or password
    		if(empty($veri)){
    		
    			echo"<label style='border-radius:10px;margin:10px 0;color:red'>Wrong Stundent Number or Student Password!</label>";
    			echo"<meta http-equiv=\"refresh\" content=\"2;url=index.php\">";
    			
    		}
    		
    	}else{
    	// don't empty blank!
    	if(!empty($id) || !empty($pw)){
    		echo"<label style='border-radius:10px;margin:10px 0;color:red'>Please, don't empty blank!</label>";
    		echo"<meta http-equiv=\"refresh\" content=\"2;url=index.php\">";
    	}
    	?>
    TeamViewer ile sistemin çalışan haline bakabilirsiniz.
  • 18-11-2013, 23:01:14
    #2
    eğer yeni bilgilerle giriş yapıyorsanız unlink("cookie.txt"); ile cookie dosyasını silip ondan sonra curl oturumunu başlatmayı denediniz mi ?

    veya cookie dosyasının adına random yerine student id yi ekletin örn "cookie_student_no.txt" gibi. böylece girilen id ye göre cookie çekip curlde kullanabilirsiniz.
  • 19-11-2013, 02:19:58
    #3
    Kimlik doğrulama veya yönetimden onay bekliyor.
    <?php
    	# Requests for PHP kütüphanesini aşağıdaki bağlantıdan indirebilirsiniz.
    	# https://github.com/rmccue/Requests
    	#
    	# Requests for PHP sınıfımızı dahil edelim.
    	require("Requests.php");
    	# Otomatik sınıf yükleyicisi başlatalım.
    	Requests::register_autoloader(); 
    	# Yeni bir oturum oluşturalım.
    	$session = new Requests_Session();
    	# Oluşturduğumuz oturum ile ilgili adrese gidip çerez oluşturmasını isteyelim.
    	$response = $session->get("https://httpbin.org/cookies/set?k1=v1&k2=v2");
    	# Oluşan çerezlerden "k1" anahtarına sahip olan çerezin bilgilerini alalım.
    	print_r(
    		$response->cookies->offsetGet("k1")
    	);
    Bu mesajım size yardımcı olduysa R10+ butonuna tıklamayı unutmayınız.
  • 19-11-2013, 17:36:28
    #4
    Hepinize teşekkür ederim sonunda hallettim