views:

277

answers:

3

Hi,

I'm running Drupal and Mediawiki on my server under the same domain. They are connected to each other with extensions/modules. Meaning if I log in to Mediawiki, it automatically logs into Drupal also.

Mediawiki has some extensions that filter the information shown on the page.

What I want to do is to show that filtered information from Mediawiki on my Drupal page. I'm trying to fetch the data with PHP cURL, but I'm not able to force it to use the login information.

How can I convert PHP's $_COOKIE into cURL cookie.txt format? I suppose after that I'm able to fetch the data from Mediawiki with the right permissions.

This is what print_r($_COOKIE) outputs:

[wiki_session] => gg05lhd6pcfs5g6iokhoo0gue7

[wikiUserName] => WikiSysop

[wikiLoggedOut] => 20100510110913

[wikiUserID] => 1

[wikiToken] => 52cdb19a7b4a43e5a2f86939e4f54941

Thanks for any help!

+1  A: 

I believe the cookie file is a tab-seperated file consisting of the following fields:

  • domain - the domain the cookie applies to
  • tailmatch - true/false whether to allow subdomains access to
  • cookie path - the path to limit the cookie to (default /, meaning all)
  • secure - true/false whether to only transmit the cookie over https
  • expires - a unix timestamp or zero to never expire
  • name - name of the cookie variable
  • value - value!

I guess multiple lines in the file would correspond to multiple cookies, but I'm not sure

So your cookie might be

www.domain.com TRUE / FALSE 12395013 wiki_session gg05lhd6pcfs5g6iokhoo0gue7
www.domain.com TRUE / FALSE 12395013 wikiUserName WikiSysop

and so on

adam
A: 

Actually I found a way of doing it with file_get_contents instead of cURL.

This is how the problem was solved:

$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."\r\n"));

$context = stream_context_create($opts);

$contents = file_get_contents('http://foo/bar', false, $context);

boogie
A: 

To create a cookie the following function is used setcookie(name,value,expire,path,domain)

manoj
it is very useful
manoj
--------------------------------------
manoj