Linto's Blog

Just another WordPress.com weblog

Example code for SOAP , using nusoap library January 23, 2012

Filed under: SOAP — linodavis @ 4:46 pm

<?php
/*
+——————————————————————-+

+——————————————————————-+
*/
session_start();
// Enable error reporting
//  ini_set(“display_errors”,”1″);
//  ini_set(“error_reporting”, E_ALL);

// Pull in the NuSOAP code
require_once(‘nusoap/lib/nusoap.php’);

// Create the client instance
//$client = new nusoap_client(‘http://dev1.uvjtech.net/gev/API/Authentication.php?wsdl’, true);
$client = new nusoap_client(‘http://my2020i.com/gev/API/Authentication.php?wsdl’, true);

// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo ‘<h2>Constructor error</h2><pre>’ . $err . ‘</pre>’;
// At this point, you know the call that follows will fail
}

$error_text = “”;
if(isset($_POST['submit']) && $_POST['submit'] == “Sign In”){

$username  = $_POST['username'];
$password  = $_POST['password'];

if($username && $password){

if($_POST['is_doctor'] == 1)
$is_doctor = TRUE;
else
$is_doctor = FALSE;

if($username && $password){
// Call the SOAP method
$result = $client->call(‘Authenticate’, array(‘user_username’ => $username, ‘user_password’ => $password, ‘is_doctor’ => $is_doctor));
if($result['user_id']){
$_SESSION['user_id'] = $result['user_id'];
$_SESSION['user_grp_id'] = $result['user_grp_id'];
}

}

}else{

$error_text = “Please enter Username or Password”;
}

}

//echo ‘<h2>Response</h2><pre>’ . htmlspecialchars($client->response, ENT_QUOTES) . ‘</pre>’;

?>
<html>
<head>
<title>Authentication</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>

<body>
<table width=”100%” cellpadding=”1″ cellspacing=”1″ align=”center”  border=”0″>
<tr>
<td width=”20%” align=”center” valign=”top”></td>
<td width=”80%” valign=”top”>
<form name=”frm_login” action=”" method=”post”>
<table>
<tr><td colspan=”2″><b>Sign in</b></td></tr>
<tr><td colspan=”2″></td></tr>

<?php if($_POST['submit'] && $result['user_id']){
?>
<tr><td colspan=”2″ height=”20″></td></tr>
<tr><td colspan=”2″><?php echo “Welcome, “. $result['user_fname'].’ ‘.$result['user_lname']; ?></td></tr>
<tr><td colspan=”2″><?php echo “Your email ID: “.$result['user_email']; ?></td></tr>
<?php if(!$is_doctor){
?>
<tr><td  colspan=”2″ height=”20″><a href=”find_doctors.php”>Search Doctor</a></td></tr>
<?php }
?>
<tr><td  colspan=”2″ height=”20″><a href=”update_profile.php”>Update Profile</a></td></tr>
<tr><td  colspan=”2″ height=”20″><a href=”change_password.php”>Change Password</a></td></tr>

<tr><td  colspan=”2″ height=”20″></td></tr>

<?php }else if($result['user_id'] == ’0′){ ?>
<tr><td colspan=”2″>Sorry…Invalid login. Please try again.</td></tr>
<tr><td  colspan=”2″ height=”20″></td></tr>

<?php }else if($error_text){ ?>
<tr><td colspan=”2″><?php echo $error_text; ?></td></tr>
<tr><td  colspan=”2″ height=”20″>&nbsp;</td></tr>
<?php } ?>
<tr >
<td >Username</td>
<td ><input type=”text” name=”username” value=”<?php echo $username; ?>” /></td>

</tr>
<tr >
<td>Password</td>
<td ><input type=”password” name=”password”  /></td>
</tr>

<tr >
<td>Check if Doctor</td>
<td ><input type=”checkbox” name=”is_doctor” value=”1″ <?php if($is_doctor) echo ‘checked’;?>  /></td>
</tr>

<tr>
<td ></td>
<td align=”left”>
<input type=”submit” name=”submit” value=”Sign In” />
</td>
</tr>
<tr>
<td  colspan=”2″>&nbsp;</td>
</tr>
<tr>
<td  colspan=”2″><a href=”user_registration.php”>Sign Up</a></td>
</tr>

</table>
</form>
</td>
</tr>

</table>
</body>
</html>

Advertisement
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.