有人可以看看这个PHP文件,看看他们是否能发现问题。我很难过

时间:2012-04-20 19:00:07

标签: php

我的主网站在文档的开头引用了这个php文件,就像这个

<?php
include('db.php');
include('func.php');
?>

db.php是一个数据库引用文件,它工作正常。但是,只要我引用func.php,网站就会出现以下错误:

HTTP错误500(内部服务器错误):服务器尝试完成请求时遇到意外情况。

所以我很乐意,如果你看下面的代码,看看你是否能发现会导致这种情况发生的错误。提前谢谢。

<?php
require_once('models.php');
require_once('phpspellcheck/include.js');
$spellcheckObject = new PHPSpellCheck();
$spellcheckObject -> LicenceKey = "TRIAL";
$spellcheckObject -> DictionaryPath = ("phpspellcheck/dictionaries/");
$spellcheckObject -> LoadDictionary("English (International)") ;
$spellcheckObject -> LoadCustomDictionary("custom.txt");

$ckfile = tempnam('/tmp', 'ADCOOK');

//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
    /*$result = mysql_query("SELECT DISTINCT vmake FROM vmake") 
    or die(mysql_error());

      while($tier = mysql_fetch_array( $result )) 

        {
           echo '<option value="'.$tier['vmake'].'">'.$tier['vmake'].'</option>';
        }*/

}

//**************************************
//     First selection results     //
//**************************************
if(isset($_GET['func']) && $_GET['func'] == "vmake") { 
   vmake($_GET['drop_var']); 
}

function vmake($drop_var)
{  
    /*include_once('db.php');
    $result = mysql_query("SELECT * FROM vmake WHERE vmake='$drop_var'") 
    or die(mysql_error());

    echo '
          <option style="width:242" value=" " selected="selected">Model</option>';

           while($drop_2 = mysql_fetch_array( $result )) 
            {
              echo '<option style="width:242" value="'.$drop_2['vmodel'].'">'.$drop_2['vmodel'].'</option>';
            }

*/

}


if(isset($_POST['email'])) {
    // Keep count
    $count = 0;

    // Time to process searches!

    // Is it a familiar zip code?
    if(substr($_POST['zip'], 0, 2) == '45') {
        if($_POST['homesearch'] == true) {
            $count = craigs('http://ogden.craigslist.org/search/sss', $_POST['city'] . ' ' . $_POST['propertytype'], $_POST['pricemin'], $_POST['pricemax']);
        } elseif($_POST['carsearch'] == true) {
            $count = craigs('http://ogden.craigslist.org/search/sss', $_POST['vmake'] . ' ' . $_POST['vmodel'], $_POST['pricemin'], $_POST['pricemax']);
        } else {
            $count = craigs('http://ogden.craigslist.org/search/sss', $_POST['item'], $_POST['pricemin'], $_POST['pricemax']);
        }
    } elseif(substr($_POST['zip'], 0, 2) == '65') {
        if($_POST['homesearch'] == true) {
            $count = craigs('http://boise.craigslist.org/search/sss', $_POST['city'] . ' ' . $_POST['propertytype'], $_POST['pricemin'], $_POST['pricemax']);
        } elseif($_POST['carsearch'] == true) {
            $count = craigs('http://boise.craigslist.org/search/sss', $_POST['vmake'] . ' ' . $_POST['vmodel'], $_POST['pricemin'], $_POST['pricemax']);
        } else {
            $count = craigs('http://boise.craigslist.org/search/sss', $_POST['item'], $_POST['pricemin'], $_POST['pricemax']);
        }
    }
    // Okay, it's neither.
    // Is it a home search?
    elseif(isset($_POST['homesearch']) && $_POST['homesearch'] == true) {
        // First off, let's split up the cities.
        $cities = explode(',', $_POST['city']);

        // Now, let's translate our owner types.
        if($_POST['homeseller'] == 'owner') {
            $homeseller = '1';
        } elseif($_POST['homeseller'] == 'agent') {
            $homeseller = '0';
        } else {
            $homeseller = '';
        }

        // Now, let's translate our apartment types.
        if($_POST['propertytype'] == '') {
            $propertytype = 0;
        } elseif($_POST['propertytype'] == 'apartment') {
            $propertytype = 3;
        } elseif($_POST['propertytype'] == 'singlefamily') {
            $propertytype = 1;
        } elseif($_POST['propertytype'] == 'townhome') {
            $propertytype = 2;
        } elseif($_POST['propertytype'] == 'manufactured') {
            $propertytype = 4;
        } elseif($_POST['propertytype'] == 'horse') {
            $propertytype = 5;
        } elseif($_POST['propertytype'] == 'vacation') {
            $propertytype = 6;
        } elseif($_POST['propertytype'] == 'multi') {
            $propertytype = 7;
        } else {
            $propertytype = '';
        }

        //function house($item = null, $type = 0, $city = null, $state = null, $zip = null, $distance = null, $seller = null, $pricemin = null, $pricemax = null, $minsqft = null, $maxsqft = null, $minacres = null, $maxacres = null, $minbed = null)
        foreach($cities as $city) {
            $count = house($_POST['item'], $propertytype, $_POST['city'], $_POST['state'], $_POST['zip'], $_POST['distance'], $homeseller, $_POST['pricemin'], $_POST['pricemax'], $_POST['minsqfeet'], $_POST['maxsqfeet'], $_POST['minacres'], $_POST['maxacres'], $_POST['minbedrooms']);
        }
    } elseif(isset($_POST['carsearch']) && $_POST['carsearch'] == true) {
        //function car($pricemin, $pricemax, $vmake, $vmodel, $minmileage, $maxmileage, $year, $carseller, $doors)
        $count = car($_POST['pricemin'], $_POST['pricemax'], $_POST['vmake'], $_POST['vmodel'], $_POST['minmileage'], $_POST['maxmileage'], $_POST['year'], $_POST['carseller'], $_POST['doors']);
    } else {
        $count = ksl($_POST['item'], $_POST['zip'], $_POST['distance'], $_POST['pricemin'], $_POST['pricemax']);
    }

    $perDay = round($count/7);

    if ($count > 14) {
        echo "<p>Based on your search criteria, we estimate that you will receive approximately $perDay alerts a day.</p><p>If this is ok, just press SUBMIT. If not, please press edit and be more specific in your search criteria.</p><p><input type=\"submit\" value=\"Submit\" onclick=\"doSubmit()\" /><input type=\"submit\" value=\"Edit\" onclick=\"$('.loading').dialog('destroy')\" /></p>";
    } elseif ($count > 0) {
        doSubmit();
    } else {
        $bad = false;
        $words = explode(" ", $_POST['item']) {
        if(count($words) > 0) {
            foreach($words as $word) {
                if(!$spellcheckObject->SpellCheckWord($word)) { $bad = true; }
            }
        }
        if($bad) {
            echo "<p>Current estimates show no results based on your current criteria.</p><p>Please ensure the all details are accurate before proceeding.</p><p><input type=\"submit\" value=\"Submit\" onclick=\"doSubmit()\" /><input type=\"submit\" value=\"Edit\" onclick=\"$('.loading').dialog('destroy')\" /></p>";
        } else { 
            doSubmit();
        }
    }
}

// curl
function curl($url, $post=false, $cookie=false) {
    global $ckfile;

    $curl_handle = curl_init();

    if($cookie == 'init') {
        curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $ckfile);
    }

    curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $ckfile);
    curl_setopt($curl_handle, CURLOPT_URL, $url);
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

    if($post <> false) {
        curl_setopt($curl_handle, CURLOPT_POST, TRUE);
        curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post['data']);
    }

    $result = curl_exec($curl_handle);
    curl_close($curl_handle);

    return $result;
}

// craigslist
function craigs($url, $item = null, $pricemin = null, $pricemax = null)
{
    $i = 0;

    // http://ogden.craigslist.org/search/sss?query={item}&srchType=A&minAsk={pricemin}&maxAsk={pricemax}
    $result = curl("$url?query=$item&srchType=A&minAsk=$pricemin&maxAsk=$pricemax");

    if(strpos($result, 'Nothing found for that search') === false) {
        preg_match_all('/<p class="row">.*?<\/p>/is', $result, $output, PREG_PATTERN_ORDER);

        $sevenDaysAgo = strtotime('8 days ago');
        $total = 0;

        foreach($output[0] as $out) {
                if($i < 100) {
                        preg_match_all('/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*\d{1,2}/is', $out, $date, PREG_PATTERN_ORDER);

                        foreach($date[0] as $day) {
                                // Total count
                                $total++;

                                // Let's strip extra spaces...
                                $finalDay = preg_replace('/\s\s+/is', ' ', $day);

                                // Let's compare the dates...
                                if ($sevenDaysAgo < strtotime($finalDay)) {
                                        $i++;
                                }
                        }
                }
        }
    } else {
        // Nothing found.
    }

    return $i;
}

