0

So I already looked at the answers that are related to my issue. I have a laravel application which is working great on my localhost server. Routes are working fine there. But when I uploaded my laravel application on shared hosting, only GET methods are working. When I try to use any POST request such as login to my application, it sends 405 error code. So i'll show you what is wrong when I login for example.

This is the route.

Route::post('authinticate',['as'=>'authinticate','uses'=>'LoginController@authenticate']);

The controller function

public function authenticate(LoginRequest $request)
    { //$credentials = $request->only('user_name', 'password');

        $credentials = array(
            'user_name' => $request->input('username'),
             'password' => $request->input('password'),
            );


        if (Auth::attempt($credentials)) {
            // Authentication passed...
            return redirect()->route('home');
        }
        else{
            return redirect()->back()->withErrors(['message' => 'اسم المستخدم او كلمة المرور غير صحيحين.']);
        }
    }

HTML form:

<form method="POST" action="{{ route('authinticate') }}">
                @csrf

                    <div class="form-group signIn">
                        <label for="username">اسم المستخدم</label>
                        <input type="text" name="username" placeholder="اسم المستخدم" class="form-control" id="username" value="{{ old('user_name') }}">
                    </div>
                    <div class="form-group">
                        <label for="password">كلمة المرور</label>
                        <input type="password" name="password" placeholder="كلمة المرور" class="form-control" id="password">
                        <p></p>
                        <a href="{{ route('forgot') }}" >نسيت كلمة المرور</a>
                    </div>
                    <input type="submit" class="btn btn-block btn-default btn-success" name="submit" id="submit" value="دخـــول">
                </form>

This is what I get from console before submitting the form.

Mixed Content: The page at 'https://www.aouacc.net/login' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://www.aouacc.net/authinticate'. This endpoint should be made available over a secure connection.

And this is after submitting. enter image description here

enter image description here

mkabbanii
  • 59
  • 2
  • 10
  • Can you show your `home` route and controller? And can you log inside of your `authenticate` function to make sure it's 1) hitting the function and 2) which redirect it's going to? – aynber Aug 16 '18 at 20:13

1 Answers1

3

Check the headers, the POST request to http://www.aouacc.net/aunthinticate returns a 301 Mover Permanently header, which triggers a redirect to the https version. Since apparently you're not setting that redirect in your code, it might have been set at a sever level. Change your routes so they use https://www.aouacc.net instead of http://www.aouacc.net.

José A. Zapata
  • 1,187
  • 1
  • 6
  • 12
  • Alright, but how can I do that?, Also I forgot to mention that i'm using cloudflare, maybe it's passing somethings which is causing the problem? – mkabbanii Aug 17 '18 at 01:48
  • Check your Cloudflare configuration, there's a rule that automatically redirects all `http` requests to `https`. I think the option is "Automatic HTTPS Rewrites". If you do want to use https, then you need to force it in all your rules. Check the answer here: https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https/28403907#28403907 to see how to do that. – José A. Zapata Aug 17 '18 at 14:28