Recently the major search engines have worked together to help fix one of the biggest problems in SEO, The canonical URL. With this quick fix all you need to do is add a tag to the <head> section of the page and search engines will use this as an anchor to index the page.
since it is still fairly new we don’t know how it will work in the long run and if there are any side effects such as the pagerank not transferring.
The new tag looks like this
<link rel="canonical" href="http://www.open-source-web.com/">
But nothing can be that easy, obviously with a large site you wouldn’t want to write that out for a million pages so here is the PHP code to make it work.
$thispage = "http://www.";
$thispage .= $_SERVER["SERVER_NAME"];
$thispage .= $_SERVER["PHP_SELF"];
if($_SERVER["QUERY_STRING"]){$thispage .= "?".$_SERVER["QUERY_STRING"];}
<link rel="canonical" href="<? echo $thispage;?>">
I use a variation of this code on most websites I have coded as it is versitile and full of uses when working with dynamic content. An example might be reusing the same mail() function for differant forms, you could loop through what is posted to it and print it out in the body of the mail.
The foreach loop will process each of the requests set to the page. The $_REQUEST can be changed to just $_POST to check only posted form data or any other type of request.
The following loop contains a few examples of what you could do with the request once you have it.
foreach ($_REQUEST as $key => $value)
{
$value = mysql_real_escape_string( $value );
$value = addslashes($value);
$value = strip_tags($value);
if($value != ""){$requestnumber ++;}
echo $key. ' - '.$value.'</br>';
}
The idea behind this was to aid design and usability by adding a label inside the input box to give an indication of what it was for. It might not be a search box, maybe you want to add labels for name and address boxes who knows.
Click the input box below and see how the “search” disappears leaving it empty for the user to edit. If the user clicks and clicks off leaving it empty the label will return to “Search”
Here is how it works.
A basic Javascript function to control the input box called “test” This function basicaly says. Check if the box is empty, if it is make it’s value “Search”.
The input box also calls Javascript “onclick” to clear the input and “onblur” to call the function below.
Recent Comments