Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel : How to hide url parameter?

Here the scenario is I want to pass a variable which will be send from one page to another and in next page it's gonna store through a form. So I have passed the variable from first page to second page through the URL. But I want to hide the parameter in the URL. How do I do it?

Here is my route :

Route::get('/registration/{course_id}',[
   'uses'=>'AppController@getregistration',
    'as'=>'registration'
]);

And Controller :

public function getregistration($course_id)
{        
    return view('index')->with('course_id',$course_id);      
}

And first page this is how I send the value to first page:

<li> <a  href="{{route('registration',['course_id' => '1'])}}">A</a> </li>
like image 579
Hola Avatar asked Oct 10 '16 04:10

Hola


People also ask

How can I hide URL parameters?

You cannot hide parameters. Even if you use the post method instead of the get method to remove parameters from the url. You can still see the passed parameters in the request message. The way to safely hide parameters is to encrypt them.

How to hide URL data in PHP?

It's possible to hide the URL parameters from users by creating a PHP session. You must then store the parameters in session variables, use a PHP redirect to call the second PHP script and retrieve the session variable values in the second PHP script.

How do I hide URL value when using HREF to pass value?

you can use session (if user is logged in) pass user id (not that good idea thou, users can guess that easily) make a POST request with params (not link, form is used for that)

What is @param in laravel?

The required parameters are the parameters that we pass in the URL. Sometimes you want to capture some segments of the URI then this can be done by passing the parameters to the URL. For example, you want to capture the user id from the URL.


1 Answers

Post Method

Route

Route::post('/registration',['uses'=>'AppController@getregistration','as'=>'registration']);

View

{!!Form::open(array('url' => '/registration')) !!}
  {!! Form::hidden('course_id', '1') !!}
  {!! Form::submit('registration') !!}
{!! Form::close() !!}

Controller

public function getregistration(Request $request)
{   
    $course_id = $request->input('course_id');
    return view('index')->with('course_id',$course_id);      
}

Get method

use encryption method, it will show encrypted id in url

View

<li> <a  href="{{route('registration',['course_id' => Crypt::encrypt('1') ])}}">A</a> </li>

Controller

public function getregistration($course_id)
{    
  $course_id = Crypt::decrypt($course_id);    
  return view('index')->with('course_id',$course_id);      
}
like image 63
Imran Hossain Avatar answered Oct 20 '22 02:10

Imran Hossain