Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
Share
LinkBack Thread Tools
Old 07-21-2012, 10:41 AM   #1
Warrior Member
War Room Member
 
Join Date: May 2012
Posts: 28
Thanks: 0
Thanked 32 Times in 5 Posts
Default PHP Question for PHP Pro

If I use an include function on my index page, which says something like "if user came from ESPN include Sports.php page, else include Music.php page" so the user will stay on the index.php page but what he is shown will be different based on where he came from, is this something that user can identify?
christhurman is offline   Reply With Quote
Old 07-21-2012, 02:58 PM   #2
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 2,406
Thanks: 157
Thanked 1,022 Times in 458 Posts
Default Re: PHP Question for PHP Pro

Only way I know how to do that is by using 'HTTP Referer'. Unfortunately it's not 100% reliable, because not all browsers support it. But it should work for the majority of your visitors.


<?php

$referer = $_SERVER['HTTP_REFERER']; // Get the referring URL and put it in a variable

if(isset($referer)) // Check to make sure that the variable is set
{
$espn = strpos($referer, "espn"); // Search the variable to see if it contains "espn"
if ($espn === true) {
include ('Sports.php'); // If it does, include Sports.php
} else {
include ('Music.php'); // If it doesn't, include Music.php
}
}

?>

Brandon Tanner is online now   Reply With Quote
Old 07-22-2012, 04:17 AM   #3
Warrior Member
 
programming's Avatar
 
Join Date: Jul 2012
Location: Russia
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Contact Info
Send a message via Skype™ to programming
Default Re: PHP Question for PHP Pro

Usually we use this to fool SE spiders. It's called "Cloaking". Check the wikipedia article.
programming is offline   Reply With Quote
Old 07-22-2012, 01:24 PM   #4
DJL
HyperActive Warrior
War Room Member
 
DJL's Avatar
 
Join Date: Jan 2008
Location: , , USA.
Posts: 334
Thanks: 23
Thanked 106 Times in 80 Posts
Default Re: PHP Question for PHP Pro

@Brandon Tanner,
Can you please advise me, what development environment do you recommend for testing such things on my Windows PC before potentially screwing up an active WordPress blog?
DJL is offline   Reply With Quote
Old 07-22-2012, 02:31 PM   #5
HyperActive Warrior
 
Join Date: Jul 2012
Posts: 198
Thanks: 0
Thanked 14 Times in 14 Posts
Default Re: PHP Question for PHP Pro

If you design your site in wordpress then you can do that by adding some plugins.
If you are not using wordprees then you have to that by coding php program.
jaasmit is offline   Reply With Quote
Old 07-22-2012, 02:46 PM   #6
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 2,406
Thanks: 157
Thanked 1,022 Times in 458 Posts
Default Re: PHP Question for PHP Pro

Quote:
Originally Posted by DJL View Post
@Brandon Tanner,
Can you please advise me, what development environment do you recommend for testing such things on my Windows PC before potentially screwing up an active WordPress blog?
Huh?... You don't like screwing up active blogs???

For local testing, I use (and highly recommend) XAMPP. I've never tried to install WP under XAMPP though, as I develop non-WP sites. But I don't see any reason why it wouldn't work.

If you only do WP development, then it might be easier for you to use something like this.

Brandon Tanner is online now   Reply With Quote
Old 07-22-2012, 02:54 PM   #7
DJL
HyperActive Warrior
War Room Member
 
DJL's Avatar
 
Join Date: Jan 2008
Location: , , USA.
Posts: 334
Thanks: 23
Thanked 106 Times in 80 Posts
Default Re: PHP Question for PHP Pro

Thanks, Brandon, I will take a look at InstantWP.
DJL is offline   Reply With Quote
Old 07-22-2012, 04:08 PM   #8
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: Nov 2008
Location: Asheville, NC USA
Posts: 624
Thanks: 33
Thanked 88 Times in 80 Posts
Social Networking View Member's Twitter Profile 
Default Re: PHP Question for PHP Pro

Quote:
Originally Posted by Brandon Tanner View Post
Only way I know how to do that is by using 'HTTP Referer'. Unfortunately it's not 100% reliable, because not all browsers support it.
Actually that's not quite true. All major browsers, including all the mobile browsers, support the HTTP Referer header (yes, the misspelling of referrer is accurate..). The problem is, and why it's not 100% reliable, is that plugins, or even the browser's settings, can allow users to either spoof or turn off the sending of this header. Since it's totally up to the client (browser), whether or not to send it, you can't always count on it. You can, however, count on it to be there for 99% of users, if not more, so it can tell you something. You just need to account for cases where it isn't being sent to the server.

I build web things, server things. I help build the startup Veenome.
wayfarer is offline   Reply With Quote
Old 07-23-2012, 07:51 AM   #9
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 2,406
Thanks: 157
Thanked 1,022 Times in 458 Posts
Default Re: PHP Question for PHP Pro

Quote:
Originally Posted by wayfarer View Post
Actually that's not quite true. All major browsers, including all the mobile browsers, support the HTTP Referer header (yes, the misspelling of referrer is accurate..). The problem is, and why it's not 100% reliable, is that plugins, or even the browser's settings, can allow users to either spoof or turn off the sending of this header. Since it's totally up to the client (browser), whether or not to send it, you can't always count on it. You can, however, count on it to be there for 99% of users, if not more, so it can tell you something. You just need to account for cases where it isn't being sent to the server.
I never said that major browsers don't support it... I said that all browsers don't support it... which is true. But you bring up a good point, that the user can also set their browser to block/hide this info if they want. And this can also be done in many firewall/antivirus programs.

And to the OP: I forgot to mention that 'Http Referer' will only work if the visitor comes to your site via a hyperlink on the referrer's site. If they just type your URL in the address bar or click your link in their 'bookmarks' folder, it won't work. For that reason alone, you're not going to get the referrer info for anywhere near 99% of your visitors. I actually tested this some years ago on one of my sites, and if I recall correctly, it was more in the 60 - 70% range. So just something to keep in mind.

Brandon Tanner is online now   Reply With Quote
Old 07-23-2012, 08:48 AM   #10
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: Nov 2008
Location: Asheville, NC USA
Posts: 624
Thanks: 33
Thanked 88 Times in 80 Posts
Social Networking View Member's Twitter Profile 
Default Re: PHP Question for PHP Pro

Quote:
Originally Posted by Brandon Tanner View Post
If they just type your URL in the address bar or click your link in their 'bookmarks' folder, it won't work. For that reason alone, you're not going to get the referrer info for anywhere near 99% of your visitors.
True, direct referrals won't send a referral no matter what.

I build web things, server things. I help build the startup Veenome.
wayfarer is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Bookmarks

Tags
php, pro, question

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 03:06 AM.