+ Reply to Thread
Results 1 to 4 of 4

Thread: Submitting login info via CURL

  1. #1
    bocode is offline Roundcube Newcomer
    Join Date
    Jan 2010
    Posts
    6
    Downloads
    0
    Uploads
    0

    Default Submitting login info via CURL

    Hello All,

    I'm trying to post the login info to RC (viz., _user, _pass, _action et al) via a curl script with no changes done to any of the RC code (like rc/index.php). But am unable to get the RC mail dashboard (folders or left, mail pane in the center etc). Also the the address bar remains same with the url of the script which has the curl in it.

    This is my CURL code:
    --------------------------------
    $url = "/rc/index.php";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); // return into a variable
    curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after Ns
    curl_setopt($ch, CURLOPT_POST, 1); // set POST method
    curl_setopt($ch, CURLOPT_POSTFIELDS, "_user=".$_POST['uname']."&_pass=".$_POST['passwd']."&ajax=1&_action=login"); // add POST fields
    curl_setopt($ch, CURLOPT_FAILONERROR, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_exec($ch); // run the whole process
    curl_close($ch);
    ----------------------------------------------

    Can somebody tell me what am doing wrong?

    Note: I'm interested in finding a solution to the problem of sending login info via a script to RC backend..curl is just a candidate..please let me know if any other (non-html) ways exist.

    Thanks in advance

  2. #2
    rosali's Avatar
    rosali is offline Super Moderator
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    2,394
    Downloads
    36
    Uploads
    0

    Default

    Check my plugin 'logout_redirect' (bundled with MyRoundcube plugins - see signature).

    There is a Javascript AJAX login sample included.

    CURL does not work because it establish a session by the webserver where the script is running and not for the client.
    Regards,
    Rosali

    __________________
    MyRoundcube Project http://myroundcube.googlecode.com
    MyRoundcube Online Demo - Free Email Address http://mail4us.net
    MyRoundcube Plugins Generic Installation Guide http://mail4us.net/myroundcube/index.php
    Mailing List http://mail4us.net/?_action=plugin.nabble

  3. #3
    coolatt is offline Registered User
    Join Date
    Mar 2010
    Location
    Mauritius
    Posts
    13
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by rosali View Post
    Check my plugin 'logout_redirect' (bundled with MyRoundcube plugins - see signature).

    There is a Javascript AJAX login sample included.

    CURL does not work because it establish a session by the webserver where the script is running and not for the client.
    hi rosali,

    according to my understanding curl emulates a browser.

    what if php is configured to store the session id in url instead of a cookie on the user's browser ?
    is it possible to ask CURL to log on behalf of the user ?
    assume curl login on behalf of user then it gets the session for that user.

    in a real browser, we access the desired url with the session id (get from curl) appended.
    will this do the job of automatically login a user ??


  4. #4
    rosali's Avatar
    rosali is offline Super Moderator
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    2,394
    Downloads
    36
    Uploads
    0

    Default

    Well, just try it. I'm not too experienced in these things. But I think it won't work. On the first request PHP transmits a Session ID to the browser, which the browser has to use on each following request to be identified as the same user. The first request comes from cURL and not from the client browser.
    Regards,
    Rosali

    __________________
    MyRoundcube Project http://myroundcube.googlecode.com
    MyRoundcube Online Demo - Free Email Address http://mail4us.net
    MyRoundcube Plugins Generic Installation Guide http://mail4us.net/myroundcube/index.php
    Mailing List http://mail4us.net/?_action=plugin.nabble

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts