I'm trying to realize a simple authorization using login and password. I get a cookie but not sure if authorized or not (how to check?), also I am trying to redirect after authorization but as a result, I get Error 404 after my code tried to redirect (followlocation, true).
Here's my php code
Trying just to redirect but 404 occurred.
$curl = curl_init($url); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $result = curl_exec($curl); echo $result; curl_close($curl); And here's trying to authorize, not sure if it works (but I get cookie and in header I get 200 OK)
$loginData = [ urlencode('j_username') => 'someName', urlencode('j_password') => 'somePassword' ]; $curl = curl_init($url); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_VERBOSE, 2); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($loginData)); curl_setopt($curl, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/authCookie.txt'); curl_setopt($curl, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/authCookie.txt'); $result = curl_exec($curl); echo $result; curl_close($curl); Also, I use urlencode but not sure if I use it in the right way (I have it in curl like $curl --location --request POST 'http://someFullName' \ --data-urlencode 'j_username=someUsername' \ --data-urlencode 'j_password=somePassword')