How to remove comments section in all pages of wordpress

Hi guys,

I removed comments section in all pages of my wordpress site in a very simple way.

Its as simple as clicking enter 😉

Just goto wp-content/themes/yourtheme/page.php

Page.php:

Change this one <div class=”comments_template”><?php comments_template(”,true); ?></div> to

<div class=”comments_template”></div>. That’s it, now you cant see any comments section in your pages no more. Enjoy 😉

Working with SQL Server Stored Procedures(Input & Output Parameters) in PHP

Now we will consider a example of changing password proedure:

We have a stored procedure with 4 parameters like email id,old password,new password & one output parameter. If output parameter shows 1 then old password which is in DB is different with typed one. Else if it is 0 then password matches to DB password.

.Net Stored Procedure:

CREATE PROCEDURE [dbo].[SP_some_ChangePassword]
@EmployeeID varchar(50), @OldPassword VARCHAR(200), @NewPassword VARCHAR(200),
@rout INT OUT
AS

IF EXISTS (SELECT * FROM Employees E INNER JOIN EmpCredentails EC ON
EC.EmployeeID = E.EmployeeID INNER JOIN UserRoles UR ON
UR.EmployeeID = E.EmployeeID
WHERE E.UserID = @EmployeeID AND EC.Password = @OldPassword)
BEGIN
Declare @EmpId int
Set @EmpId =(Select EmployeeID from Employees Where UserID = @EmployeeID)

UPDATE EmpCredentails SET Password = @NewPassword WHERE EmployeeID = @EmpId
SET @rout = 1 — Password Changed
END

ELSE
BEGIN
SET @rout = 0 –Old Password is wrong
END

HTML file:

<html>
<head>
</head>
<body>

<form action=”change.php? run=1″ method=”post” border=”0″ style=”padding-bottom:10px”>

<label for=”log” style=”padding-right:6px;”><b> Enter Old Password : </b></label>
<input class=”field” type=”password” name=”op” id=”op” value=”” size=”25″> <br/>
<label for=”log”><b> Enter New Password : </b></label>
<input class=”field” type=”password” name=”np” id=”np” value=”” size=”25″>
<input type=”submit” name=”submit” value=”Submit” class=”button2″>
</form>
</body>
</html>

PHP file:

<?php
header(“Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0”);
header(“Pragma: no-cache”);
$v1 = isset($_REQUEST[‘run’]) ? $_REQUEST[‘run’] : 0 ;
if($v1==1)
{

$a = $_POST[“op”];
$b = $_POST[“np”];

}
$serverName = “serverName\instanceName”; //

$connectionInfo = array(
‘Database’ => ‘DB’,
‘UID’ => ‘userid’,
‘PWD’ => ‘pwd’);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
echo “Connection established.<br />”;
}else{
echo “Connection could not be established.<br />”;
die( print_r( sqlsrv_errors(), true));
}

$id = ‘some@example.com’;
echo $id.'<br/>’;
$rout=1;
$query = “{call SP_some_ChangePassword( ?, ?, ?, ?)}”;
$params = array( array($id, SQLSRV_PARAM_IN),
array($a, SQLSRV_PARAM_IN),
array($b, SQLSRV_PARAM_IN),
array($rout, SQLSRV_PARAM_OUT));
$result1 = sqlsrv_query($conn, $query, $params);
if( $result1 === false )
{
echo “Error in executing statement .\n”;
die( print_r( sqlsrv_errors(), true));
}
if( $rout==0)
echo “password is wrong”;
else
echo “password is right”;
$result2 = sqlsrv_fetch_array($result1);
echo $result2;
echo “Updated”;
?>

It works well for me.. Good Luck 🙂

PHP Coding Frameworks

Popular coding standard frameworks are

1. YII

2. CodeIgniter

Now we will see how to use codeigniter:

1. Download codeigniter from this link

2. Extract the codeigniter folder from zip file & upload to your localhost(wamp/xampp server)

3. First, we make controller, create a file name hello.php within:\application\controllers. Enter following code:

<?php
class Hello extends CI_Controller{

function Hello()

{
parent::__construct();
}

function index()

{
$this->you();
}
public function you()
{
$this->load->view(‘you_view’);
}

}

?>

4.Next step, make a view. Create you_view.php within CodeIgniter \application\views. Enter just simple line code like:

1 Hello, you!

5.Now, test your application. Point your browser to http://localhost/codeigniter/index.php/Hello/ You should get like this:

Hello, you!

Validate E-Mail Script

<script>
$(document).ready(function(e) {
$(‘#email’).click(function() {
var sEmail = $(‘#txtEmail’).val();
if ($.trim(sEmail).length == 0) {
new Messi(‘Please enter valid email address’, {center: false, viewport: {top: ‘380px’, left: ‘500px’}});// this is jquery 3rd party plugin to change default alert box.
e.preventDefault();
}
if (validateEmail(sEmail)) {
$.post(“mail.php”, { txtEmail: $(‘#txtEmail’).val() },function(data) {   // This is to post url to server
//alert(“Data Loaded: ” + data);
new Messi(‘<b style=”font-family: Segoe UI;font-size:14px;”>Check Your E-Mail in Inbox/Junk Box !!</b>’,{title: ‘<b style=”font-family: Cambria;font-size:15px;”>Email Sent</b>’});

} );

}
else {
new Messi(‘<b style=”font-family: Segoe UI;font-size:14px;”>Invalid Email Address.</b>’,{title: ‘<b style=”font-family: Cambria;font-size:16px;”>Invalid Email</b>’});
e.preventDefault();
}
});
});

function validateEmail(sEmail) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(sEmail)) {
return true;
}
else {
return false;
}
}
</script>

