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
<?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
See [Forum, topic 20621] Calling pwg.session.login to login user via php script? and [Forum, post 142004 by Polly in topic 21866] PHP API Login.
Offline
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
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
$conf['session_use_ip_address'] = false;
<?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