cURL PHP Внутренняя ошибка, почему? - PullRequest
0 голосов
/ 05 августа 2011

Я работаю над инструментом для извлечения URL-адресов из поисковых запросов Google, которые содержат конкретные URL-адреса. Ввод - это список URL-адресов и целевой URL-адреса, желаемый вывод - это список URL-адресов для объявлений, которые отображаются в результатах поиска в списке, в который включен целевой URL-адрес. Curl используется для получения исходного кода этих поисков.

Действует на http://obsidianpunch.com/Summer, однако, как вы можете видеть, он возвращает внутреннюю ошибку сервера. «Поиски» - это URL-адреса поиска Google, поля ввода прокси-серверов и данные о конкуренции.

К сожалению, GoDaddy не позволяет мне просматривать журналы ошибок, хотя я надеюсь вскоре получить ответ от их службы поддержки ...

Я трижды проверил детали базы данных и ищу ошибки в коде, которые могли бы вызвать эту ошибку.

Разделители для объявлений Google могут быть отключены, но я не ожидаю, что это приведет к пустому результату, а не к ошибке.

Любые предложения обойти этот тупик приветствуются. Спасибо.

<html>
<body>

<?
set_time_limit (0);

$urls=explode("\n", $_POST['url']);

$target=$_Post['target'];

$allurls=count($urls);

//use the new tool box
require "ToolBoxA4.php";

for ( $counter = 0; $counter <= $allurls; $counter++) {


 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$urls[$counter]);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
 curl_setopt ($ch, CURLOPT_HEADER, 1); 
 curl_exec ($ch); 
 $curl_scraped_page=curl_exec($ch); 



//call the new function parseA1
$arrOut = parseA1 ($curl_scraped_page);

//the output is an array with 3 items:  $arrOut[0] is RHS, $arrOut[1] is TOP, $arrOut[2] is NAT
//to look at the RHS

$curl_scraped_page=strtolower($curl_scraped_page);
$haystack=$curl_scraped_page;
if (strlen(strstr($haystack,$target))>0) {



$FileName = abs(rand(0,1000000000000));
$FileHandle = fopen($FileName, 'w') or die("can't open file");
fwrite($FileHandle, $curl_scraped_page);

$hostname="********.hostedresource.com";
$username="*******";
$password="*******";
$dbname="******";
$usertable="*******";

$con=mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname ,$con);

$right = explode(",", $arrOut[0]);
$top = explode(",", $arrOut[1]);

for ( $countforme = 0; $countforme <= 5; $countforme++) {

$topnow=$top[$countforme];

$query = "INSERT INTO ***** (time, ad1) VALUES ('$FileName','$topnow')";
mysql_query($query) or die('Error, insert query failed');

}

for ( $countforme = 0; $countforme <= 15; $countforme++) {

$rightnow = $right[$countforme];


$query = "INSERT INTO ***** (time, ad1) VALUES ('$FileName','$rightnow')";
mysql_query($query) or die('Error, insert query failed');

}

mysql_close($con);

echo 'Done';


fclose($FileHandle);
}
curl_close($ch);

}



?>

</body>
</html>

Это toolboxA4.php, названный выше.

<?php

function strTrim ($strIn, $cutA, $cutB){
    //keeps what is between $cutA and $cutB
    $pieces = explode($cutA, $strIn, 2);
    $str1 = $pieces[1];  //keep everything after cutA 

    $pieces = explode($cutB, $str1, 2);
    $strOut = $pieces[0];  //keep everything before cutB            
    return $strOut;
}

function arrWords ($strIn, $theStart, $theEnd){
    //returns what is between $theStart and $theEnd
    $cutA = $theStart;
    $pieces = explode($cutA, $strIn);
    $pieces[0] = "";  //discard the first piece

    $cutB = $theEnd;
    foreach ($pieces as $key => $value) {
        $arrB = explode($cutB, $value, 2);
        $arrOut[$key] = $arrB[0];  //keep everything before cutB        
    }

    return $arrOut;
}

function arrElems ($strIn, $tag){
    //returns what is between <$tag> and </$tag>
    $cutA = "<$tag>";
    $pieces = explode($cutA, $strIn);
    $pieces[0] = "";  //discard the first piece

Ответы [ 2 ]

1 голос
/ 05 августа 2011

Массив POST чувствителен к регистру, поэтому начните с изменения

$target=$_Post['target']; 
на
$target=$_POST['target'];

Включены ли короткие теги ?

0 голосов
/ 10 августа 2011

суперглобальный $_POST ДОЛЖЕН БЫТЬ ВСЕМ КОПИЯМИ.

http://php.net/manual/en/reserved.variables.post.php

...