Jump to content

Recommended Posts

these are the 3 looped errors that come up in my error_log

 

[04-Nov-2009 15:33:22] PHP Warning:  fopen() expects at least 2 parameters, 1 given in /home/jnero/public_html/mydomainpagerank.com/search2/querygoogle.php on line 19
[04-Nov-2009 15:33:22] PHP Warning:  feof(): supplied argument is not a valid stream resource in /home/jnero/public_html/mydomainpagerank.com/search2/querygoogle.php on line 20
[04-Nov-2009 15:33:22] PHP Warning:  fread(): supplied argument is not a valid stream resource in /home/jnero/public_html/mydomainpagerank.com/search2/querygoogle.php on line 21


 

the error_log is here:

http://mydomainpagerank.com/search2/error_log

 

here is the pages that i have:

 

 

index.php:

<?php
include('config.php');
if(isset($_GET['q'])) {

$query = $_GET['q'];
$query = str_replace(" ","+",$query);
$murl = "http://mydomainpagerank.com/search2/index.php?searhquery=$query";
header('Location: ' . $murl);

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Custom Google Search Page</title>
<meta name="description" content="Custom Google Search Page" />
<meta name="keywords" content="custom, google, search, page" />
<script type="text/javascript" src="includes/js.php"></script>
<link href="images/home.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
    <link href="images/ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<style type="text/css">

.searchresult
{
padding: 1.5em 0;
border-bottom: 1px solid #333;
}

.searchresult h3, .searchresult p
{
margin: 0;
}

.searchresult h3 a
{
font: italic 1em Georgia, serif;
color: #f30;
border-bottom: 1px solid #900;
text-decoration: none;
font-weight: bold;
font-size: 1em;
}

.searchresult .resultdesc b
{
color: #fff;
}

.searchresult .resulturl
{
color: #666;
font-size: .75em;
}

</style>
</head>
<body>
<div id="wrapper">
<div id="bg_t"> </div>
    <div id="bg_c">
    	<div id="logo">
		<a href="./index.php"><img src="./images/logo.png" border="0"></a>
        </div>
	<form method="get" action="querygoogle.php">    
        <div id="search">Search this site<input type="text" maxlength="255" title="Enter your keywords and click the search button" name="searchquery" /></label>

        </div>
        
        <div id="buttom">
            <input type="submit" value="Search" />
		</form>
        </div>
        </form>
	<br><br>
	                <?php
if(!empty($_SESSION['googleresults']))
{
echo $_SESSION['googleresults'];
unset($_SESSION['googleresults']);
}
?>
        <div id="newkey">
        	<div class="searchnew">
		<?php 
include('tag_cloud.php'); 

print tag_cloud();
?>
			<br clear="all" />                
            </div>
            <div class="searchnew_b">  </div>
        </div>
    </div>
    <div id="bg_b"> </div>
    <div id="footer">
    	Copyright © 2009 by <strong>Domain.com</strong>. All rights reserved - Script by: <a href="http://prophpdev.net/"><strong>ProPHPDev.net</strong></a>
    </div>
</div>
</body>
</html>

 

querygoogle.php:

<?php
session_start();

if(isset($_GET['searchquery'])) {

$searchquery = $_GET['searchquery'];
$searchquery = str_replace(" ","+",$searchquery);

// if you use an Mike Migurski's JSON library, include it like I did
require_once('JSON.phps');

// Here's the Google AJAX Search API url for curl. It uses Google Search's site:www.yourdomain.com syntax to search in a specific site. I used $_SERVER['HTTP_HOST'] to find my domain automatically. Change $_POST['searchquery'] to your posted search query

$handler = "'http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&q=$searchquery', 'rb'";
$url ="http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&q=$searchquery";

// use fopen and fread to pull Google's search results

$handle = fopen($handler);
while(!feof($handle)) {
$body .= fread($handle, 8192);
}

fclose($handle);

// now $body is the JSON encoded results. We need to decode them.

$json = new Services_JSON();
$json = $json->decode($body);

// now $json is an object of Google's search results and we need to iterate through it.

foreach($json->responseData->results as $searchresult)
{
if($searchresult->GsearchResultClass == 'GwebSearch')
{
$formattedresults .= '
<div class="searchresult">
<h3><a href="' . $searchresult->unescapedUrl . '">' . $searchresult->titleNoFormatting . '</a></h3>
<p class="resultdesc">' . $searchresult->content . '</p>
<p class="resulturl">' . $searchresult->visibleUrl . '</p>
</div>';
}
}

$query = $_GET['searchquery'];
$query = str_replace(" ","+",$query);
$murl = "http://mydomainpagerank.com/search2/index.php?search=$query";
$_SESSION['googleresults'] = $formattedresults;
header('Location: ' . $murl);
exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/180345-solved-help-with-infinite-loop-error/
Share on other sites

ok i changed the code around but still get this errror:

 

[04-Nov-2009 15:46:18] PHP Warning:  fread(): supplied argument is not a valid stream resource in /home/jnero/public_html/querygoogle.php on line 20

and the error just loops

 

this is the new code:

querygoogle.php:

<?php
session_start();

if(isset($_GET['searchquery'])) {

$searchquery = $_GET['searchquery'];
$searchquery = str_replace(" ","+",$searchquery);

// if you use an Mike Migurski's JSON library, include it like I did
require_once('JSON.phps');

// Here's the Google AJAX Search API url for curl. It uses Google Search's site:www.yourdomain.com syntax to search in a specific site. I used $_SERVER['HTTP_HOST'] to find my domain automatically. Change $_POST['searchquery'] to your posted search query

$url ="http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&q=$searchquery";

// use fopen and fread to pull Google's search results

$handle = fopen("$url", "rb");
while(!feof($handle)) {
$body .= fread("$handle", "8192");
}
fclose($handle);

// now $body is the JSON encoded results. We need to decode them.

$json = new Services_JSON();
$json = $json->decode($body);

// now $json is an object of Google's search results and we need to iterate through it.

foreach($json->responseData->results as $searchresult)
{
if($searchresult->GsearchResultClass == 'GwebSearch')
{
$formattedresults .= '
<div class="searchresult">
<h3><a href="' . $searchresult->unescapedUrl . '">' . $searchresult->titleNoFormatting . '</a></h3>
<p class="resultdesc">' . $searchresult->content . '</p>
<p class="resulturl">' . $searchresult->visibleUrl . '</p>
</div>';
}
}

$query = $_GET['searchquery'];
$query = str_replace(" ","+",$query);
$murl = "http://mydomainpagerank.com/search2/index.php?search=$query";
$_SESSION['googleresults'] = $formattedresults;
header('Location: ' . $murl);
exit;
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.