Avatar of Shamsul Kamal
Shamsul Kamal

asked on 

How to run PHP script with session check via linux shell ?


I would like to request an assistant.

I have the following script :

function getClient() {

    $client = new SoapClient('http://url:8080/SKS1A/SKS1A?wsdl');

    // is soapcookies already set? (must be already logged in)

    if (isset($_SESSION['soapcookies'])) 

        // just set the cookies
        foreach ($_SESSION['soapcookies'] as $cookiename => $value)
            $client->__setCookie($cookiename, $value[0]);
    else  {

        //please change the username and password

        $result = $client->login(array('username' => $username, 'password' => $password))->return;

        //store the soap cookies in $_SESSION so that don't need to reauthenticate.
        $_SESSION['soapcookies'] = $client->_cookies;

    return $client;

$query = "SELECT id,domainname from domain WHERE status='check'";
$data = mysql_query($query, $conn) or die(); 

echo "Cron Check Start<br>";

	while($rec = mysql_fetch_array($data))
//get the SOAP client connection

$api = getClient();

$domain = $rec[domainname]; 
$arg0 = $reseller;
$arg1 = $domain; //sample result available

$result = $api->checkDomainAvailability(array('arg0' =>$arg0,'arg1' =>$arg1))->return;  
$xml = new SimpleXMLElement($result);
$result = $xml->code; 
$description = $xml->reason;

			if($result == 1000) { echo "Domain $domain successfully checked<br>";		}
            else { echo "Domain: '".$rec[domainname]."' '".$description."' ERROR<br>"; }

	}// end while.

Open in new window

May i know how to passed the session check in the script so that i can run the script finely via shell as if using browser ?

The purpose of doing this is that i want to set a cronjob to run this script.

A few complete sample with my current code inside it is appreciated.

Thank you.
PHPShell ScriptingLinux

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon