LMSouq
moodle-core Open

cURL works from Terminal, but not from PHP

CO
Community Contributor
1 month ago
3 views
Problem Description
I'm running into a rather strange issue. I'm trying to log into a remote moodle install using curl from PHP. I have a curl command, which works perfectly in the Terminal. When I translate the same thing into PHP, it works, but it just doesn't login. The exact same value which successfully login via terminal, somehow trips up the login system via PHP and it doesn't login. Instead, it returns the login page again. My cURL command (data section ommitted as it has my username and password): curl 'http://moodle.tsrs.org/login/index.php' -H 'Pragma: no-cache' -H 'Origin: http://moodle.tsrs.org' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: http://moodle.tsrs.org/login/index.php' -H 'Cookie: MoodleSession=ngcidh028m37gm8gbdfe07mvs7; MOODLEID_=%25F1%25CD%2519D%25B2k%25FE%251D%25EFH%25E5t%25B1%2503%258E; MoodleSessionTest=NhzaTNij6j; _ga=GA1.2.925953522.1416155774; _gat=1; __utmt=1; __utma=147409963.925953522.1416155774.1416642544.1416692798.3; __utmb=147409963.1.10.1416692798; __utmc=147409963; __utmz=147409963.1416155774.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)' -H 'Connection: keep-alive' The corresponding PHP code: function login() { $username = $_POST['username']; $password = $_POST['password']; if(!isset($_POST['username']) || !isset($_POST['password'])) { echo "No login data received"; return; } $creq...

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base