2

I've signed up to one of those affiliate sites to help drive traffic to my online store. They've asked that I hide the telephone number on my site for referring traffic.

All traffic that they refer will append any of my site urls with something like '?affiliate'.

Does anyone know how I can hide content on a page if a URL contains '?affiliate' but show it if the URL does not contain this text?

I'm using the Magento system, in case that makes a difference. :D

Thanks, Neil

3 Answers 3

6
if (!array_key_exists('affiliate', $_GET)) {
    //show telephone number
}

empty will fail here because the value of $_GET['affiliate'] will be "".

Sign up to request clarification or add additional context in comments.

2 Comments

Hey, I've tried using this as follows. But it always shows the number. I need it to show the number by default, unless the url contains affiliate. if (!array_key_exists('affiliate', $_GET)) { echo "<p>020 XXXXXX</p>"; }
@Neil WHat you did was correct. Maybe the query string is malformed, e.g. the url already contained a query string and the affiliate added "?affiliate" instead of "&affiliate"?
1
<?php
if (isset($_GET['affiliate'])) {
    // don't show
}
else {
    // show telephone number
}
?>

Comments

1

Try something like:

if (isset($_GET['affiliate']))
{
  // hide the content now
}

4 Comments

I think this will fail: The manual on isset() says "Determine if a variable is set and is not NULL." affiliate will be null in this case.
@Pekka I was actually wrong there. It will be "". This is also correct.
@Artefacto you're right, isset() indeed works. I stand corrected!
@Pekka I actually was induced in error with a phpinfo page, which showed "no value", which I assumed mean NULL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.