// ksl
function ksl($item = null, $zip = null, $distance = null, $pricemin = null, $pricemax = null)
{
    $i = 0;

    // http://www.ksl.com/index.php?nid=231&search=radio&zip=45174&distance=10&min_price=1&max_price=500&addisplay=%5BNOW-7DAYS+TO+NOW%5D&sort=5&nocache=1&viewNumResults=70&sort=5
    $result = curl("http://www.ksl.com/index.php?nid=231&search=$item&zip=$zip&distance=$distance&min_price=$pricemin&max_price=$pricemax&addisplay=%5BNOW-7DAYS+TO+NOW%5D&sort=5&nocache=1&viewNumResults=70&sort=5");

    if(strpos($result, 'There are no listings for this search.') === false) {
        preg_match_all('/<div class="adBox">.*?<\/div>/is', $result, $output, PREG_PATTERN_ORDER);

        $i = count($output[0]);
    } else {
        // Nothing found.
    }

    return $i;
}

// house
function house($item = null, $type = 0, $city = null, $state = null, $zip = null, $distance = null, $seller = null, $pricemin = null, $pricemax = null, $minsqft = null, $maxsqft = null, $minacres = null, $maxacres = null, $minbed = null)
{
    // http://www.ksl.com/index.php?si=5017903&nid=651&city=Salt+Lake+City&zipcode=&distance=&state=&start=&end=25000&keyword=&sellertype=&acresstart=&acresend=&sqftstart=&sqftend=&bedrooms=&type=&homes_search=Search

    $done = false;
    $pid = 1;
    $i = 0;
    $sevenDaysAgo = strtotime('8 days ago');
    $total = 0;

    while(!$done) {
        $result = curl("http://www.ksl.com/index.php?sid=5017903&nid=651&city=$city&zipcode=$zip&distance=$distance&state=$state&start=$pricemin&end=$pricemax&keyword=$item&sellertype=$seller&acresstart=$minacres&acresend=$maxacres&sqftstart=$minsqft&sqftend=$maxsqft&bedrooms=$minbed&type=&homes_search=Search&pid=$pid");

        if(strpos($result, '0 results') === false) {
            preg_match_all('/<div class="postDate">.*?<\/div>/is', $result, $output, PREG_PATTERN_ORDER);

            if(count($output[0] != 0)) {
                foreach($output[0] as $out) {
                    // Check the date on this entry.
                    preg_match_all('/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*\d{1,2}/is', $out, $date, PREG_PATTERN_ORDER);
                    foreach($date[0] as $day) {
                        // Total count
                        $total++;
                        // Let's strip extra spaces...
                        $finalDay = preg_replace('/\s\s+/is', ' ', $day);
                        // Let's compare the dates...
                        if ($sevenDaysAgo < strtotime($finalDay)) {
                            $i++;
                        }
                    }
                }

                if ($i >= 70) {
                    $done = true;
                }

                $pid++;
            } else {
                $done = true;
            }
        } else {
            $done = true;
        }
    }

    return $i;
}

// car search
function car($pricemin, $pricemax, $vmake, $vmodel, $minmileage, $maxmileage, $year, $carseller, $doors)
{
    // Car values
    // $carMake = array(); - This is included in an external file.

    // $carModel = array(); - This is included in an external file.

    $carSeller = array(
                'dealer' => 288110,
                'owner' => 20);

    // Let's setup our post data:
    if(trim($vmake) <> "") {
        $fields['make'][$carMake[$vmake]] = 1;
    }

    if (trim($vmodel) <> "" && $vmodel <> 0) {
        $fields['model'][$carModel[$vmodel]] = 1;
    }

    if ($pricemin <> "") {
        $fields['sell_price'][$pricemin] = 1;
    }

    if ($pricemax <> "") {
        $fields['sell_price'][$pricemax] = 1;
    }

    if ($minmileage <> "") {
        $fields['mileage'][$minmileage] = 1;
    }

    if ($maxmileage <> "") {
        $fields['mileage'][$maxmileage] = 1;
    }

    if(is_array($doors)) {
        foreach($doors as $door) {
            $fields['doors'][$door] = 1;
        }
    }

    if(is_array($year)) {
        foreach($year as $yr) {
            $fields['year'][$yr] = 1;
        }
    }

    if(is_array($carseller)) {
        foreach($carseller as $seller) {
            if($seller == '' || $seller == ' ') { 
                $fields['seller_type']['0'] = 1;
            } else {
                $fields['seller_type'][$carSeller[$seller]] = 1;
            }
        }
    }

    // We need to firstly initiate a cookie. This is done like so.
    curl('http://www.ksl.com/index.php?sid=0&nid=443', false, 'init');

    // Then, we need to set our search values. We can send a post value to do this.

    $data = 'call='.urlencode('save_query').'&sdata='.urlencode(urlencode(serialize($fields))).'&run='.urlencode('resources/community/java/community_rpc.php');

    $post['count'] = 3;
    $post['data'] = $data;

    // Submit our post data...


    $done = false;
    $pid = 0;
    $i = 0;
    $sevenDaysAgo = strtotime('8 days ago');

    while(!$done) {
        // do curl here
        $result = curl("http://www.ksl.com/index.php?sid=0&nid=443&tab=list&pid=$pid", false, true);
        $f = fopen('f.txt', 'w');
        fwrite($f, $result);
        fclose($f);

        if(strpos($result, 'There are no listings for this search.') === false) {
            preg_match_all('/<div class="adTime">.*?<\/div>/is', $result, $output, PREG_PATTERN_ORDER);

            if(count($output[0] != 0)) {
                foreach($output[0] as $out) {
                    // Check the date on this entry.
                    preg_match_all('/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*\d{1,2}/is', $out, $date, PREG_PATTERN_ORDER);

                    foreach($date[0] as $day) {
                        // Let's strip extra spaces...
                        $finalDay = preg_replace('/\s\s+/is', ' ', $day);
                        // Let's compare the dates...
                        if ($sevenDaysAgo < strtotime($finalDay)) {
                            $i++;
                        }
                    }
                }

                if ($i >= 70) {
                    $done = true;
                }

                $pid++;
            } else {
                $done = true;
            }
        } else {
            $done = true;
            // Nothing found.
        }
    }

    return $i;
}

