Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: program indeksujacy (prosty lecz ma blad)
Forum PHP.pl > Forum > PHP
szymon1551web
Witam. napisałem program który indeksuje strony dziala wspaniale jak by przymknac oko na jeden maly blad jak na trafi na link i jest on w bazie danych to go zapisze a tak nie powinno byc dla was zawansowanych programistow to bulka z maslem ale ja tego bledu nie moge znalez od 4.5h mecze sie z tym od 11 wiec prosze pomozcie.
  1. <head>
  2. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2" />
  3. </head>
  4. <body>
  5. <?php
  6. $polaczenie = mysql_connect('localhost', 'miltu', '12345') or die("Brak polaczenia: " . mysql_error());
  7. $baza = mysql_select_db('kalorie',$polaczenie) or exit("Nie wybrano bazy, blad: " . mysql_error());
  8.  
  9. $sql="SELECT url FROM szukacz ORDER BY rand() LIMIT 1";
  10. $wynik = mysql_query($sql);
  11. $rekord=mysql_fetch_assoc($wynik);
  12. $url = $rekord['url'];
  13.  
  14. $liczy = "SELECT COUNT(*) as ile FROM szukacz WHERE url = ".$url."";
  15. $result = mysql_query($liczy);
  16. $arr = mysql_fetch_assoc($result);
  17. $tags = get_meta_tags($url);
  18. $content=file_get_contents($url);
  19. preg_match ('/<title>([^>]*)<\/title>/',$content,$title);
  20. preg_match_all('/<a.*href=\"([^\"]*)\".*>(.*)<\/a>/iU', $content, $links);
  21. echo $arr['ile'];
  22.  
  23. $a = iconv("utf-8", "iso-8859-2", $title[1]);
  24. $b = iconv("utf-8", "iso-8859-2", $tags['keywords']);
  25. $c = iconv("utf-8", "iso-8859-2", $tags['description']);
  26.  
  27. function sprawdz($url, $a, $b, $c, $arr) {
  28. if ($arr['url'] < 1) {
  29. //jezeli url nie istnieje robot go doda.
  30. if (!empty($a)) {
  31. if (!empty($c)) {
  32. if (!empty($b)) {
  33. $zapytanie = "INSERT INTO szukacz (url, title, klucz, opis, odslony, klikniecia) VALUES ('".$url."','".$a."','".$b."','".$c."',1,1)";
  34. $wynik = mysql_query($zapytanie) or die (mysql_error());
  35. }
  36. }
  37. }
  38. }
  39. else {
  40. // jezeli url istnieje robot go zaktualizuje.
  41. if (!empty($a)) {
  42. if (!empty($c)) {
  43. $update = "UPDATE szukacz SET 'title' = ".$a." opis = '".$c."' klucz ='".$b."' WHERE url ='".$url."'";
  44. $update_wykonac = mysql_query($update);
  45. }
  46. }
  47. }
  48. }
  49.  
  50. sprawdz($url, $a, $b, $c, $arr);
  51.  
  52. for ($i=1;$i<100;$i+=10) {
  53. $sprawdzenie = substr($links[1][$i],0,11);
  54. $sprawdzenie2 = substr($links[1][$i],0,7);
  55. $linki = $links[1][$i];
  56.  
  57. if ($sprawdzenie == ('http://www.') || $sprawdzenie2 == ('http://')) {
  58. $tags2 = get_meta_tags($linki);
  59. $content2 = file_get_contents($linki);
  60. preg_match ('/<title>([^>]*)<\/title>/',$content2,$title2);
  61. $d = iconv("utf-8", "iso-8859-2", $title2[1]);
  62. $e = iconv("utf-8", "iso-8859-2", $tags2['keywords']);
  63. $f = iconv("utf-8", "iso-8859-2", $tags2['description']);
  64. $liczy2 = "SELECT COUNT(*) as ile FROM szukacz WHERE url = ".$linki."";
  65. $result2 = mysql_query($liczy2);
  66. $arr2 = mysql_fetch_assoc($result2);
  67.  
  68. sprawdz($linki, $d, $e, $f, $arr2);
  69. }
  70.  
  71. else {
  72. $link = $url.$links[1][$i];
  73. $tags3 = get_meta_tags($link);
  74. $content3 = file_get_contents($link);
  75. preg_match ('/<title>([^>]*)<\/title>/',$content3,$title3);
  76. $g = iconv("utf-8", "iso-8859-2", $title3[1]);
  77. $h = iconv("utf-8", "iso-8859-2", $tags3['keywords']);
  78. $j = iconv("utf-8", "iso-8859-2", $tags3['description']);
  79.  
  80. $liczy3 = "SELECT COUNT(*) as ile FROM szukacz WHERE url = ".$link."";
  81. $result3 = mysql_query($liczy3);
  82. $arr3 = mysql_fetch_assoc($result3);
  83.  
  84. sprawdz($link, $g, $h, $j, $arr3);
  85. }
  86. }
  87.  
  88. ?>
  89. </body>
  90. </html>


