title: Login to a php site with curl
body: <p>I am trying to do a bash script to login to a php site via curl. In this way (always with curl) I will be able to download a file.</p>
  <p>The site in question is this:</p>
  <pre><code>&quot;https://web.spaggiari.eu/home/app/default/login.php&quot;
  </code></pre>
  <p>I thought I could use this command to login by sending a cookie:</p>
  <pre><code>curl --anyauth --user username:password https://web.spaggiari.eu/
  </code></pre>
  <p>and then try to download the file from this site using this command (The site below is where I should download the file from):</p>
  <pre><code>curl -v https://web.spaggiari.eu/fml/app/default/xml_export.php? 3Aclasse_id% 3A &amp; gruppo_id =% 3Agruppo_id% 3A &amp; ope = RPT &amp; dal = 2020-11-03 &amp; al = 2020-11-03 &amp; format = xls 
  </code></pre>
  <p>The output of the command though is this:</p>
  <pre><code>* Expire in 2 ms for 1 (transfer 0x558707881f50)
  *   Trying 159.69.111.222...
  * TCP_NODELAY set
  * Expire in 149996 ms for 3 (transfer 0x558707881f50)
  * Expire in 200 ms for 4 (transfer 0x558707881f50)
  * Connected to web.spaggiari.eu (159.69.111.222) port 443 (#0)
  * ALPN, offering h2
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * TLSv1.3 (OUT), TLS handshake, Client hello (1):
  * TLSv1.3 (IN), TLS handshake, Server hello (2):
  * TLSv1.2 (IN), TLS handshake, Certificate (11):
  * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  * TLSv1.2 (IN), TLS handshake, Server finished (14):
  * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
  * TLSv1.2 (OUT), TLS handshake, Finished (20):
  * TLSv1.2 (IN), TLS handshake, Finished (20):
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
  * ALPN, server accepted to use http/1.1
  * Server certificate:
  *  subject: CN=*.spaggiari.eu
  *  start date: May 29 00:00:00 2020 GMT
  *  expire date: May 29 12:00:00 2022 GMT
  *  subjectAltName: host &quot;web.spaggiari.eu&quot; matched cert's &quot;*.spaggiari.eu&quot;
  *  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
  *  SSL certificate verify ok.
  &gt; GET /fml/app/default/xml_export.php?stampa=%3Astampa%3A HTTP/1.1
  &gt; Host: web.spaggiari.eu
  &gt; User-Agent: curl/7.64.0
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 302 Found
  &lt; Server: nginx/1.18.0
  &lt; Date: Tue, 03 Nov 2020 19:30:46 GMT
  &lt; Content-Type: text/html; charset=UTF-8
  &lt; Content-Length: 0
  &lt; Connection: keep-alive
  &lt; X-Frame-Options: SAMEORIGIN;
  &lt; Content-Security-Policy: script-src 'self' filesystem: 'unsafe-eval' 'unsafe-inline' *.spaggiari.eu https://ajax.googleapis.com/ https://cdnjs.cloudflare.com/ https://cdn.jsdelivr.net/ https://code.jquery.com/ https://d31qbv1cthcecs.cloudfront.net/atrk.js https://fonts.googleapis.com/ https://www.google-analytics.com/ https://www.google.com/recaptcha/ https://www.googletagmanager.com/ https://www.gstatic.com/recaptcha/;frame-ancestors 'self' file: *.spaggiari.eu;
  &lt; Set-Cookie: PHPSESSID=pc6u2mc162b30ek2gp9u6phdpt7q85kv; path=/; secure; HttpOnly
  &lt; Expires: Thu, 19 Nov 1981 08:52:00 GMT
  &lt; Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  &lt; Pragma: no-cache
  &lt; Location: ../../../home/app/default/login.php
  &lt; X-ZVersion: c
  &lt; Pragma: public
  &lt; Cache-Control: public, must-revalidate, proxy-revalidate
  &lt; 
  * Connection #0 to host web.spaggiari.eu left intact
  </code></pre>
  <p>That's a redirection sending me to the login page.
  So it tells that I have an authentication problem i think.
  Now I don't understand what I have to do to be able to log in. I have the correct credentials, but I think I am doing something wrong with the command used.</p>
  <p>Thanks everyone for the answers.</p>