We help IT Professionals succeed at work.
Get Started

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

Shamsul Kamal
Last Modified: 2014-12-07

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.
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE