Jump to content

Help with redirect


Flashmaster82
 Share

Recommended Posts

Im trying to redirect a logged in user back to his own user page if he tries to access another member page, but i can´t get it to work. It will redirect back to the correct url but then i get browser error?

"The page redirects incorrectly, Firefox has detected that the server is redirecting the request for this location in a way that prevents completion."
<?php

$userloggedinname = $user->name;
$pagename = $page->name;

{
$session->redirect( "{$pages->get(1)->httpUrl}medlemmar/" . $userloggedinname );
}

?>

also i tried this but same result

$userloggedinname = $user->name;
$pagename = $page->name;

if (!$userloggedinname === $pagename)
{
$session->redirect("{$pages->get('/')->url}medlemmar/{$userloggedinname}");
}

I have created another user template similar to this post https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

So my users is now under Home/Members/MemberX

I´m on localhost.

Also i if a user is logged in, the user can edit other users aswell 😞 so my goal is also to hide/restrict users to edit or access the processwire front end user edit page. I am building a separate edit on the front end user custom page that also is the memberX page, Home/Members/MemberX.

Any suggestions? Please help..

Link to comment
Share on other sites

I am assuming the template for those users is named 'member'. What is the setting in template member "URLs" tab, particularly the "Should page URLs end with a slash?" setting. If this is set to Yes (default), you need to append a trailing slash to the redirect URL, e.g. mydomain.com/medlemmar/username/ to avoid unnecessary redirects.

if ($sanitizer->pageName($userloggedinname) !== $pagename)
{
$session->redirect($pages->get('/')->url . "medlemmar/{$userloggedinname}/");
}

 

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...