function doSubmit() {
foreach($_POST as $key => $value) {
    // This should trim any extra spaces in addition to any newlines or tabs.
    $_POST[$key] = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $value);
}

$email=$_POST['email'];
$phone=$_POST['phone'];
$item=$_POST['item'];
$pricemin=$_POST['pricemin'];
$pricemax=$_POST['pricemax'];
$zip=$_POST['zip'];
$miles=$_POST['miles'];
$carsearch=$_POST['carsearch'];
$vmake=$_POST['vmake'];
$vmodel=$_POST['vmodel'];
$minmileage=$_POST['minmileage'];
$maxmileage=$_POST['maxmileage'];
$year=$_POST['year'];
$carseller=$_POST['carseller'];
$doors=$_POST['doors'];
$homesearch=$_POST['homesearch'];
$propertytype=$_POST['propertytype'];
$city=$_POST['city'];
$state=$_POST['state'];
$homeseller=$_POST['homeseller'];
$minacres=$_POST['minacres'];
$maxacres=$_POST['maxacres'];
$minsqfeet=$_POST['minsqfeet'];
$maxsqfeet=$_POST['maxsqfeet'];
$minbedrooms=$_POST['minbedrooms'];
$maxbedrooms=$_POST['maxbedrooms'];



// check email & phone validity
if(!preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i", $email) && !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone)) {
    die();
}
$url="id.txt";
$id=file($url);
$next=$id[0]+1;


$fp=fopen("form$next.txt", "a");
$fh=fopen($url, 'w') or die ("cant open file");
$savestring =  $carsearch . "\n" . $homesearch . "\n" . $next . "\n" . $email . "\n" . $phone . "\n" . $item . "\n" . $pricemin . "\n" . $pricemax . "\n"  . $zip . "\n"   . $miles . "\n"   . $vmake . "\n"  . $vmodel . "\n"  . $minmileage . "\n" . $maxmileage . "\n"  . implode(",",$_POST['year']) . "\n" . implode(",",$_POST['carseller']) . "\n" . implode(",",$_POST['doors']) . "\n"  . $propertytype . "\n"  . $city . "\n"  . $state . "\n"  . $homeseller . "\n"  . $minacres . "\n"  . $maxacres . "\n"  . $minsqfeet . "\n"  . $maxsqfeet . "\n"  . $minbedrooms . "\n"  . $maxbedrooms . "\n";
fwrite($fp, $savestring);
fclose($fp);
unlink("id.txt");
$fa=fopen("id.txt", "a");
fwrite($fa, $next);
fclose($fa)


//header("Location:http://www.mywebsite.com/formsubmit.html");
echo "<script type=\"text/javascript\">window.location = \"http://www.mywebsite.com/formsubmit.html"\"</script";
}

unlink($ckfile);
?>

要看的很多,但我在这一点上完全被打败了。再次感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

我认为你需要添加分号。 :)

<?php
  include('db.php')
  include('func.php')
?>

应该成为

<?php
  include('db.php');
  include('func.php');
?>

答案 1 :(得分:1)

这是你的问题:

    $words = explode(" ", $_POST['item']) { 

应该是

    $words = explode(" ", $_POST['item']);