Search engine script errors

Discussion in 'PHP' started by toppin1, Dec 21, 2005.

  1. #1
    I just added the site search engine script to my website. When I search it returns the following errors:


    Warning: feof(): supplied argument is not a valid stream resource in /home/u2/burlocrc/html/search.php on line 45

    Warning: fclose(): supplied argument is not a valid stream resource in /home/u2/burlocrc/html/search.php on line 48

    Parse error: parse error, unexpected ';' in /home/u2/burlocrc/html/search.php(50) : eval()'d code on line 1


    I changed only the basic required fields, and followed instructions carefully. I don't know PHP. Can anyone help me?
     
    toppin1, Dec 21, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    maybe there is a firewall or something stopping you connecting to the file?
     
    dave487, Dec 22, 2005 IP
  3. toppin1

    toppin1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I discovered another thread dealing with the same problems, so I followed the suggestion and removed the @ in fopen to show the errors. The error message it returned is this (with site & key removed):

    Warning: fopen(http://search.digitalpoint.com/?q=test&key=**********&site=**********&start=0&spell=1): failed to open stream: Permission denied in /home/u2/burlocrc/html/search.php on line 44

    How can I find out why permission is denied, and what can I do to fix it? Does it still look like a firewall?
     
    toppin1, Dec 22, 2005 IP
  4. cornelius

    cornelius Peon

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    wait wait a second

    u are trying to open http://search.digitalpoint.com/

    which is obviously on different server to yours


    YOU CANNOT OPEN PAGES OUTSIDE YOUR SERVER IN THIS WAY

    no wonder u getting permission denied, php doesnt work in this way

    also post the whole code here and be more detailed
     
    cornelius, Dec 22, 2005 IP
  5. toppin1

    toppin1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I see what you're saying, but this is a script I downloaded off this site (http://www.digitalpoint.com/tools/search/), and I believe I'm using it as intended. Here's the whole script:

    <?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 = "*************";			// 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.burlingtonocrc.com";		// 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 = "black";
    	$color_title = "FFFFD2";
    	$color_odd_results = "#CCCCCC";
    	$color_even_results = "#FFFFFF";
    
    
    	$q = stripslashes ($HTTP_GET_VARS['q']);
    	$start = 0 + $HTTP_GET_VARS['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 width=700 align="center" BGCOLOR=' . $color_border . ' CELLSPACING=1 CELLPADDING=0>
    	<TR><TD><TABLE width=700 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 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></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");
    
    ?>
    Code (markup):
     
    toppin1, Dec 22, 2005 IP
  6. cornelius

    cornelius Peon

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i see sorry :)

    anyways
    Parse error: parse error, unexpected ';' in /home/u2/burlocrc/html/search.php(50) : eval()'d code on line 1

    means u have extra ; somewhere around line 50

    the other errors are because the parameters are wrong going into them functions
     
    cornelius, Dec 22, 2005 IP
  7. toppin1

    toppin1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    line 50 is "eval ('$urls = ' . $line . ';');".

    I guess what I don't understand is that many others have used this script as is, and I followed directions exactly in entering the necessary things, so why would it not work for me?
     
    toppin1, Dec 22, 2005 IP