Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-01-14 08:58:04

Michael
Member
From: Vienna/Austria
Registered: 2004-03-25
Posts: 147
Website

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

#2 2007-01-14 15:24:56

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

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

#3 2007-01-14 15:34:28

Michael
Member
From: Vienna/Austria
Registered: 2004-03-25
Posts: 147
Website

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

#4 2007-01-14 16:12:40

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

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

#5 2007-01-14 22:17:06

Michael
Member
From: Vienna/Austria
Registered: 2004-03-25
Posts: 147
Website

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

#8 2015-07-12 07:51:54

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

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

Board footer

Powered by FluxBB