SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict pentium10's Avatar
    Join Date
    Apr 2004
    Location
    Transilvania
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    curl login, then redirect client to logged in page

    Hello,

    I have a cURL script, which logs in to a site with hardcoded login details. This is OK, and it's working.

    Also I want to redirect the client to the logged in page, logged in. The target page is not on my server and I don't have access to the code.
    How can I do that?

    Pentium10
    Rype :: book, do, charge, collect,
    track time, track expenses and invoice easily on the go.
    Available on Mac, Win, iPhone, WinMobile.
    http://www.rypenow.com

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    From your description, you can't do that. The client will need to know the hardcoded login details, or the target page will need some form of special auth(entication/orisation) setup.
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way that could work (provided some conditions are met):
    When you are logged in the remote site sets a session cookie - Typically PHPSESSID. By default PHP allows sessions to be sent either using cookies or via GET. So what you need, to do is to redirect user to remote page: http://remote.host.rem/logged_in.php?PHPSESSID={whatever_the_cookie_value_was_that_you_received_through_curl}

    This might work. But only if remote site does not take IP address into account and allows session id to be passed around through GET.

  4. #4
    SitePoint Addict pentium10's Avatar
    Join Date
    Apr 2004
    Location
    Transilvania
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    understood.

    How can I get the returned PHPSESSID from cURL?
    Rype :: book, do, charge, collect,
    track time, track expenses and invoice easily on the go.
    Available on Mac, Win, iPhone, WinMobile.
    http://www.rypenow.com

  5. #5
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The -v command line switch among other things turns on display of headers that you send and what server responds. For instance, if I type:
    curl -v http://www.sitepoint.com
    I get this:
    * About to connect() to www.sitepoint.com port 80 (#0)
    * Trying 69.20.16.232... connected
    * Connected to www.sitepoint.com (69.20.16.232) port 80 (#0)
    > GET / HTTP/1.1
    > User-Agent: curl/7.18.2 (i686-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8h zlib/1.2.3
    > Host: www.sitepoint.com
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Date: Fri, 05 Dec 2008 11:18:26 GMT
    < Server: Apache/2.0.46 (Red Hat)
    < X-Powered-By: PHP/4.3.11
    < Cache-Control: private, max-age=600
    < Set-Cookie: SID=9f68900d0a7088b1a252650e2b78b319; path=/
    < Set-Cookie: SPabc=a; expires=Sat, 05 Dec 2009 11:18:26 GMT; path=/
    < Transfer-Encoding: chunked
    < Content-Type: text/html
    <
    ... the usual content follows

  6. #6
    SitePoint Addict pentium10's Avatar
    Join Date
    Apr 2004
    Location
    Transilvania
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and how that works with PHP curl library?

    I use this
    PHP Code:
    $ch = @curl_init();
    @
    curl_setopt($chCURLOPT_URL,$loginURL);
    @
    curl_setopt($chCURLOPT_POST1);
    @
    curl_setopt($chCURLOPT_POSTFIELDS,$POSTFIELDS);
    @
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    @
    curl_setopt($chCURLOPT_REFERER$reffer);
    @
    curl_setopt($chCURLOPT_COOKIEFILE$cookie_file_path);
    @
    curl_setopt($chCURLOPT_COOKIEJAR$cookie_file_path);
    $result = @curl_exec ($ch);
    @
    curl_close ($ch); 
    Rype :: book, do, charge, collect,
    track time, track expenses and invoice easily on the go.
    Available on Mac, Win, iPhone, WinMobile.
    http://www.rypenow.com

  7. #7
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From the documentation:
    http://lv.php.net/manual/en/function.curl-setopt.php
    CURLOPT_HEADER TRUE to include the header in the output.
    I gather, that you have to use:
    curl_setopt($ch, CURLOPT_HEADER, true);


Bookmarks

Posting Permissions

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