Jump to content

find refferer


jwk811

Recommended Posts

Er. Well. There's no magical variable to give you the keywords.

 

But lets say they were brought to your site from google. Then the referrer url ($_SERVER['HTTP_REFERER']) may look like this:

 

http://www.google.ca/search?q=keyword+keyword&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a

 

Now if you can write some PHP to cut the query string down just to show this

 

q=keyword+keyword

 

Then there you go. The keywords.

 

EDIT: However, this is only assuming that they DID come straight from the search engine. And other search engine's querystrings may be different!

Link to comment
Share on other sites

i see.. how could i take the q variable's contents though? so i can make it separated from the whole address?

 

 

Hmm, lets see...

 

<?php

$url = "http://www.google.ca/search?q=keyword+keyword&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a";

        // I basically tell $new_url to equal $url from the first = sign to the first &. Usually
        // the keywords are the first variables in the query string
$new_url = substr(
	$url,
	strpos($url, '=')+1,
	(strpos($url, '&') - strpos($url, 'q=')-2)
);
// now: keyword+keyword

$keywords_array = explode('+', $new_url);
        // now: $keywords_array[0] and $keywords_array[1] = 'keyword'

?>

 

Now the two keywords are in $keywords_array. However, I'm not sure if I did this the best way. Give me a minute or two to check it out.

 

But it works, at least for google.

 

EDIT: Changed the code a bit.

 

Ok, there, that should work. But only assuming for google. For yahoo it's ...p=keyword+keyword...

 

Actually. To be compatible with more browsers, maybe:

 

<?php

$url = "http://www.google.ca/search?q=keyword+keyword&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a";

$new_url = substr( $url, strpos($url, '=')+1, (strpos($url, '&')-strpos($url, 'q=')-2) );

$keywords_array = explode('+', $new_url);

?>

 

Hmm, that may work for more search engines.

Link to comment
Share on other sites

Sorry, ended up copying and pasting my second example into the first, couldn't modify after (modify time limit expired).

 

They are both the same. Just one with notes, one without.

 

also would any of you know how to get the host name, country, langauge, state, city? my old chat software had this but now its only available for those who upgrade.. and id rather build my own not use any analytics

 

There's a way, forgot what it was called off the top of my head. Geoprogramming? Something similar, but basically you use the person's IP to locate them (at least down to country or state), not sure about city. But, can't help you there, i haven't a clue how they do it without straight-off just asking the user "where are you?" lol.

 

Doing it automatically has its drawbacks, the IP could be faked. But then again, if you ask them where they are, that's no better. lol.

 

But to pull it off you have to perform some math formula on the IP and it gets you a country code or something.

 

 

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.