Login with Bootstrap validation via POST

This application uses the sc_url_library function of Scriptcase to include the Bootstrap CSS libraries, and the PHP file_get_contents function to access a webservice created in another application that performs user validation and typed password.

Application Details

1. We are using a Blank application to display the login screen and include the Bootstrap library:


2. In the application we have the following code:

Blank "login"

$str_error_msg = "";
// Check if the login and password were typed.
if(isset($_POST['login']) && !empty($_POST['login']) && isset($_POST['password']) && !empty($_POST['password']))
// Parameters to be passed to the webservice.
$parms = 'option=validate_login';
$parms .= '&str_login=' . $_POST['login'];
$parms .= '&str_password=' . $_POST['password'];
$webservice_url = dirname(dirname("http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"])) . "/user/";

// Access the webservice.
$str_output = sc_webservice('file_get_contents', $webservice_url, $_SERVER["SERVER_PORT"], "POST", $parms, array(), 30);

// Check the return from the webservice.
if($str_output != 'ok')
$str_error_msg = $str_output;
// Starts the Login page layout.
<title>Bootstrap Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Include the Bootstrap libraries -->
<link rel="stylesheet" type="text/css" href="<?php echo sc_url_library('prj', 'bootstrap-3.3.2-dist', 'css/bootstrap.min.css'); ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo sc_url_library('prj', 'bootstrap-3.3.2-dist', 'css/style1.css'); ?>" />

<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<h1 class="text-center login-title">Sign in to continue to Login</h1>
<div class="account-wall">
<img class="profile-img" src="https://lh3.googleusercontent.com/-OJ26yjLQ8mo/AAAAAAAAAAI/AAAAAAAAAHg/9aw8LXIfn5I/s120-c/photo.jpg?sz=120" alt="">
<form class="form-signin" method="post">
<input type="text" name="login" class="form-control" id="form-login" placeholder="Email" required autofocus>
<input type="password" name="password" class="form-control" id="form-password" placeholder="Password" required>
<span role="alert" class="error-msg" id="errormsg_0_Passwd"><?php echo $str_error_msg; ?></span>
<input type="submit" value="Sign in" class="btn btn-lg btn-primary btn-block" />
<label class="checkbox pull-left">
<input type="checkbox" value="remember-me">
Remember me
<a href="#" class="pull-right need-help">Need help? </a><span class="clearfix"></span>
<a href="#" class="text-center new-account">Create an account </a>
<?php // Ends the Login page layout.

User validation service application

3. The code above performs access to the application "/user/", which will validate the login and password entered. This application will be a Blank containing the following code:

Blank "user"

if(isset($_POST['option']) && !empty($_POST['option']))
// Enter the condition if parameters have been correctly received from the previous application
$str_return = "";

// Check the option clicked by the user.
case 'validate_login':
// Option to validate user login and password.
sc_lookup(rs, "SELECT COUNT(*) FROM sec_users WHERE login = " . sc_sql_injection($_POST['str_login']) . " AND pswd = " . sc_sql_injection($_POST['str_password']));

if(isset({rs[0][0]}) && {rs[0][0]} > 0)
$str_return = "ok";
$str_return = {lang_msg_sec01};

case 'add_user':
// Option to insert an user.


case 'delete_user':
// Option to delete an user.


echo $str_return;

Untitled Document

Rate this Tutorial
Bad Great
Leave your comments (optional).