943,202 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 118
  • PHP RSS
Aug 31st, 2010
0

Show content only to visitors from search engines

Expand Post »
Hi!
I'd like to show the ads on my page only to visitors coming from search engines. I'm looking for a php script that can do the trick - if lucky and I'll find it, I'll integrate it in my page.
If you know of such thing or how to do it, please post it here, I'll highly apreciate it.
Thank you!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
Aug 31st, 2010
0
Re: Show content only to visitors from search engines
Hi wattaman,

You can use the code below, but you will need to add more search engines after the 8th line.

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $refurl = $_SERVER['HTTP_REFERER'];
  3. $refurl = explode("/", $refurl);
  4. $refurl = $refurl[0]."//".$refurl[2];
  5. if ($refurl == www.google.com) echo "Add code here!";
  6. if ($refurl == www.google.co.uk) echo "Add code here!";
  7. if ($refurl == www.bing.com) echo "Add code here!";
  8. ?>

Calum
Reputation Points: 10
Solved Threads: 3
Light Poster
CalumMc is offline Offline
34 posts
since Jul 2010
Aug 31st, 2010
0
Re: Show content only to visitors from search engines
Thanks, Calum, but is not working. No ads (or whatever I insert there) is displayed.
Have no idea why
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
Aug 31st, 2010
0
Re: Show content only to visitors from search engines
What version of google are you using e.g. google.fr / es / co.uk ect if not .co.uk or com you will need to edit it, also some browsers don't send the refer header, try wit a different one.
Is your site in google? because it doesn't work by just going to google and typing the url in the address bar.

hope this works

Calum
Reputation Points: 10
Solved Threads: 3
Light Poster
CalumMc is offline Offline
34 posts
since Jul 2010
Aug 31st, 2010
0
Re: Show content only to visitors from search engines
Nothing works, Calum. The site is in Google and I've checked in IE, FF3 and Chrome browsers. Is it possible to be something wrong with my server?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
Aug 31st, 2010
0
Re: Show content only to visitors from search engines
Also, I'm trying this javascript without succes, too:
PHP Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. var ref = document.referrer;
  3. //you can add more URLs to not show ads, for example you want to block Google and Yahoo images traffic but show to any other Google and Yahoo traffic in
  4. var se = new Array('images.google.','images.yahoo.');
  5. //you can add more search engines below, just follow the same format!
  6. var se2 = new Array('.google.','.yahoo.','.bing.','.ask.','.msn.');
  7. for (var i = 0; i <= se.length-1; i++) {
  8. if (ref.indexOf(se[i])!== -1) {
  9. var expiry = new Date ();
  10. expiry.setTime(expiry.getTime() + 60000);
  11. document.cookie = "sevisitor=1; expires=" + expiry.toGMTString() + "; path=/; ";
  12. }
  13. }
  14. </script>
PHP Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. var results = document.cookie.match ( '(^|;) ?sevisitor=([^;]*)(;|$)' );
  3.  
  4. if(results) {
  5. if (results[2] == 1) {
  6. //if traffic from images.google.com or images.yahoo.com do nothing
  7. //or you can show CPM ads or whatever you want to do.
  8. }
  9. }else {
  10.  
  11. var results2 = document.cookie.match ( '(^|;) ?sevisitor2=([^;]*)(;|$)' );
  12. if(results2) {
  13. if (results2[2] == 1) {
  14. //if traffic coming from google.com ,yahoo.com ,msn.com, bing.com, or ask.com
  15. //IMPORTANT: replace pub-xxxxxxxxxxxxx with your publisher id!
  16. // Also replace yyyyyyyy with your google_ad_slot
  17.  
  18. var gstring="<script type=\"text/javascript\"><!--\n";
  19. gstring+="google_ad_client = \"pub-xxxxxxxxxxxxxxxx\"\n";
  20. gstring+="google_ad_slot = \"yyyyyyyyyyy\";\n";
  21. gstring+="google_ad_width = 336;\n";
  22. gstring+="google_ad_height = 280;\n";
  23. gstring+="//-->\n";
  24. gstring+="<\/script>\n";
  25. gstring+="<script type=\"text/javascript\"\n";
  26. gstring+="src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n";
  27. gstring+="<\/script>\n";
  28. document.write(gstring);
  29. }
  30. }
  31. }
  32. </script>
Borrowed from here.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
Aug 31st, 2010
0
Re: Show content only to visitors from search engines
You may want to redirect people coming from like www.google.com to another page that has the ads using htaccess... just a thought.. maybe a bit painful to implement
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pcalior is offline Offline
8 posts
since Aug 2010
Sep 1st, 2010
0
Re: Show content only to visitors from search engines
Click to Expand / Collapse  Quote originally posted by pcalior ...
You may want to redirect people coming from like www.google.com to another page that has the ads using htaccess... just a thought.. maybe a bit painful to implement
Can do, but I want the same page for everyone, only to hide ads from time to time (or show to some visitors only). Thanks for the suggestion.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: having form data sent to specified e-mail
Next Thread in PHP Forum Timeline: client side and server side





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC