Ben php ile Google sıralama kontrol scriptini biraz daha geliştirmeye çalışıyorum... Elimdeki Script gopof gibi anahtar kelime ile site adresi olduğunda o sitenin o kelimede kaçıncı sırada olduğunu söylüyor...
Ben bunu veri tabanı ile geliştireyim dedim ama yarıda kaldı. Şimdi sistem veritabanından site url ve siteye ait anahtar kelimeleri çekiyor. daha sonra sorgu yaparak sitenin o anahtar kelimede yerini buluyor ve veritabanına kayı yapıyor.
Ama sorun şu veritabanında kayıtlı olan siteye ait 2'den fazla anahtar kelime varsa yine 1 tane anahtar kelimenin sorgusunu alıyor... Ben bi türlü çözemedim.. Normalde sorunsuz çalışması lazım ve gereksiz bir hata.
Yardım edersenizz sevinirim.. ve ileride r10 paylaşımına sunmayı düşünüyorum..
<?
function getGoogleResults($query, $start) {
$googleurl="http://www.google.com.tr/";
$sesse = urlencode($query);
$urlslist = array();
$googlesearch = "search?q=$sesse&hl=tr&start=$start&sa=N";
$pagesource = curlGetPage($googleurl.$googlesearch, "http://www.google.com.tr/");
$urls = getTags($pagesource, "<li class=g><h3 class=r>", "</a>");
for($i = 0; $i < sizeof($urls); $i++) {
$href = "";
$anchors = getTags($urls[$i], "<a", ">");
$href = getTagField($anchors[0], "href=");
$urlslist[$i] = $href;
}
return $urlslist;
}
function curlGetPage($url, $referer) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS["agent"]);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
if($referer != "") {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
$html = curl_exec($ch);
if(curl_errno($ch)) {
echo curl_error($ch);
$html = "";
}
curl_close ($ch);
return $html;
}
function getTags($source, $start, $end) {
$tmp = $source;
for($i = 0; strlen($tmp) > 0; $i++) {
if(($postagst = strpos($tmp, $start)) == false)
break;
$tmp = substr($tmp, $postagst);
$postagend = strpos($tmp, $end);
if($postagend > 0)
$tags[$i] = substr($tmp, 0, $postagend + strlen($end));
else {
$tags[$i] = $tmp;
}
$tmp = substr($tmp, strlen($tags[$i]));
}
return $tags;
}
function getTagField($tag, $fieldname) {
$field = "";
$ttag = substr($tag, 1, strpos($tag, '>') - 1);
if(($pos = strpos($ttag, $fieldname)) > 0) {
$tmpfield = substr($ttag, $pos + strlen($fieldname));
if($tmpfield[0] == '"' || $tmpfield[0] == "'") {
if($tmpfield[0] == '"') {
$tmpfield = substr($tmpfield, 1);
$field = substr($tmpfield, 0, strpos($tmpfield, '"'));
}
if($tmpfield[0] == "'") {
$tmpfield = substr($tmpfield, 1);
$field = substr($tmpfield, 0, strpos($tmpfield, "'"));
}
}
else {
if(strpos($tmpfield, ' ') > 0)
$field = substr($tmpfield, 0, strpos($tmpfield, ' '));
else
$field = $tmpfield;
}
}
return $field;
}
?>
<?
@$tarih = date("j.n.Y");
$kontrol = mysql_query("select * from site_siralari where tarih = '$tarih' limit 0,01") or die("tarih sorgu hatası");
$tarihsay = mysql_num_rows($kontrol);
if($tarihsay <= 0){
$weburl = mysql_query("select * from kelime_listesi");
while($url_yaz = mysql_fetch_array($weburl)){
$keywords = $url_yaz["kelime"];
$web_sitesi = $url_yaz["websitesi"];
$kullanici_id = $url_yaz["kullanici_id"];
if ($keywords) {
$keyword = explode("\r", ereg_replace("\n","", $keywords));
$siteurl = str_replace("/","",str_replace("www.","",$web_sitesi));
for ($i1=0; $i1<count($keyword); $i1++) {
for($ses = 0; $ses < 100; $ses = $ses + 10) {
$urlslist = array();
$googleurlslist = getGoogleResults($keyword[$i1], $ses);
$urlslist = array_merge($urlslist, $googleurlslist);
for($i = 0; $i < sizeof($urlslist); $i++) {
if (!strpos($urlslist[$i], "interstitial")) {
$googl=parse_url($urlslist[$i]);
}
else
{
$without = str_replace("/interstitial?url=", "", $urlslist[$i]);
$googl=parse_url($without);
}
if ($googl['host']==$web_sitesi || $googl['host']==$siteurl) {
$siteposit = $ses + $i + 1;
$anahtar_kelime = $keyword[$i1] ;
$site = $urlslist[$i];
$sira = $siteposit ;
$kullanici_id = $url_yaz["kullanici_id"];
@$tarih = date("j.n.Y");
$site_kelime_kayit = mysql_query("insert into site_siralari values(null,'$kullanici_id','$site','$anahtar_kelime','$sira','$tarih')");
if($site_kelime_kayit){
echo "Kayıt başarılı<br/>";
}
}
}
}
}
}
}
}
else{
echo "Bu güne Ait istatislik bilgileri Zaten veri tabanımızda Kayıtlıdır.";
}
?>