Announcement

  •  » Extensions
  •  » Unable to access pwg.session.login method of web API (web-services)

#1 2022-03-25 15:22:33

colorpencil
Member
2022-03-25
4

Unable to access pwg.session.login method of web API (web-services)

I am new to piwigo. Was trying to login into local piwigo installation, using pwg.session.login method as per following code using PHP. Getting blank screen and no error in apache log. Any help to make it work is appreciated.

piwigo-12.2.0
PHP 7.4.16
Ubuntu 21.04

Code:

<?php

$url = "http://myubuntu21/piwigo/ws.php?format=json&method=pwg.session.login";

$data = array(
    'username' => 'admin',
    'password' => 'xxxxxxxx'
);
$data_string = json_encode($data);                                                                                   

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

$resultLogin = curl_exec($ch);

echo $resultLogin;

curl_close($ch);
?>

Last edited by colorpencil (2022-03-25 15:27:53)

Offline

 

#2 2022-03-25 19:18:13

erAck
Only trying to help
2015-09-06
1395

Offline

 

#3 2022-03-26 06:51:44

colorpencil
Member
2022-03-25
4

Re: Unable to access pwg.session.login method of web API (web-services)

Thanks. Tried that but did not work.
Noticed that solution was from 2004. Probably lots of things has been changed meantime.
Any other idea to try?

Offline

 

#4 2022-03-27 16:48:36

colorpencil
Member
2022-03-25
4

Re: Unable to access pwg.session.login method of web API (web-services)

Finally was able to make it works. Sharing, the working code bellow,  as this might help some other newbie like me :-

1. It did not work in local machine. Need the host the target piwigo in internet
2. Added the following line in local/config/config.inc.php

Code:

$conf['session_use_ip_address'] = false;

Code:

<?php

$siteUrl = 'http://www.example.com/';
$user ='admin';
$password = 'xxxxxx';

// LOGIN TO PIWIGO
$url= $siteUrl . "ws.php?format=json";
$postdata = "method=pwg.session.login&username=" . $user . "&password=" . $password;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, true);
$resultLogin = curl_exec($ch);

echo "<pre>$resultLogin</pre>";

//GET COOKIE
preg_match_all('|Set-Cookie: (.*);|U', $resultLogin, $results);
$cookie = $results[1][1];
echo "<pre>$cookie</pre>";

curl_close($ch);

?>

Last edited by colorpencil (2022-03-27 16:50:01)

Offline

 
  •  » Extensions
  •  » Unable to access pwg.session.login method of web API (web-services)

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2022 · Contact