cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: curl:cookies

From: peeyush gulati <peeyushgulati_at_gmail.com>
Date: Thu, 10 Jan 2008 00:06:37 +0530

Thank you all for your replies.

We just solved it down using HTTP_REQUEST.

1.What we did was using HTTP_REQUEST a request was send to login page with
post
data credentials like username, password and some other field if required.

2. Then using HTTP_RESPONSE the cookies that were being sent from the
application(viz wordpress,mediawiki) to the layer were retrieved into local
variables.

3. Finally the cookies were set using setcookie() depending what all cookies
were
to be set like sessionid, username and so on.

4. Then using header('Location:URL'); the page was directed to desired
loggedin
page and since the cookies were also set now so the user would not have any
issues in navigating through the application.

If anyone is still not clear or has some doubts please do tell also suggest
if this would have some loop holes.

Thanks once again all.

Peeyush

On Jan 8, 2008 4:21 PM, peeyush gulati <peeyushgulati_at_gmail.com> wrote:

>
> Dear All
>
>
>
> I am trying to code a php-script that would automatically log a user
> into mediawiki. The script and mediawiki are on the same server.
>
>
> eg Browser----->Script----->Mediawiki
>
>
>
>
>
>
> Please refer to the code below :
>
> <?php
>
> require_once "HTTP/Request.php";
> $req =& new HTTP_Request();
> function hitForm($loginURL, $loginFields, $referer="") {
> $ch = curl_init();"
> curl_setopt($ch, CURLOPT_COOKIEJAR,"cookies.txt ");
> curl_setopt($ch, CURLOPT_COOKIEFILE,"cookies.txt ");
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); "
> curl_setopt($ch, CURLOPT_URL, $loginURL);
> curl_setopt($ch, CURLOPT_POST, 1);"
> curl_setopt($ch, CURLOPT_REFERER, $referer);"
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);"
> curl_setopt($ch, CURLOPT_POSTFIELDS, $loginFields);"
> $ret = curl_exec($ch);
> curl_close($ch);"
> return $ret;
>
> }
>
> $loginURL="
> http://localhost/login.php?title=Special:Userlogin&action=submitlogin&type=login";
> $loginFields = "wpName=peeyush&wpPassword=redhat&wpLoginattempt=Log+in";
> $referer="
> http://localhost/main/index.php?title=Special:Userlogin&returnto=Special:Userlogout";
>
> echo hitForm($loginURL,$loginFields,$referer);
> ?>
>
> I am able to login in using the above script but if i try to navigate
> further in the application it does not helps me.
>
> I also executed curl_setopt($ch, CURLOPT_COOKIEFILE,
> "/tmp/cookieFileName"); to navigate to further pages. But it doesn't
> works. Is this all some platform dependent. I am implementing this all
> on linux platform.
>
> Can some one help on this !!!!
>
>
> Thanks
> Peeyush
>
> --
> Thanks and Regards
> Peeyush Gulati
> +91-9916304135

-- 
Thanks and Regards
Peeyush Gulati
+91-9916304135

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-01-09