Redirects working on localhost but not web host

Hi, I’m having an unusual issue which I can’t get my head around - and I’d appreciate advice from this community on the best way to debug it.

My site works correctly when run on my local wamp server, but when I upload it to my web host certain redirects don’t work. As an example, at the end of this post route there is a redirect to ‘home’, which is namespaced as ‘home’.

On my local server this redirects correctly and I get my home view with the URL ‘localhost/websitename/public’ in the address bar.

However, when run on my webhost it instead just shows a blank browser window with the URL as ‘www.websitename.com/public/register’

Does anyone know what may be causing this to happen? I’ve tried echoing out the root and var_dumping the session, but neither has helped me find the cause yet. Any help is much appreciated!


<?php use PhD\User\UserPermission; $app->get('/register', $guest(), function() use ($app) { $app->render('auth/register.php'); })->name('register'); $app->post('/register', $guest(), function() use ($app) { $request = $app->request; $email = $request->post('email'); $username = $request->post('username'); $password = $request->post('password'); $passwordConfirm = $request->post('password_confirm'); $v = $app->validation; $v->validate([ 'email' => [$email, 'required|email|uniqueEmail'], 'username' => [$username, 'required|alnumDash|max(20)|uniqueUsername'], 'password' => [$password, 'required|min(6)'], 'password_confirm' => [$passwordConfirm, 'required|matches(password)'] ]); if ($v->passes()) { $identifier = $app->randomlib->generateString(128); $user = $app->user->create([ 'email' => $email, 'username' => $username, 'password' => $app->hash->password($password), 'active' => false, 'active_hash' => $app->hash->hash($identifier), ]); $user->permissions()->create(UserPermission::$defaults); $app->mail->send('email/auth/registered.php', ['user' => $user, 'identifier' => $identifier], function($message) use ($user) { $message->to($user->email); $message->subject('Thanks for registering.'); }); $app->flash('global', 'You have been registered.'); return $app->response->redirect($app->urlFor('home')); } $app->render('auth/register.php', [ 'errors' => $v->errors(), 'request' => $request ]); })->name('register.post');

Hey jimyclarke01 - Make sure there are no blank lines before “<?php" and REMOVE all "?>”. Removing all the “?>” might cause an error or two, in that case add the “?>” only to the pages giving the error…

It has to do with headers being sent (or not, i think) with the blank lines or the php end. That is why the page remains blank.

Hope this solves the problem.