CURL not retaining the session after login

Posted on 2011-10-04
Last Modified: 2013-11-13

I am using CURL to login to a page which redirects to another page upon successful login.
The problem I am facing is, once the login is successful, the redirect page is taking me back to the login page with error code 302 - Page moved Temporarily.

I am using the following command to login
CURL.exe -c "cookies.txt" -d "username=xxxx&password=xxxx&submit=Login" -i

**the above command logs me in and redirects back me to the login page where as it is suppose to show the page.

once the login is successful, i have to post the data to another page for which am using the following command which is redirecting me to same login page.
CURL.exe -b "cookies.txt" --form "field1=xxx" --form "field2=xxxx" -i

NOTE: one thig I noticed which may be a relevant hint is when i am loged in to the page using hte browser and when i try to access the from another tab it redirects me to the login page.

Please help me to understand where i am going wrong here.

Question by:Shiva-Kumar
    LVL 42

    Expert Comment

    by:Rob Jurd, EE MVE
    have you tried the -u switch for username and password?  Also sound like some variables might be missing either GET or POST?
    LVL 39

    Accepted Solution

    You may need  another -c to get more cookies.
    And you may need -e  (--referer) that old the previous URL
    LVL 13

    Expert Comment

    Try using -c "cookies.txt" -b "cookies.txt" -L
    on at least the first command and maybe both--maybe the server really wants you to follow that redirect to be logged in.

    Author Comment

    Noci's switch has done the trick.  Thank you.

    I was missing --referer.


    Author Closing Comment

    Thank you!!!!

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This is about my first experience with programming Arduino.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now