Changing site content depending on where a visitor comes from

[Note: I’m really new to PHP]

If I wanted to display content on a site depending on where a visitor has come from (say a Google ad vs. an industry directory, for example), what’s the best way to do that?

Would I set a cookie and write conditionals based on the information stored in it?

Good tip.

So presumably I’d get the value from $_SERVER[‘HTTP_REFERER’], set it in a cookie so that I could refer to the value for the session, and display my content based on that.

Does that sound right?

To see where you visitor came from you want to inspect

$_SERVER['HTTP_REFERER']

variable.

If you want to continue to customise the content on multiple pages you will need to put something in a cookie. The referrer will change to your own website once they click through to a second page. It needn’t be the whole referrer URL, you could set a flag like adwords/directory/other in the cookie

Thanks for chiming in, gents.

In this case, I do need to present that alternative content as the user moves through the site, as cranial-bore said. So I think the cookie solution is the right one.

I likely didn’t make that entirely clear in my initial post, Alex.

Thanks for the help, you guys.

You don’t need to use a cookie as you don’t need to remember where it came from over multiple pages, you could place the PHP code within the section where the content will appear and either use a require (to grab the content from a file) or call to the database and grab the content (based on the referrer variable). :slight_smile: