lundi 4 juin 2018

set session when send posts data from external website via curl to action controller

I using a code in my Home Controller :

public function myAction1(Request $request)
{
   $request->session()->put('redirect', $_POST['redirect']);
}

public function myAction2(Request $request)
{
   $request->session()->get('redirect');
}

and this is part of my route :

Route::get('pGetway/send', 'HomeController@myAction1')->middleware('cors');
Route::post('pGetway/send', 'HomeController@myAction1')->middleware('cors');

Route::get('pGetway/verify', 'HomeController@myAction2')->middleware('cors');
Route::post('pGetway/verify', 'HomeController@myAction2')->middleware('cors');

when I use HTTP request from browser thats session working well but when sending data from other website via curl it not working mean session did not set !!

I want set sesstion and using that from other action for example in myAction2

and this is curl request post:

$params = ['redirect'=>'http://example.com'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:8000/pGetway/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));

$response = curl_exec($ch);
curl_close($ch);

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire