views:

63

answers:

3

Hello guys,

What I have in mind is this... We are going to have people come from a particular site during a acquisition campaign and was wondering how I could conditionalize a certain section of my site to display a thank you message instead of the sign up form as they would have had the opportunity to fill this out before coming to my landing page.

I have seen solutions like: $referal = mysql_real_escape_string($_SERVER['HTTP_REFERER']);

I would like to know if this is the best way to get this to work???

->>> okay this is what i think might work. The third party website that is referring people to our landing page once the form on that site has been filled out can push into the record a hidden input value of "www.sample.com" or whatever... then I can have something check the for that particular value and fire off the conidtional.

Does that even sound right?

+2  A: 

$_SERVER['HTTP_REFERER'] is the most reliable information you'll get about where your visitor came from. And it's not at all reliable. Some browsers may be configured to not send that header at all, and anybody can send misinformation, claiming they came from http://ultra-secure.top-secret.government.gov/ if they feel so inclined.

With that caution in mind, it sounds like perfect reliability isn't a consideration here, and you're just hoping to save some time for visitors with a correct HTTP_REFERER set.

In that case, comparing the beginning portion of that value to the www.example.com address where you expect visitors to originate with pre-filled-out signup information, would be the best way to go.

Here's an example:

$site = "http://www.sample.com/";
if (!empty($_SERVER['HTTP_REFERER']) &&
        substr($_SERVER['HTTP_REFERER'], 0, strlen($site)) == $site) {
    //if execution reaches this point, user claims he came from www.sample.com
}
VoteyDisciple
I added the example I was writing before you posted your answer. Hope you don't mind.
Artefacto
Okay... in an effort to avoid using HTTP_REFERER can I have them push into my database a value of SOMETHING.When the visitor that has filled out that form submits they get brought to our site. Now the question is can I check if that value is a part of this persons record upon page load?
Matthew
If you're able to work with the other site in collaboration, have them insert a unique ID into your database and then redirect to a script on your site **with that in the URL**. Then it's easy to tell exactly who you're seeing.
VoteyDisciple
@Matthew If the flow is your site -> another site -> your site and you have control over the another site, you create a unique token, forward the user to the other site with that token part of the query string and have the other site pass that token back to you when the user submits the form there (e.g. as part of a 303 forward or, less recommended, with the form action directly your site). You'd have to store the unique token in the database when you generate it and invalidate it once the user returns to your site.
Artefacto
@Artefacto - Okay we have control over the site and the form that these people are coming from. I just need to know if I take the option of passing a value via a hidden input and check for this value upon them being directed to our site once they submit the form is the best and simplest option.If so I was wondering what that syntax would look like. I'm sorry if this is repetitive but it's a little over my knowledge of php and conditionals.
Matthew
@Matthew It's the only way you can guarantee the user came from your site, went to the other, and returned to yours.
Artefacto
+2  A: 

Based on your overall use case, I'd say that the best way to do this is to have the website that's referring to you pass a special POST or GET param, whichever is appropriate.

JSBangs
+1, I agree. If you have control over the referring site, then sending a POST or GET parameter is more reliable than $_SERVER['HTTP_REFERER'].
Steven Oxley
Really, it's indifferent. If the visitor knows which site he's supposed to come from, he might as well add the special GET or POST parameter. If he knows which site he's supposed to come from, but doesn't know the particular page (and therefore doesn't know which param to add), you could match the `$_SERVER['HTTP_REFERER']` against that specific page and you'd have the same level of ... "security".
Artefacto
+1  A: 

If you don't know if it sounds right, you'll have a hard time implementing it.

What you can do is this:

  • Check the referer. It's inside the variable $_SERVER['HTTP_REFERER'], but you don't need a mysql_real_escape string around that just to check if the user comes from a particular site. Note that the referer is basically "user-defined", so you can neither rely on it nor trust it.
  • If they have to fill out a form anyway just add a <input type="hidden" ... Note that this can be faked too.
  • Add a GET parameter and check it with if( isset($_GET['ref']) ) the form would look like this <form action="http://yoursite/register.php?ref" method="POST">.
svens