PDA

View Full Version : How to manage a visitor redirect?


vbplusme
05-01-2010, 01:05 PM
First the goal: I am trying to redirect a visitor to my registration page after they have been browsing my site for some time.

Here id the code that sort of works:

<vb:if condition="$bbuserinfo['userid'] == 0">
<meta HTTP-EQUIV="REFRESH" content="30; url=http://mysite.com/register.php">
</vb:if>
I included this call with the other meta tags at the top of includeheader template.

It looked like it does exactly what I expected, at first.

I then noticed that when I was in the registration form that it refreshed because that same code is in its header as well.

How can I get either to not put the refresh code in the registration form or add a conditional that detects that its in the form and does not do the refresh?

I was thinking in the original code to add some like "If This Page = register" or whatever the correct variable term is for check the page.

Any help will be greatly appreciated.

Thanks Michael

bpr
05-01-2010, 04:26 PM
According to the file register.php in your forum root directory this is line 17:
define('THIS_SCRIPT', 'register');

You can also use "THIS_SCRIPT" to ask for the current script, in that case you could say

if (THIS_SCRIPT == 'register') { do this}

i am not an expert on the hooks but i assume that you could actually create a new plugin choose the right hook and then you just put your if clause which i mentioned before and afterwords you do something like this:

$template_hook['YOU NEED THE CORRECT HOOK'] .= vB_Template::create('header_include_orwhatever')->render();

hope it helps

vbplusme
05-02-2010, 01:48 AM
Thanks for the update. I was thinking that I needed a added condition in the template conditional. I am not using any php code to do this redirect as the whole process is contained and executed inside the headinclude template. So, I was thinking that I needed something like :

<vb:if condition="$bbuserinfo['userid'] == 0" AND !(THIS_SCRIPT == 'register')>


I do want the redirect to work on all scripts EXCEPT the registration form. I think this logic is correct but I am sure that the syntax is not.

Any ideas?

Edit:

Found it!

<vb:if condition="$bbuserinfo['userid'] == 0" AND condition="THIS_SCRIPT != 'register'">
<meta HTTP-EQUIV="REFRESH" content="15; url=http://yoursite.com/register.php">
</vb:if>

Paste this block in headinclude template just with the rest of the meta tags and if you have a visitor to your site checking things out, they will be redirected to the registration form in 15 seconds using this code. To change the time of the redirect change 15 to what ever.

bpr: thanks for the tips, got me thinking in the right direction