Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How do I call different forms depending on referer? (PHP)
I would like to show my readers coming from other sites (like Google, Yahoo, and so on) a big adsense-block, whereas the ones typing in my url michaelsremarks.org should just see a small adsense-block.
I found this script and modified it to my needs, but since I have really no idea of php, any help would be appreciated. I would like to turn this script around, so that the condition is: If someone comes from my own site, he/she sees the small adsense-block, else the big one.
How can I do this?
Here is the code I use until now:
if
(
strpos (getenv ("HTTP_REFERER") , "google") ||
strpos (getenv ("HTTP_REFERER") , "yahoo") &&
strpos (getenv ("HTTP_REFERER") , "q")
)
{
echo '<txp:output_form form="adsense_336x280" />';
}
else
{
echo '<txp:output_form form="adsense_234x60" />';
}
Offline
Re: How do I call different forms depending on referer? (PHP)
Put this in your page template and give it a shot:
<txp:php>if(strpos($_SERVER["HTTP_REFERER"], "google") || strpos($_SERVER["HTTP_REFERER"], "yahoo"))
{ echo '<txp:output_form form="adsense_336x280" />'; } else { echo '<txp:output_form form="adsense_234x60" />'; }</txp:php>
Last edited by Walker (2007-01-14 15:25:06)
Offline
Re: How do I call different forms depending on referer? (PHP)
Works fine, thanks a lot!
— but —
Is it somehow possible to do the structure like this:
if not
michaelsremarks.org, display big adsense
else
display small adsense
Is it possible?
M.
Offline
Re: How do I call different forms depending on referer? (PHP)
<txp:php>if(strpos($_SERVER["HTTP_REFERER"], "michaelsremarks"))
{ echo '<txp:output_form form="adsense_234x60" />'; } else { echo '<txp:output_form form="adsense_336x280" />'; }</txp:php>
Offline
Re: How do I call different forms depending on referer? (PHP)
That’s it! Thanks so much, Walker!
Offline
#6 2015-07-11 22:30:09
- dwisatria
- New Member
- Registered: 2015-07-11
- Posts: 2
Re: How do I call different forms depending on referer? (PHP)
Hi,
I use the above code to prevent one particular section to have access from anywhere unless from confirming page.
but i still have an error like this: Parse error: syntax error, unexpected ‘:’, expecting ‘,’ or ‘;’ in /home/ingapekc/public_html/textpattern/publish/taghandlers.php(3836) : eval()’d code on line 20
what I did is like this
<txp:php>if(strpos($_SERVER[“HTTP_REFERER”], “/spymap/”))
{ echo ‘
…..
entire body is here
…..
‘; }
else
{header(“Location: index.php”);}
</txp:php>
spymap is the directory from where the section get the access. Other than that will be redirected to home.
Offline
#7 2015-07-11 23:43:30
- dwisatria
- New Member
- Registered: 2015-07-11
- Posts: 2
Re: How do I call different forms depending on referer? (PHP)
never mind somehow i figure it out how to make it work.
What I did is just move the whole body into form named support
Here’s the code I use
<txp:php>if(strpos($_SERVER[“HTTP_REFERER”], “/spymap/”))
{echo ‘<txp:output_form form=“support” />’;}
else
header(“Location: ../index.php”);
</txp:php>
Magically, the code is working, although I have no idea what is the different.
Offline
Re: How do I call different forms depending on referer? (PHP)
dwisatria wrote #293090:
{echo '<txp:output_form form="support" />';}
You are relying on the secondpass
here, which might give unexpected results, or simply break one day. Either replace it with
{echo parse('<txp:output_form form="support" />');}
or go txp-way:
<txp:etc_query globals="_SERVER" sanitize="_SERVER" query="not(contains('{?HTTP_REFERER}', '/spymap/'))">
{$header(Location: ../index.php)}
<txp:else />
<txp:output_form form="support" />
<!-- or entire body -->
</txp:etc_query>
Offline