Solved

PHP coding for Google Search

Posted on 2011-09-05
7
278 Views
Last Modified: 2012-05-12
Hi,

I would like to add a google custom search for the site http://secureinfo.info/ 
I want the search bar to appear in the right corner of the header section.

Attached is the current header.php file. If you need any other php file, please let me know.

Any help is appreciated as i do not know much about any php coding. I have the google code for the search bar and the search result page.

Thanks
header.php
0
Comment
Question by:ujitnos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
ropenner earned 500 total points
ID: 36482890
line 31 and 32 are...

<body <?php body_class(); ?>>

<?php


insert your code for the google search inbetween these two.  If it is PHP code then it is enclosed in <php ?> tags otherwise if it is HTML only then plop it in there.

To position it to the far top right you can use a table to contain it and absolute HTML positioning.  A sample of how it may appear in the header.php file is below... starting at line 31

<body <?php body_class(); ?>>
      <TABLE style="position:absolute; top:0px;right:5px">your stuff</TABLE>
<?php

code below is a working example placed right after the body tag

<html>

<body>

   <TABLE style="position:absolute; top:0px;right:5px">

   	<TR>

   		<TD> 

   			<SCRIPT language=javascript>

   				function addSite() {

   					var query = document.getElementById('q').value;

   					document.location.href="http://google.com/search?q="+query+"+site%3Asecurityinfo.info&hl=en&biw=1208&bih=685&num=10&lr=&ft=i&cr=&safe=images&tbs=";

   					return false;

   				}

				</SCRIPT>

   			<FORM onsubmit="javacript:return addSite();">

		   		<INPUT type=text size=20 id=q name=q>

		   	</FORM>

   		</TD>

   	</TR>

   </TABLE>

</BODY>

</HTML>

Open in new window

0
 
LVL 10

Author Comment

by:ujitnos
ID: 36483228
Ok, please review the page. I need to move it a bit down, in line with the title "Secure Info" How to?

I still not able to produce search results, but i will look into that.

This is what i inserted:-

<TABLE style="position:absolute; right:150px">
<form action="http://secureinfo.info/search-results" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-80feferf823723193:gtfedsgzg3104" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="55" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
</TABLE>
0
 
LVL 10

Author Comment

by:ujitnos
ID: 36483338
Hi, I also noticed that it is not aligned properly in Firefox
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ropenner
ID: 36483378
The form needs to be within a table row and data cell

you need to put
<TABLE>
<TR><TD>

  ... your stuff

</TD></TR>
</TABLE>
  otherwise it pushes the content outside of the table ... then you can play with the alignment

0
 
LVL 10

Author Comment

by:ujitnos
ID: 36483466
Ok, thanks, got that right. Now how do i move it a bit down ?
0
 
LVL 8

Assisted Solution

by:ropenner
ropenner earned 500 total points
ID: 36485253
add to your table's style how far from the TOP of the screen you want it to appear.  It is in the original post's code as well


eg.
style="position:absolute; top:20px; right:50px"
0
 
LVL 10

Author Closing Comment

by:ujitnos
ID: 36500614
Thanks
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question