vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Register.php redirect to previous page? (https://vborg.vbsupport.ru/showthread.php?t=217549)

Ludnix 07-01-2009 04:14 AM

Register.php redirect to previous page?
 
I'm wondering if there is an option in vbulletin to have register.php redirect the user to their previous page on completion. I don't require email verification on my forum so it would be great if once they were registered it would take them to the original page the clicked the register link on rather than dumping them on the forum index.

I've seen a post about how to modify register.php to redirect somewhere else but I before I start changing register.php I thought I better make sure this isn't an option in the control panel or something.

Saurdo 07-01-2009 08:00 AM

I helped Ludnix out with his question.

Instead of doing this the smart way, which involves putting a hidden value on the registration page and then carrying that value throughout the registration process, I decided to take the easy (and fast) route and use a temporary cookie to store my data.

In register.php, right under this line:
PHP Code:

if ($_REQUEST['do'] == 'signup')


I put this code:
PHP Code:

setcookie('register_referrer'$_SERVER['HTTP_REFERER'], 0'/'); 

Might be a good idea to encode the referrer as well.

Then, after the user completes registration. The task is to redirect them to whatever that cookie value is.

So I found this line:
PHP Code:

eval(standard_error(fetch_error('registration_complete'$username$vbulletin->session->vars['sessionurl'], $vbulletin->options['bburl'] . '/' $vbulletin->options['forumhome'] . '.php'), ''false)); 

And replaced it with this:
PHP Code:

if(strlen($_COOKIE['register_referrer']) > 0){
                             
$vbulletin->url $_COOKIE['register_referrer']; 
                             eval(
print_standard_redirect('registration_complete')); 
                        }
                        else{
                            eval(
standard_error(fetch_error('registration_complete'$username$vbulletin->session->vars['sessionurl'], $vbulletin->options['bburl'] . '/' $vbulletin->options['forumhome'] . '.php'), ''false));
                        } 

Pretty sure $vbulletin->url is just a header redirect.

If you want, you can then delete your cookie:
PHP Code:

setcookie('register_referrer'''time()-3000'/'); 

and everything works and now everyone is happy.

DragonBlade 07-01-2009 08:31 AM

Bit of advice?

Next time, if you can avoid it, don't change the hard-code. :3 Instead, use the Plugin/Hook system that vBulletin created for us. This is because any changes you make directly to the file can and will be over-written upon a forum update.

The hook in question you should use is register_signup.


For those wishing to do this to their forums, go to your AdminCP, "Add a New Plugin", choose 'register_signup' as the hook location (title it whatever you want).

You can use the same code Saurdo created above in that location:
PHP Code:

setcookie('register_referrer'$_SERVER['HTTP_REFERER'], 0'/'); 


For the actual redirect, create another Plugin, and use the Hook Location register_addmember_complete. In this hook, use the following code:
PHP Code:

if (!$vbulletin->GPC['coppauser'])
{
  
// CLEAN THE COOKIE DATA!  Not particularly important here, but it's good practice. ;)
  
$vbulletin->input->clean_gpc('c''register_referrer'TYPE_STR);
  
$vbulletin->url = ($vbulletin->GPC['register_referrer']) ? $vbulletin->GPC['register_referrer'] : $vbulletin->url;



Saurdo 07-01-2009 08:52 AM

I don't have any experience modifying vbulletin, hence why I didn't want to learn what register.php was doing, but you certainly make a good point. It would be annoying to have to fix this whenever the register.php file is updated. I was kind of using this old thread to help me find where I needed to edit. (apparently I failed to read the last post though)

Thanks for the tip. I am definitely going to move my code to the plugin system and use it for any modifications I do in the future.

DragonBlade 07-01-2009 02:35 PM

Great. :3

Just look for them hook locations in the code whenever you want to modify something or add functionality.

Sometimes you just can't avoid making a direct hack to the file, but most of the time you can get something done with plugins that you need to. :) Plugins are great for two reasons--that bit about updating that I mentioned, and so that you can turn the plugins on and off if there might be a problem somewhere.


All times are GMT. The time now is 03:00 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02118 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete