The Google "Search Engine Script" Suddenly Fails

Discussion in 'Products & Tools' started by Juan Lucero, Oct 27, 2006.

  1. #1
    I've been using the Google "Search Engine Script" provided by Digital Point for years and I love it! Here's where I found the script: http://www.digitalpoint.com/tools/search/

    As I was updating our web site today, I noticed that the search no longer functioned. It apperars to fail just after the header include and before the fopen() test script. I've included a code snipet and a link to our live site.

    If you've experienced something like this, let me know what I might be doing wrong. Thanks!

    Code Snippet

    include ("header.php"); // Edit this file to make it easy to fit into your site's look and feel

    (code fails here)

    ini_set ("allow_url_fopen", "1");
    if (!ini_get ("allow_url_fopen")) echo '<FONT COLOR=RED><B>Sorry, this PHP configuration does not allow for usage of <A HREF="http://www.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen" TARGET="_blank">fopen()</A>, which is required for this search engine script.</B></FONT><P>';​

    End Code Snippet

    Our live site is here http://www.csufresno.edu/ClassSchedule/ where you see the failure in action. I hope someone has some insight into this. I'm completely out of ideas.

    Thanks!
    Juan
     
    Juan Lucero, Oct 27, 2006 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    On the line that starts with this (in search.php):

    $handle = @fopen
    PHP:
    Remove the "@" from there (that suppresses any potential errors), and see if it throws some sort of error.

    Also, try commenting out the include header line like so:

    // include ("header.php"); // Edit this file to make it easy to fit into your site's look and feel
    PHP:
    That way can make sure it's not something weird going on in the header.php file.

    Also, add this to the beginning of search.php:

    error_reporting(E_ALL);
    PHP:
     
    digitalpoint, Oct 27, 2006 IP
  3. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. I'll try that right away!
     
    Juan Lucero, Nov 1, 2006 IP
  4. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I did as you suggested and recieved a loop error that opened a million windows. :) But when I put back the @ symbol in '$handel = @fopen()' it returned the following error:

    Notice: Undefined index: start in /user/htdocs/classschedule/search/search.php on line 37
    PHP:
    Line 37 reads:
    $start = 0 + $HTTP_GET_VARS['start'];
    PHP:
    I'm not clear on what $HTTP_GET_VARS['start] does. I'm doing a Google search to try and find out. Then maybe I can figure out why this fails.
     
    Juan Lucero, Nov 1, 2006 IP
  5. Mong

    Mong ↓↘→ horsePower

    Messages:
    4,789
    Likes Received:
    734
    Best Answers:
    0
    Trophy Points:
    235
    #5
    It takes value of variable name "start" when form is submitted thru GET action.

    first check if start variable is set or not by using
    isset() function like

    
    If (isset($start))
    {
    $start = 0 + $HTTP_GET_VARS['start'];
    }
    else
    {
    $start = 0 ;
    }
    
    Code (php):
     
    Mong, Nov 1, 2006 IP
  6. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok, that's consistent with what I've read online.

    Since "start" is not passed to this page by the form, then this value does not exist.

    I'm trying your suggestion and it replies:

    Parse error: syntax error, unexpected T_ISSET, expecting '(' in /user/htdocs/classschedule/search/search.php on line 38
    Code (markup):
    Line 38 reads:

    If isset($start) {
          $start = 0 + $HTTP_GET_VARS['start'];
          } else {
          $start = 0 ;
    }
    PHP:
     
    Juan Lucero, Nov 1, 2006 IP
  7. Mong

    Mong ↓↘→ horsePower

    Messages:
    4,789
    Likes Received:
    734
    Best Answers:
    0
    Trophy Points:
    235
    #7
    use above code :)

    means

    replace
    
    $start = 0 + $HTTP_GET_VARS['start']; 
    
    Code (php):
    with above posted code ;)
     
    Mong, Nov 1, 2006 IP
  8. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You're right. I realized my error and replaced the code as you suggested. I am now getting this error message

    Parse error: syntax error, unexpected T_ISSET, expecting '(' in /user/htdocs/classschedule/search/search.php on line 38
    Code (markup):
    Line 38 reads:

    If isset($start) {
          $start = 0 + $HTTP_GET_VARS['start'];
          } else {
          $start = 0 ;
    }
    PHP:
     
    Juan Lucero, Nov 1, 2006 IP
  9. Mong

    Mong ↓↘→ horsePower

    Messages:
    4,789
    Likes Received:
    734
    Best Answers:
    0
    Trophy Points:
    235
    #9
    Ooops my bad i am 87% sleeping :p

    code should be like this
    
       
          If (isset($start)) {   
                $start = 0 + $HTTP_GET_VARS['start'];   
                } else {   
                $start = 0 ;   
          } 
    
    Code (php):
     
    Mong, Nov 1, 2006 IP
  10. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #10
    Try changing this:

    $q = stripslashes ($HTTP_GET_VARS['q']);
    $start = 0 + @$HTTP_GET_VARS['start'];
    PHP:
    To this:

    $q = stripslashes ($_REQUEST['q']);
    $start = 0 + @$_REQUEST['start'];
    PHP:
    I'm thinking your server admin may have changed how PHP is setup maybe...
     
    digitalpoint, Nov 1, 2006 IP
  11. Mong

    Mong ↓↘→ horsePower

    Messages:
    4,789
    Likes Received:
    734
    Best Answers:
    0
    Trophy Points:
    235
    #11
    lol post your search.php code :D
     
    Mong, Nov 1, 2006 IP
  12. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #12
    The Google API servers have been acting weird this morning, so that may be what's going on right now.
     
    digitalpoint, Nov 1, 2006 IP
  13. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    The php is basically unedited except for those items you've suggested in this string.
    
    <?php
    	
    	error_reporting(E_ALL & ~E_NOTICE);
    	// Free script to search your site
    	// Copyright 2004, Digital Point Solutions
    	// version 1.2 - August 2, 2004
    	//
    	// Feel free to format the results however you see fit, the only thing we ask is that you leave a link to us in case others would like to add it to their site.
    	// Links will be checked, and removal of the link could result it your website being blocked from using the service.
    	// Other than that, have fun!  :)   - Shawn
    	
    	// Set your parameters here
    	$key = "DUh5NkpQFHLqH1j4nv+VrtmpDcxCC/RO";			// This is your Google API key, if you don't have one, get one for free at:
    									// https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey
    	
    	$site = "www.csufresno.edu/ClassSchedule/current/";		// This is the site you wish to search within
    									// If Google has you indexed without "www.", don't specify "www." within your site URL.
    									// 'http://' is *not* required in the site variable.
    									// Examples:
    									// www.cnn.com			search within www.cnn.com
    									// www.cnn.com/tech/	search within www.cnn.com/tech/
    									//
    									// You can also leave it blank to search the entire web
    
    	$spelling = 1;					// Change this to 0 if you do not want to check for spelling suggestions
    									// Using this option makes searches twice as long, because it requires 2 queries instead of 1
    	
    	// Colors
    	$color_border = "#000000";
    	$color_title = "#B0B0FF";
    	$color_odd_results = "#DDDDDD";
    	$color_even_results = "#EEEEEE";
    
    
    	$q = stripslashes ($_REQUEST['q']);
    	$start = 0 + $_REQUEST['start'];
    
    	//include ("header.php"); // Edit this file to make it easy to fit into your site's look and feel
    
    	ini_set ("allow_url_fopen", "1");
    	if (!ini_get ("allow_url_fopen")) echo '<FONT COLOR=RED><B>Sorry, this PHP configuration does not allow for usage of <A HREF="http://www.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen" TARGET="_blank">fopen()</A>, which is required for this search engine script.</B></FONT><P>';
    
    	// Let's get the results
    	$handle = fopen ("http://search.digitalpoint.com/?q=" . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start) . "&spell=" . $spelling, "r");
    	while (!feof ($handle) && $handle) {
    		$line .= fgets ($handle, 1024);
    	}
    	fclose($handle);
    		
    	eval ('$urls = ' . $line . ';');
    		
    	echo '<TABLE BGCOLOR=' . $color_border . ' CELLSPACING=1 CELLPADDING=0><TR><TD><TABLE BGCOLOR=' . $color_odd_results . ' border=0 CELLSPACING=0 CELLPADDING=6><TR BGCOLOR=' . $color_title . '><TH COLSPAN=3>';
    	echo '<TABLE border=0 WIDTH=100%><TR><TH WIDTH=80 ALIGN=CENTER VALIGN=MIDDLE><FONT SIZE=-1><A HREF="http://www.digitalpoint.com/tools/search/">Add Search<BR>To Your Site</A></FONT></TH><TH ALIGN=CENTER>';
    	
    	echo '&nbsp;&nbsp;';
    	
    	if ($urls['end'] - $urls['start'] < 9) $urls['results'] = $urls['end'];
    	
    	if ($urls['results'] > 10) {
    
    		if ($start < 40) {
    			$x = 0;
    		} else {
    			$x = round (max (0, min ($start - 40, $urls['results'] - 96) / 10));
    		}
    		for ($i = $x; $i < $x + 10; $i++) {
    			if ($i != round ($start / 10)) {
    				echo '<A HREF="search.php?q=' . urlencode($q) . '&start=' . ($i * 10) . '">' .  ($i + 1) . "</A>&nbsp;&nbsp;";
    			} else {
    				echo ($i + 1) . "&nbsp;&nbsp;";
    			}
    			if (max (10, ($i + 1) * 10) >= $urls['results']) break;
    		}
    
    		echo '<BR>';
    	}
    	
    	echo '<FONT SIZE=+1>Estimated Total Results:  ' . number_format ($urls['results']) . '</FONT>';
    	if ($urls['spelling']) echo '<br><font color="red">Did you mean: <a href="search.php?q=' . urlencode($urls['spelling']) . '">' . $urls['spelling'] . '</a></font>';
    
    	echo '</TH><TH WIDTH=80>&nbsp;</TH></TR></TABLE>';
    
    	$rownum = 1;
    	
    	$start = $urls['start'];
    	if ($urls['error']) {
    		echo "<TR COLSPAN=3><TD><BR><FONT SIZE=-1 COLOR=RED>" . $urls['error'] . "</FONT></TD></TR>";
    	} else {
    	
    		foreach ($urls['urls'] as $key => $url) {
    			$rownum++;
    			echo "<TR";
    			if ($rownum % 2 == 1) echo ' BGCOLOR=' . $color_even_results;
    			echo "><TH ALIGN=RIGHT WIDTH=35>#" . ($key + $start) . ":&nbsp;</TH><TD><A HREF=\"$url\">" . $urls['titles'][$key] . "</A><BR>" . $urls['snippet'][$key] . "<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>$url</B></FONT></TD><TD>&nbsp;&nbsp;&nbsp;</TD></TR>";
    		}
    	}
    	echo '</TABLE></TD></TR></TABLE>';
    
    	include ("footer.php");
    
    ?>
    
    PHP:
     
    Juan Lucero, Nov 1, 2006 IP
  14. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    This is the location of the live script
    "www.csufresno.edu/ClassSchedule/search/test/search.php"
    PHP:
     
    Juan Lucero, Nov 1, 2006 IP
  15. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I don't know. It seems like I've been having the same problem at lease since Thursday of last week.
     
    Juan Lucero, Nov 1, 2006 IP
  16. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #16
    Not really sure to be honest... everything looks okay. You probably are going to need to have someone that has access to your server to debug your setup further. I can't really tell you what's going on since it appears to be something specific to your server setup.
     
    digitalpoint, Nov 1, 2006 IP
  17. Juan Lucero

    Juan Lucero Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Thanks for your help anyway.
     
    Juan Lucero, Nov 2, 2006 IP
  18. ade92uk

    ade92uk Banned

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0