Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class server{
- private $con;
- public static function authenticate($header_params){
- if($header_params->username == 'Aboubakr' && $header_params->password=='root') return true;
- else throw new SOAPFault('wrong user/pass combination', 401);
- }
- public function __construct(){
- $this->con = (is_null($this->con))?self::connect():$this->con;
- }
- static function connect(){
- $con = mysql_connect('localhost','root','nis');
- mysql_select_db('dealer', $con);
- return $con;
- }
- public function getStudentName($id_array){
- $id = $id_array['id'];
- $sql = "SELECT * FROM stockprices WHERE stock_id = '$id'";
- $qry = mysql_query($sql,$this->con);
- $res = mysql_fetch_array($qry);
- return $res['stock_symbol'];
- }
- }
- $params = array('uri'=>'server.php');
- $server = new SoapServer(NULL, $params);
- $server->setClass('server');
- $server->handle();
- <?php
- class client{
- public function __construct(){
- $params = array('location'=>'http://localhost/ws/soap/server.php', 'uri'=>'urn://localhost/ws/soap/server.php', 'trace'=>1);
- $this->instance = new SoapClient(NULL, $params);
- //set headers
- $auth_params = new stdClass();
- $auth_params->username = 'Aboubakr';
- $auth_params->password = 'root';
- $header_params = new soapVar($auth_params, SOAP_ENC_OBJECT);
- $header = new soapHeader('codev','authenticate', $header_params, false);
- $this->instance->__setSoapHeaders(array($header));
- }
- public function getName($id_array){
- return $this->instance->__soapCall('getStudentName', $id_array);
- }
- }
- $client = new client;
- ?>
- <?php
- include('client.php');
- $id_array = array('id'=>'2');
- echo $client->getName($id_array);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement