Solved

PHP coding for Google Search

Posted on 2011-09-05
7
257 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

816 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now