Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. class server{
  2. private $con;
  3. public static function authenticate($header_params){
  4. if($header_params->username == 'Aboubakr' && $header_params->password=='root') return true;
  5. else throw new SOAPFault('wrong user/pass combination', 401);
  6. }
  7. public function __construct(){
  8. $this->con = (is_null($this->con))?self::connect():$this->con;
  9. }
  10. static function connect(){
  11. $con = mysql_connect('localhost','root','nis');
  12. mysql_select_db('dealer', $con);
  13. return $con;
  14. }
  15. public function getStudentName($id_array){
  16. $id = $id_array['id'];
  17. $sql = "SELECT * FROM stockprices WHERE stock_id = '$id'";
  18. $qry = mysql_query($sql,$this->con);
  19. $res = mysql_fetch_array($qry);
  20. return $res['stock_symbol'];
  21. }
  22. }
  23. $params = array('uri'=>'server.php');
  24. $server = new SoapServer(NULL, $params);
  25. $server->setClass('server');
  26. $server->handle();
  27.  
  28. <?php
  29. class client{
  30. public function __construct(){
  31. $params = array('location'=>'http://localhost/ws/soap/server.php', 'uri'=>'urn://localhost/ws/soap/server.php', 'trace'=>1);
  32. $this->instance = new SoapClient(NULL, $params);
  33.  
  34. //set headers
  35. $auth_params = new stdClass();
  36. $auth_params->username = 'Aboubakr';
  37. $auth_params->password = 'root';
  38.  
  39. $header_params = new soapVar($auth_params, SOAP_ENC_OBJECT);
  40. $header = new soapHeader('codev','authenticate', $header_params, false);
  41. $this->instance->__setSoapHeaders(array($header));
  42. }
  43. public function getName($id_array){
  44. return $this->instance->__soapCall('getStudentName', $id_array);
  45. }
  46. }
  47. $client = new client;
  48. ?>
  49.  
  50. <?php
  51. include('client.php');
  52. $id_array = array('id'=>'2');
  53. echo $client->getName($id_array);
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement