Daha Öncede Bu soruyu sordum hatta sdemirkeser'den curl videolarını aldım yok halen çözüm bulamadım
olay su arkadaşlar curl ile siteye login oluyoruz cogu forumda bu gibi sorular var ama hepsi yanıtsız kimisi maile giriyor kimisi mail gönderiyor curl ile hatta afganlı birinin sitesinde bunun anlatımı bile var ama ne yazıkki türkçe anlatım veya küçücük bir örnek bile bulamadım konu hakkında
şimdi smf forum var login oluyorum ve istediğim topic'e gidiyorum degerleri topic'e post ediyorum yani post etmek istiyorum curl ile ama bu sırada post sayfasında smf script'i benim session_id() mi yeniliyor bana bunları veriyor hidden inputlarlada bir kaç gizli valueler var bunlarıda alıyorum index.php giriyorum
kullanıcı adımı şifremi ve post atmak istediğim konunun linkini veriyorum
cod blogu işlemini mükemmel birsekilde yerine getiriyor ama gönder düğmesine basınca degerler değiştiği için oturumunuz zaman aşımına ugradı diyor bu olay için 3 gündür uyumuyorum çarşamba sabahından buyana çıldırdım artık şimdi kendi kodlamama benzer bir kod koyyorum arkadaşlar
bu kod ile tüm smf sürümlerine login olup son mesajı son aktif olma zamanını göreceksiniz dicem ama aynı problem bundada var Bütün sürümler için gecerli dediğim gibi smf den anlayan arkadaşlar vardır aramızda sınıfların işlemlerini yaptıktan sonra ne demek istediğimi anlayacaklar
curl fonksiyonunda öle bişi lazımki yeni gelen yanıtları eski ile güncelleyecek siteden hiç çıkış yapmamış gibi oturumunuda güncelleyip yoluna devam edecek işte kodlar arkadaşlar umarım anlatabilmişimdir...
<?php
class SMFBot
{
protected $username;
protected $password;
protected $url;
protected $totalLogged;
protected $lastPoster;
protected $lastPosterID;
protected $lastMessage;
protected $loggedIn = false;
protected $userAgent = "Opera/9.6 (Windows NT 5.1; U; pl)";
protected $sc;
protected $seqnum;
protected $sesc;
public function __construct($username, $password, $url, $userAgent = NULL)
{
if( !file_exists('smf.cookie.file.txt') ) file_put_contents('smf.cookie.file.txt', '');
if(isset($userAgent)) $this->userAgent = $userAgent;
$this->username = $username;
$this->password = $password;
$this->url = $url;
$urlLen = strlen($this->url)-1;
if($this->url[$urlLen] != '/') $this->url.='/';
$this->login();
}
protected function getPage ($url2, $ref='', $post='')
{
if(!extension_loaded('curl')) trigger_error("cURL extension unavailable",E_USER_ERROR);
$ch = curl_init();
if( !empty($post) )
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
else
{
curl_setopt($ch, CURLOPT_POST, 0);
}
if( empty($ref) or $ref == '' ) $ref = $url2;
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/smf.cookie.file.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/smf.cookie.file.txt');
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url2);
echo $r = curl_exec($ch);
return $r;
}
protected function login()
{
$this->loggedIn = true;
return $this->getPage($this->url.'index.php?aogin2', $this->url, 'user='.$this->username.'&passwrd='.$this->password.'&cookielength=-1&hash_passwrd=');
}
public function logout()
{
$this->getSesc();
$this->getPage($this->url.'index.php?action=logout;sesc='.$this->sesc);
}
public function getLastPost($topicID)
{
if($this->loggedIn == true)
{
$r = $this->getPage($this->url.'index.php/topic,'.$topicID.'.0.html');
if( eregi('class="navPages"', $r) )
{
$r = explode('class="navPages" href="', $r);
$n = count($rr)+1;
$r = $r[$n];
$r = explode('">', $r);
$r = $r[0];
$r = $this->getPage($r);
}
$r = explode($this->url.'index.php?action=profile;u=', $r);
$n = count($r)-2;
$r = $r[$n].$r[++$n];
$r = explode('<a name="lastPost"></a>', $r);
$r = $r[0];
$this->lastPoster = explode('title="Zobacz profil ', $r);
$this->lastPosterID = $this->lastPoster[0];
$this->lastPoster = $this->lastPoster[1];
$this->lastPoster = explode('">', $this->lastPoster);
$this->lastPoster = $this->lastPoster[0];
$this->lastPosterID = (int)str_replace(array($url."index.php?action=profile;u=","\" "),"",$this->lastPosterID);
preg_match("@<div class=\"post\"(.*)</div>@", $r, $this->lastMessage);
$this->lastMessage = $this->lastMessage[0];
$this->lastMessage = substr($this->lastMessage, 17, -6);
if($this->lastMessage[0] != '>') $pos = strpos($this->lastMessage, '>')+1;
else $pos = 1;
$this->lastMessage = substr($this->lastMessage, $pos);
}
else
{
$this->login();
$this->getLastPost($topicID);
}
}
protected function scSeqnum($topicID)
{
if($this->loggedIn == true)
{
$r = $this->getPage($this->url.'index.php/topic,'.$topicID.'.0.html');
$sc = explode('<input type="hidden" name="sc" value="', $r);
$sc = $sc[2];
$sc = explode('"', $sc);
$this->sc = $sc[0];
$seqnum = explode('<input type="hidden" name="seqnum" value="', $r);
$seqnum = $seqnum[1];
$seqnum = explode('"', $seqnum);
$this->seqnum = $seqnum[0];
}
else
{
$this->login();
$this->scSeqnum($topicID);
}
}
protected function getSesc()
{
if($this->loggedIn == true)
{
$r = $this->getPage($this->url);
preg_match("@(sesc\=)[a-z0-9]{32}@", $r, $sesc);
$this->sesc = substr($sesc[0], 5);
}
else
{
$this->login();
$this->getSesc();
}
}
public function postMessage($topicID, $message, $subject='', $icon='exclamation')
{
if($this->loggedIn == true)
{
$this->scSeqnum($topicID);
$message = $this->replace($message);
$subject = $this->replace($subject);
$ref = $this->url.'index.php?action=post;topic='.$topicID.'.0;num_replies=0';
$tar = $this->url.'index.php?action=post2';
$post = 'postmodify&topic='.$topicID.'&subject='.$subject.'&icon='.$icon.'&num_replies=0&message='.$message.'¬ify=0&goback=1&sticky=0&showsig=1&ns=NS&post=Send&c='.$this->sc.'&seqnum='.$this->seqnum;
$this->getPage($tar, $ref, $post);
}
else
{
$this->login();
$this->postMessage($topicID, $message, $subject, $icon);
}
}
public function editMessage($topicID, $messageID, $message, $subject='', $icon='', $append=false)
{
if($this->loggedIn == true)
{
$this->getSesc();
$ref = $this->url.'index.php?action=post;msg='.$messageID.';topic='.$topicID.'.0;sesc='.$this->sesc;
$r = $this->getPage($ref);
if($subject == '')
{
preg_match("@(<input type=\"text\" name=\"subject\" value=\")(.*)(\" tabindex)@", $r, $subject);
$subject = $subject[2];
}
if($icon == '')
{
preg_match("@(<option value=\")(.*)(\" selected=\"selected\">)@", $r, $icon);
$icon = $icon[2];
}
if($append == true)
{
preg_match("@(<textarea class=\"editor\" name=\"message\")(.*)(\">)(.*)(</textarea>)@", $r, $oldMessage);
$oldMessage = $oldMessage[4];
$message = $oldMessage.' '.$message;
}
preg_match("@(<link rel=\"index\" href=\"".$this->url."index.php/board,)([0-9]{1,5})(.0.html)\" />@", $r, $board);
$board = $board[2];
$message = $this->replace($message);
$subject = $this->replace($subject);
$tar = $this->url.'index.php?action=jsmodify;start=0;msg='.$messageID.';sesc='.$this->sesc.';board='.$board.';xml';
$post = 'postmodify&topic='.$topicID.'&subject='.$subject.'&icon='.$icon.'&num_replies=50&message='.$message.'¬ify=0&lock=0&goback=1&sticky=0&showsig=1&post=Zachowaj&sc='.$this->sc.'&seqnum='.$this->seqnum.'&additional_options=0';
$r = $this->getPage($tar, $ref, $post);
}
else
{
$this->login();
$this->editMessage($topicID, $messageID, $message, $subject, $icon, $append);
}
}
public function totalLogged()
{
if($this->loggedIn == true)
{
$r = $this->getPage($this->url);
$r = explode('class="middletext"', $r);
$r = $r[1];
$r = explode('<br />', $r);
$r = explode(':', $r[2]);
$r = explode(' ', $r[1]);
$this->totalLogged = (($r[1] * 24 + $r[3]) * 60 + $r[5]) * 60;
}
else
{
$this->login();
$this->totalLogged();
}
}
public function lockTopic($topicID)
{
if($this->loggedIn == true)
{
$this->getSesc();
$r = $this->getPage($this->url.'index.php?action=lock;topic='.$topicID.';sesc='.$this->sesc);
}
else
{
$this->login();
$this->lockTopic($topicID);
}
}
protected function replace($string)
{
$string = str_replace('"', '"', $string);
$string = str_replace(' ', ' ', $string);
$string = rawurlencode($string);
return $string;
}
public function getUsername()
{
return $this->username;
}
public function getLastPoster()
{
return $this->lastPoster;
}
public function getLastPosterID()
{
return $this->lastPosterID;
}
public function getLastMessage()
{
return $this->lastMessage;
}
public function getTotalLogged()
{
return $this->totalLogged;
}
public function getUser($ID)
{
$xmluri = $this->url . "index.php?action=.xml;sa=profile;u=$ID";
if(true == $this->loggedIn)
{
if ($xml = @simplexml_load_file($xmluri, 'SimpleXMLElement',LIBXML_NOCDATA))
{
return $xml;
}
else
{
return new SimpleXMLElement("<response><success>false</success><message>XML data unavailable</message></response>");
}
}
else
{
$this->login();
return $this->getUser($ID);
}
}
public function setUserAgent($userAgent)
{
if (!empty($userAgent)) $this->userAgent = $userAgent;
}
}
?>Örnek Kullanım
<?
$yeni = new SMFBot("kullamıcıadınz","şifreniz","http://www.domain.net","");
$yeni ->postMessage("topicid","göndereceğiniz mesaj","mesaj başlığı","avatar buraya sadece xx koymalısınız");
?>ben bunun biraz daha gelişmişini yaptım daha fonksiyonel ama bir türlü bu son noktayı gecemiyorum
post olayından sonra CULROPT_COOKIEJAR belki cookieyi yeniler dedim ama tık yok