troche bledow pewnie zawiera
bim2
Jesteś pewien co zwraca $arr3? Bo ja na pierwszy rzut oka widzę że powinno być w
  1. if ($arr['url'] < 1) {

$arr['ile']
Pawel_W
  1. if (!empty($a)) {
  2. if (!empty($c)) {
  3. if (!empty($b)) {


słyszałeś kiedyś o koniunkcji?
szymon1551web
no dobra wszystko ladnie gra url sie nie powtarzaja smile.gif ale linki dziwnie wychodza np http://www.forum.php/index.php?XXX/XXX.php...mp;sads/cos.php a powinno http://www.forum.php/index.php?act=post
  1. <head>
  2. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2" />
  3. </head>
  4. <body>
  5. <?php
  6. $polaczenie = mysql_connect('localhost', 'miltu', '12345') or die("Brak polaczenia: " . mysql_error());
  7. $baza = mysql_select_db('kalorie',$polaczenie) or exit("Nie wybrano bazy, blad: " . mysql_error());
  8.  
  9.  
  10. $sql="SELECT url FROM szukacz ORDER BY rand() LIMIT 1";
  11. $wynik = mysql_query($sql);
  12. $rekord=mysql_fetch_assoc($wynik);
  13. $url = $rekord['url'];
  14.  
  15. function sprawdz($url, $a, $b, $c) {
  16. //liczy ile linkow jest w bazie danych
  17. $result = mysql_query("SELECT COUNT(*) as ile FROM `szukacz` WHERE `url` = '".$url."'");
  18. $arr = mysql_fetch_assoc($result);
  19. if ($arr['ile'] == 1) {
  20.  
  21. if (!empty($a)) {
  22. if (!empty($c)) {
  23. $update = "UPDATE szukacz SET 'title' = ".$a." opis = '".$c."' klucz ='".$b."' WHERE url ='".$url."'";
  24. $update_wykonac = mysql_query($update);
  25. }
  26. }
  27. }
  28.  
  29.  
  30. if ($arr['ile'] <= 0) {
  31.  
  32. //jezeli url nie istnieje robot go doda.
  33. if (!empty($a)) {
  34. if (!empty($c)) {
  35. if (!empty($b)) {
  36. $zapytanie = "INSERT INTO szukacz (url, title, klucz, opis, odslony, klikniecia) VALUES ('".$url."','".$a."','".$b."','".$c."',1,1)";
  37. $wynik = mysql_query($zapytanie) or die (mysql_error());
  38. }
  39. }
  40. }
  41. }
  42. }
  43.  
  44. $tags = get_meta_tags($url);
  45. $content=file_get_contents($url);
  46. preg_match ('/<title>([^>]*)<\/title>/',$content,$title);
  47. preg_match_all('/<a.*href=\"([^\"]*)\".*>(.*)<\/a>/iU', $content, $links);
  48.  
  49. $a = iconv("utf-8", "iso-8859-2", $title[1]);
  50. $b = iconv("utf-8", "iso-8859-2", $tags['keywords']);
  51. $c = iconv("utf-8", "iso-8859-2", $tags['description']);
  52.  
  53. sprawdz($url, $a, $b, $c);
  54.  
  55. foreach($links[1] as $adres) {
  56. $sprawdzenie = substr($adres,0,11);
  57. $sprawdzenie2 = substr($adres,0,7);
  58.  
  59. if ($sprawdzenie == ('http://www.') || $sprawdzenie2 == ('http://')) {
  60. $tags2 = get_meta_tags($adres);
  61. $content2 = file_get_contents($adres);
  62. preg_match ('/<title>([^>]*)<\/title>/',$content2,$title2);
  63. $d = iconv("utf-8", "iso-8859-2", $title2[1]);
  64. $e = iconv("utf-8", "iso-8859-2", $tags2['keywords']);
  65. $f = iconv("utf-8", "iso-8859-2", $tags2['description']);
  66. sprawdz($adres, $d, $e, $f);
  67. unset($tags2, $content2, $adres);
  68.  
  69. }
  70.  
  71.  
  72. // w przeciwnym razie ...
  73. else {
  74. substr($adres,1);
  75. $tags3 = get_meta_tags($url.$adres);
  76. $content3 = file_get_contents($url.$adres);
  77. preg_match ('/<title>([^>]*)<\/title>/',$content3,$title3);
  78. $g = iconv("utf-8", "iso-8859-2", $title3[1]);
  79. $h = iconv("utf-8", "iso-8859-2", $tags3['keywords']);
  80. $j = iconv("utf-8", "iso-8859-2", $tags3['description']);
  81. sprawdz($url.$adres, $g, $h, $j);
  82. unset($tags3, $content3, $adres);
  83.  
  84.  
  85. }
  86.  
  87. }
  88. ?>
  89. <script type="text/javascript">
  90. window.location = "kopia.php"
  91. </script>';"
  92. </body>
  93. </html>
  94.  


up

pomozcie
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.