最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - 403 Forbidden in Laravel - Stack Overflow

matteradmin4PV0评论

Description: Whenever I visit the URI '/storage/decode/hello' the 403 error is shown, but when I go to '/storage/decode' URI, then the code works perfectly fine.

Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {

    $requestedUri       = $request->getRequestUri();
    $requestedUri_array = explode('/', $requestedUri);
    $task               = $requestedUri_array[2];

    if ($request->isMethod('get')) {

        if ($task == 'decode') {
            if ( ! isset($requestedUri_array[3])) {
                return "Bro you are in wrong place.";
            }

            return "Yes bro right place to be";
        }

    }

    if ($request->isMethod('post')) {

        if ($task == 'encode') {
            if ( ! isset($requestedUri_array[3])) {
                dd(['success' => 'false', 'message' => 'Please provide valid data to store']);
            }
            $encryptedVal = encrypt($requestedUri_array[3]);
            dd($encryptedVal);
        } else {
            dd('Invalid URL');
        }

    }

});

Description: Whenever I visit the URI '/storage/decode/hello' the 403 error is shown, but when I go to '/storage/decode' URI, then the code works perfectly fine.

Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {

    $requestedUri       = $request->getRequestUri();
    $requestedUri_array = explode('/', $requestedUri);
    $task               = $requestedUri_array[2];

    if ($request->isMethod('get')) {

        if ($task == 'decode') {
            if ( ! isset($requestedUri_array[3])) {
                return "Bro you are in wrong place.";
            }

            return "Yes bro right place to be";
        }

    }

    if ($request->isMethod('post')) {

        if ($task == 'encode') {
            if ( ! isset($requestedUri_array[3])) {
                dd(['success' => 'false', 'message' => 'Please provide valid data to store']);
            }
            $encryptedVal = encrypt($requestedUri_array[3]);
            dd($encryptedVal);
        } else {
            dd('Invalid URL');
        }

    }

});
Share Improve this question asked Nov 17, 2024 at 14:13 Diwash MainaliDiwash Mainali 634 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {

})->where('any', '.*');

This accepts any number of URIs.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far