I hope I'm asking in correct area if I wanted to display certain content to people being referred by search engines is that possible? Then visitors coming from direct type in would be shown different content. If its possible would someone be willing to explain how to achieve this or what I need to search for to find out more information on it.
hello here is a lite example <?php // GET REFERER $refer_parts = parse_url($_SERVER['HTTP_REFERER']); // for google you change to how engines you like if(eregi('google.',$refer_parts['host'])) { echo "visitor comming from google"; } ?> Best
Here's a bit more of a full example ... <?php /** * Gonne cheat and set the referer to test, you won't do this ... */ $_SERVER['HTTP_REFERER'] = "http://www.google.co.uk/search?client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&channel=s&hl=en&q=google.com&meta=&btnG=Google+Search"; /** * SearchDetails * Attempt to discover the search engine and keyword used by current user */ final class SearchDetails { /** * The engine that made the search * * @var string * @access protected */ protected $engine ; /** * The keyword the engine searched for * * @var string * @access protected */ protected $keyword ; /** * The _REQUEST vars from the referer * * @var array * @access protected */ protected $request ; /** * The parsed referer URL * * @var array * @access protected */ protected $parsed ; /** * Construct a new object of type SearchDetails * * @access public */ public function __construct( ) { if( ( $this->parsed = parse_url( $_SERVER['HTTP_REFERER'] ) ) ) { foreach( split( '&', $this->parsed['query'] ) as $part ) { if( list( $key, $value ) = explode( '=', $part ) ) { $this->request[$key] = urldecode( $value ); } } } } /** * Attempt to recover details from object data * * @return bool * @access public */ public function getDetails( ) { if( ( $this->engine = @preg_replace( '~^www\.~s', '', $this->getParsed( 'host' ) ) ) ) { switch( $this->getEngine( ) ) { case 'altavista.com': case 'google.co.jp': case 'google.com': case 'search.msn.co.uk': case 'google.co.uk': case 'search.msn.com': return ( $this->keyword = $this->getRequest( 'q' ) ); break; case 'search.yahoo.com' : case 'uk.search.yahoo.com' : return ( $this->keyword = $this->getRequest( 'p' ) ); break; } } } /** * Attempt to retrieve the engine name from object data * * @return string * @access public */ public function getEngine( ) { return $this->engine ; } /** * Attempt to retrieve the keyword used from object data * * @return string * @access public */ public function getKeyword( ) { return $this->keyword; } /** * Retrieve some or all of the parsed request data * * @return array|string * @param null|string $member * @access public */ public function getRequest( $member = null ) { return is_null( $member ) ? $this->request : $this->request[$member]; } /** * Retrieve some or all of the parsed url data * * @return array|string * @param null|string $member * @access public */ public function getParsed( $member = null ) { return is_null( $member ) ? $this->parsed : $this->parsed[$member]; } } /** * Create a new Object of Class SearchDetails */ $Search = new SearchDetails( ); /** * Attempt to retrieve search data from object */ if( $Search->getDetails( ) ) { /** * There are search details available */ printf( "Engine: %s\r\n", $Search->getEngine( ) ); printf( "Keyword: %s\r\n", $Search->getKeyword( ) ); } /** no search data detected in referer **/ ?> PHP: I don't know all the search engine and their url format, you'll need to do some homework and change the main switch there in getDetails ...
This is working almost perfect. <?php // GET REFERER $refer_parts = parse_url($_SERVER['HTTP_REFERER']); // for google you change to how engines you like if(eregi('google.',$refer_parts['host'])) { echo "visitor comming from google"; } ?> PHP: How would I add a else or if to it so if the visitor came from another location it would show a different text? Also can I add this three times to one page? or would I only need to add a part of the code for the other 2 times I add it?