Jump to content

Newbie Needs Some Help


mnybud

Recommended Posts

Hey guys I have this script that will check a sites indexed pages in Google using the Google API.

 

Right now it requires that you enter one domain in a form and hit submit. Is there a way for me to change this so it loads a list of domains from a text file instead? I am guessing yes but I have been having a tough time getting it working right.

 

Here is the working script that is using the form...If anyone could help me out I would REALLY appreciate it :)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Google API DEMO- Number of indexed pages from a site</title>
<META NAME="description" CONTENT=" This demo will output the number of links indexed by Google in a site">
<META NAME="keywords" CONTENT="Google API DEMO">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<!--
***
This simple demo is put together to illustrate the use of Google API (to query the number of indexed pages)
by KC TAN at http://www.kchut.com. No linkback is required but would appreciate if the publisher
can leave this notice intact. Thank you.
***
-->

</head>

<body>

<?php // include the nusoap class, can be downloaded from http://sourceforge.net/projects/nusoap/	  
  require_once('lib/nusoap.php');

if(isset($_POST['submit'])) {
     
  //trim the user's url
  $qurl=trim($_POST['url']);  
  
  $mq='site:'.$qurl;
   
   $parameters = array(
'key'=> 'Your Google API Key',
'q'=> $mq,
'start'=> '0',
'maxResults'=>'10',
'filter'=> 'false',
'restrict'=>'',
'safeSearch'=>'false',
'lr'=>'',
'ie'=>'',
'oe'=>''
);

//Create a new soap client, feeding it googlesearch.wsdl
$soapclient=new soapclient('http://api.google.com/GoogleSearch.wsdl','wsdl');

//save the results into $results array
$results = $soapclient->call('doGoogleSearch',$parameters);   

//save the total number of pages indexed 
$no_pages=$results['estimatedTotalResultsCount'];

// test if any results were returned		
    if(is_array($results['resultElements'])) $enable=1;			
    else $enable=2;   
} 
?>

<div align="center">	
<form name="demoform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr><td>Site URL:</td><td><input type="text" name="url" size='45' value="<?php echo $_POST['url']; ?>">
(Eg. http://www.useseo.com)</td></tr>
<tr align="center"><td colspan="2"><input type="submit" name="submit" value="Search"></td></tr></table>
</form>

<?php 
if($enable==1) echo'<p style="margin-top:15px;">Google has indexed <b>'.number_format($no_pages).'</b> pages from the above domain.</p>';
elseif ($enable==2) echo'<p style="margin-top:10px;color:red;">There are no results returned.</p>';
?>

</body>
</html>

Link to comment
Share on other sites


if(is_array($results['resultElements'])) $enable=1;
else $enable=2;

// should be

if(is_array($results['resultElements'])) {
    $enable=1;
} else {
   $enable=2;
}

// or if you want to keep short form

if(is_array($results['resultElements'])):
    $enable=1;
else:
    $enable=2;

// but it can be that it is interpreted the wrong way

Link to comment
Share on other sites

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.