Send Mail to an email that entered in text box

Today we will see how to send a mail that has been entered in a textbox through PHP 🙂

In Order to first send mail..add few fields in php.ini

php.ini:

SMTP = smtp.company.net
smtp_port = 25

sendmail_from = support@company.net

HTML Page:

<html>
<form method= “post” action= “mail.php” />
<table>
<tr>
<td> Enter E-Mail :<br/>
&nbsp;<div style=”background-image:url(‘./username1.png’);width:322px; height:35px;background-repeat:no-repeat; “>
<div style=”padding-left:0px;”><input type=”text” id=”to” name=”to” placeholder=” someone@redim.net” style=”font-family: Trebuchet MS;font-size: 14px;background:none;border:none; width:314px; height:28px;padding-left:6px;padding-top:3px;outline: none;” /></div>
</tr>
<tr>

<td><input name= “email” type= “image” value= “Send” src=”submit.png”/></td>
</tr>
</table>
</form>
</html>

Mail.php:

<?php

if ( isset ( $_POST [ ’email’ ])){

$to = $_POST [ “to” ];
$subject = ‘Your Company Login Details’ ;

$message = ‘Test Purpose’;
$headers = ‘From: support@company.net’ . PHP_EOL ;

mail ( $to , $subject , $message , $headers );
echo “Check your email!!” ;}
else {
echo”try again”;
} ?>

Session maintenance in PHP

Today we will see how we can maintain login sessions in php. 🙂

Here we are considering a simple example for 4 pages. One is index page(login page) and index_action,home,logout page respectively. As we are connecting login page to sql server remotely, here connection syntax will be in sql server syntax. When ever user login with different credentials which is not located in sql server db then it returns to index page again. If he enters proper credentials, then login to home page. When ever user clicks signout from homepage, session will be destroyed immediately.

Index Page:

<form id=”login”method=”post” action=”index_action.php? run=1″>

Index_action Page:

<?php
ob_start();
session_start();

header(“Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0”);
header(“Pragma: no-cache”);
$v1 = isset($_REQUEST[‘run’]) ? $_REQUEST[‘run’] : 0 ;
if($v1==1)
{

$a = $_POST[“username”];
$b = $_POST[“password”];

}
$serverName = “serverName\instanceName”;

$connectionInfo = array(
‘Database’ => ‘DBName’,
‘UID’ => ‘userid’,
‘PWD’ => ‘pwd’);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
echo “Connection established.<br />”;
}else{
echo “Connection could not be established.<br />”;
die( print_r( sqlsrv_errors(), true));
}
$query = “Stored_Procedure_name ‘$a’,’$b'”;
$params = array();
$result1 = sqlsrv_query($conn, $query, $params);
$result2 = sqlsrv_fetch_array($result1);
echo $result2[UserID];
if($result2[UserID])
{
$_SESSION[‘session_name’] = $result2[UserID];

header(“Location:home.php”);
}
else{

header(“Location:index.php?err=1”);

}

?>

Home Page:

<?PHP
session_start();

if(!isset($_SESSION[‘session_name’]))
{
header(“Location: index.php”);
}

?>

<a href=”logout.php” title=”Sign out”>Sign Out</a>

Logout Page:

<?php
session_start();
unset($_SESSION);
session_destroy();
header(“Location:index.php”);
?>

Call SQL Stored Procedure with Parameters through PHP

Hi, Lets consider a simple scenario like Username & Password of a basic form should call a stored procedure by passing this textboxes(username & password) values and then output is dispalyed.

Stored Procedure:

CREATE procedure sp_Employee1
(
@username VARCHAR(200),
@password VARCHAR(200)
)
AS
begin
if (select COUNT(*) from Employees where UserID=@username) > 0
select ‘success’ as statusmsg
else
select ‘failure’ as statusmsg
end

Description: This sp will check username from employee data and if it is valid then display success message, else failure message.

PHP File:

<html>
<form method=”post” action=”testsql2.php? run=1″>
<input type=”text” id=”un” name=”un”value=””>
<input type=”password” id=”ps” name=”ps” value=””>
<input type=”submit” value=”Submit” onsubmit=””></form>
</html>
<?php
header(“Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0”);
header(“Pragma: no-cache”);
$v1 = isset($_REQUEST[‘run’]) ? $_REQUEST[‘run’] : 0 ;
if($v1==1)
{

$a = $_POST[“un”];
$b = $_POST[“ps”];
}

$serverName = “serverName\instanceName”;

$connectionInfo = array(
‘Database’ => ‘Database’,
‘UID’ => ‘userid’,
‘PWD’ => ‘pwd’);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
echo “Connection established.<br />”;
}else{
echo “Connection could not be established.<br />”;
die( print_r( sqlsrv_errors(), true));
}

$query = “sp_Employee1 ‘$a’,’$b'”;
$params = array();
$result1 = sqlsrv_query($conn, $query, $params);
while ($result2 = sqlsrv_fetch_array($result1)){

echo $result2[statusmsg].”<br/>”;
}

Output: Show Success/Failure message based on your input(if emp username existed in database, it show success else failure).

Enjoy 🙂