Time22's avatar

127.0.0.1 redirected you too many times.

Reseting password in my application a mail is sent am using mailtrap mail is well received when i click on the link it gives me this error 127.0.0.1 redirected you too many times please help.

0 likes
8 replies
LaryAI's avatar
Level 58

This error usually occurs when there is a redirect loop happening in your application. Here are a few things you can try to fix it:

  1. Clear your browser cache and cookies and try again.
  2. Check your code for any infinite redirect loops. Make sure that your code is not redirecting the user back to the same page repeatedly.
  3. Check your .htaccess file (if you are using Apache) for any redirect rules that might be causing the issue.
  4. Check your application's configuration files for any redirect rules that might be causing the issue.

If none of the above solutions work, please provide more information about your application and the code you are using so that we can help you better.

Code example:

// Check for infinite redirect loop
if ($redirectCount > 10) {
    throw new Exception('Too many redirects');
}

// Clear browser cache and cookies
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
setcookie('PHPSESSID', '', time() - 3600, '/', '', 0, 0);

// Check .htaccess file for redirect rules
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

// Check application configuration files for redirect rules
return [
    'debug' => env('APP_DEBUG', false),
    'url' => env('APP_URL', 'http://localhost'),
    'timezone' => 'UTC',
    'locale' => 'en',
    'fallback_locale' => 'en',
    'key' => env('APP_KEY'),
    'cipher' => 'AES-256-CBC',
];
tisuchi's avatar

@timene is it that your code was working fine before and suddenly you are facing this issue?

Time22's avatar

@tisuchi no i received the email about reseting the password when i click the link it needs to redirect to where i need to reset the password but am receiving This page isn’t working 127.0.0.1 redirected you too many times. I have cleared my cache cookies still not working

Time22's avatar

@tisuchi

    {
        return view('admin.auth.forget_password');
    }

    public function forget_password_submit(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
           ]);

           $admin_data = Admin::where('email',$request->email)->first();
           if(!$admin_data){
            return redirect()->back()->with('error','Email Not Found In Our Database');
           }

           $token = hash('sha256',time());

           $admin_data->token = $token;
           $admin_data->update();
           $reset_link = url('admin/reset-password/'.$token.'/'.$request->email);
           $subject = 'Reset Password';
           $message = 'Please Click the following link:<br>';
           $message .= '<a href="'.$reset_link.'">Click Here</a>';
           \Mail::to($request->email)->send(new Websitemail($subject,$message));
           return redirect()->route('admin_login')->with('status','Please Check Your Mail and Follow the Steps There!!!');
    }

    public function reset_password($token,$email)
    {
          $admin_data = Admin::where('token',$token)->where('email',$email)->first();
          if(!$admin_data){
            return redirect()->route('admin_login');
          }

          return redirect()->route('admin_reset_password',compact('token','email'));
    }

    public function reset_password_submit(Request $equest)
    {
        $request->validate([
            'password' => 'required',
            'retype_password' => 'required|same:password',
           ]);

           $admin_data = Admin::where('token',$request->token)->where('email',$request->email);
           $admin_data->password = Hash::make($request->password);
           $admin_data->token ='';
           $admin_data->update();
           return redirect()->route('admin_login')->with('status','Password Resetted Successfully');

    }```
tisuchi's avatar
tisuchi
Best Answer
Level 70

@Timene Can you change this line:

return redirect()->route('admin_reset_password', compact('token', 'email'));

To:

return view('your_reset_password_view', compact('token', 'email'));

In your reset_password() method?

Sidenote: You need to set your proper view name instead of your_reset_password_view

1 like

Please or to participate in this conversation.