XF 2.1 Redirect to 'register' page from /XF/Entity/Session

Wutime

Well-known member
Hoping someone can help: I've extended the /XF/Entity/Session to track a special cookie value pair for guests.

When an occurrence is found I want to redirect the current guest visitor to the registration page.

What is the best method of redirection? /XF/Entity/Session has no redirect methods and PHP Header("Location") is messy.

Can anyone point me in the right direction of what method or existing class to use for best practices, and how to use that from /XF/Entity/Session if possible?

Thank you very much in advance.
 
I tried the following, which is definitely not pretty, but it gives a "400 Bad Request" error:

PHP:
$response = \XF::app()->http()->client();
$response->redirect('http://192.168.33.10/xenforo/index.php?register');

The resulting error:
An exception occurred: [GuzzleHttp\Exception\ClientException] Client error: REDIRECT http://192.168.33.10/xenforo/index.php?register resulted in a 400 Bad Request response: <!DOCTYPE html> <html id="XF" lang="en-US" dir="LTR" data-app="public" data-template="error" data-container-key="" d (truncated...) in src/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

GuzzleHttp\Exception\RequestException::create() in src/vendor/guzzlehttp/guzzle/src/Middleware.php at line 66
GuzzleHttp\Middleware::GuzzleHttp\{closure}() in src/vendor/guzzlehttp/promises/src/Promise.php at line 203
GuzzleHttp\Promise\Promise::callHandler() in src/vendor/guzzlehttp/promises/src/Promise.php at line 156
GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() in src/vendor/guzzlehttp/promises/src/TaskQueue.php at line 47
GuzzleHttp\Promise\TaskQueue->run() in src/vendor/guzzlehttp/promises/src/Promise.php at line 246
GuzzleHttp\Promise\Promise->invokeWaitFn() in src/vendor/guzzlehttp/promises/src/Promise.php at line 223
GuzzleHttp\Promise\Promise->waitIfPending() in src/vendor/guzzlehttp/promises/src/Promise.php at line 267
GuzzleHttp\Promise\Promise->invokeWaitList() in src/vendor/guzzlehttp/promises/src/Promise.php at line 225
GuzzleHttp\Promise\Promise->waitIfPending() in src/vendor/guzzlehttp/promises/src/Promise.php at line 62
GuzzleHttp\Promise\Promise->wait() in src/vendor/guzzlehttp/guzzle/src/Client.php at line 131
GuzzleHttp\Client->request() in src/vendor/guzzlehttp/guzzle/src/Client.php at line 89
GuzzleHttp\Client->__call() in src/addons/Wutime/LimitedGuestViewing/XF/Session/Session.php at line 56
Wutime\LimitedGuestViewing\XF\Session\Session->start() in src/XF/App.php at line 825
XF\App->XF\{closure}() in src/XF/Container.php at line 28
XF\Container->offsetGet() in src/XF/Pub/App.php at line 43
XF\Pub\App->XF\Pub\{closure}() in src/XF/Container.php at line 28
XF\Container->offsetGet() in src/XF/App.php at line 2505
XF\App->session() in src/XF/Pub/App.php at line 148
XF\Pub\App->start() in src/XF/App.php at line 2173
XF\App->run() in src/XF.php at line 390
XF::runApp() in index.php at line 20

My goal is to immediately forward the user to the non-overlay registration page. Something like: RedirectCurrentVisitor ('register')
 
I'm using the following code to build the URL to redirect to the registration page.

If someone has a cleaner way to build the full URL (something that's bullet proof against the registration page changing locations) please let me know:
PHP:
$registerUrl = $options->boardUrl . 'register/'; // registration link

I did try:
PHP:
\XF::app()->router('public')->buildLink('register')
but it results in: /xenforo/register/ and the $boardUrl already has /xenforo/ in it because of my sub-directory, so this method seemed like it would require too much string clean-up.
 
Can you show your work for the class for the \XF::app()->response()->redirect($url, $httpCode); i seem to not get this to work
 
Top Bottom