title: Credibility of getting searched keyword in PHP
body: <p>My Goal is to get exact keywords provided to a search engine by which a user has arrived to my webpage.
  i found script to get these keywords from <a href="https://stackoverflow.com/questions/941469/is-it-possible-to-capture-search-term-from-google-search/941515#941515">link</a>.</p>
  
  <pre><code>$referringPage = parse_url( $_SERVER['HTTP_REFERER'] );
  if ( stristr( $referringPage['host'], 'google.' ) )
  {
      parse_str( $referringPage['query'], $queryVars );
      echo $queryVars['q']; // This is the search term used
  }
  </code></pre>
  
  <p>and also found following script from <a href="http://www.electrictoolbox.com/php-keywords-search-engine-referer-url/" rel="nofollow noreferrer">link</a>.</p>
  
  <pre><code>function search_engine_query_string($url = false) {
  
      if(!$url) {
          $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
      }
      if($url == false) {
          return '';
      }
  
      $parts = parse_url($url);
      parse_str($parts['query'], $query);
  
      $search_engines = array(
          'bing' =&gt; 'q',
          'google' =&gt; 'q',
          'yahoo' =&gt; 'p'
      );
  
      preg_match('/(' . implode('|', array_keys($search_engines)) . ')\./', $parts['host'], $matches);
  
      return isset($matches[1]) &amp;&amp; isset($query[$search_engines[$matches[1]]]) ? $query[$search_engines[$matches[1]]] : '';
  
  }
  </code></pre>
  
  <p>My question is that what is the credibility of keywords got by these scripts, either these scripts give exact keywords from user provided to Search engine?</p>