PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I manage several domains, most with highly ranked .html landing pages in Google, which when the form is submitted a .php file is called which performs very basic validation , + fires an email to me and my client. I would love to add at the bottom information about the referring domain / keyword used and maybe the IP..
I have found some code for the landing page, but I don't know if I can just insert it into the .html code, and where, aobove the DOCTYPE, or in the head, or body.
I don't know whether I should change the file extension of the .html files to .php, because then the SEO ranked pages wont be loaded/work until they are re-indexed.
< ?php
session_start();
if(!isset($_SESSION[’referrer’])){
//get the referrer
if ($_SERVER[’HTTP_REFERER’]){
$referrer = $_SERVER[’HTTP_REFERER’];
}else{
$referrer = “unknown”;
}
//save it in a session
$_SESSION[’referrer’] = $referrer; // store session data
}
?>
Then on the .php email/form file I could insert this
session_start();
echo “referrer = “. $_SESSION[’referrer’]; //retrieve data
?>
markandcha wrote:Can I still use this code at the top of a html page...?
No, the page must have a .php extension and your webserver must parse php files.
Other than that, you can place your PHP code anywhere inside the file, since it doesnt produce output. If your code DOES produce output, then you want to place it within the <BODY> of the page.
i found this code on the net, not quite sure on how to integrate/call it though
PHP function to get search query
function get_search_phrase($referer){
$key_start = 0;
$search_phrase = "";
// used by dogpile, excite, webcrawler, metacrawler
if (strpos($referer, '/search/web/') !== false) $key_start = strpos($referer, '/search/web/') + 12;
// used by chubba
if (strpos($referer, 'arg=') !== false) $key_start = strpos($referer, 'arg=') + 4;
// used by dmoz
if (strpos($referer, 'search=') !== false) $key_start = strpos($referer, 'query=') + 7;
// used by looksmart
if (strpos($referer, 'qt=') !== false) $key_start = strpos($referer, 'qt=') + 3;
// used by scrub the web
if (strpos($referer, 'keyword=') !== false) $key_start = strpos($referer, 'keyword=') + 8;
// used by overture, hogsearch
if (strpos($referer, 'keywords=') !== false) $key_start = strpos($referer, 'keywords=') + 9;
// used by mamma, lycos, kanoodle, snap, whatuseek
if (strpos($referer, 'query=') !== false) $key_start = strpos($referer, 'query=') + 6;
// don't allow encrypted key words by aol
if (strpos($referer, 'encquery=') !== false) $key_start = 0;
// used by ixquick
if (strpos($referer, '&query=') !== false) $key_start = strpos($referer, '&query=') + 7;
// used by aol
if (strpos($referer, 'qry=') !== false) $key_start = strpos($referer, 'qry=') + 4;
// used by yahoo, hotbot
if (strpos($referer, 'p=') !== false) $key_start = strpos($referer, 'p=') + 2;
// used by google, msn, alta vista, ask jeeves, all the web, teoma, wisenut, search.com
if (strpos($referer, 'q=') !== false) $key_start = strpos($referer, 'q=') + 2;
// if present, get the search phrase from the referer
if ($key_start > 0){
if (strpos($referer, '&', $key_start) !== false){
$search_phrase = substr($referer, $key_start, (strpos($referer, '&', $key_start) - $key_start));