Category Archives: Scripts

Emergence of several scripting languages has enabled the web programmers with an unimaginable power that really yields.

A Databse Handling Class In Php

Now this is the age of RAD (Rapid App Development Tool). To run faster in web development thins class may help you. This is simply a DBHANDLER class .

We suggest you to use the DBHANDLER Class and find its amazing potential in the modern age that is primarily governed by Rapid Application Development Tools.

class __dbConfigSys

{

var $LINK=”; var $NON=’DD';

var $HOST=”; var $USER=”; var $PASS=”; var $DB=”;

var $ERROR=”;

function  __dbConfigSys($DBHOST,$DBUSER,$DBPASS,$DBNAME) {

$this->HOST=$DBHOST; $this->USER=$DBUSER; $this->PASS=$DBPASS; $this->DB=$DBNAME;

}

function mySQLConnet() {

$LINK= @mysql_pconnect($this->HOST,$this->USER,$this->PASS,65536);

if(!$LINK) {

$this->ERROR[‘MYSQL_PCONNECT’]=’LINE 12 :’ . mysql_error() . ‘ . [mySQLConnet]';

return 0;

} else {

$this->LINK=$LINK;

$SELDB=@mysql_select_db($this->DB,$LINK);

if(!$SELDB) {

$this->ERROR[‘MYSQL_SELECT_DB’]=’LINE 18 :’ . mysql_error() . ‘ . [mySQLConnet]';

return -1;

} else {

return $SELDB;

}

}

}

function executeNonQuery($QUARY) {

if($QUARY==”) {

$this->ERROR[‘QUARY_NULL’]=’LINE 28 : NO QUERY SENT IN THE FUNCTION [executeNonQuery]';

return 0;

} else {

$this->mySQLConnet();

$SELDB=@mysql_query($QUARY);

if(!$SELDB) {

$this->ERROR[‘MYSQL_QUARY’]=’LINE 34 : PLEASE CHECK THE QUERY [ ‘ . $QUARY . ‘ ]. ‘ . mysql_error() . ‘ . [executeNonQuery]';

} else {

mysql_close($this->LINK);

return 1;

}

}

}

function resultSET($QUARY) {

if($QUARY==”) {

$this->ERROR[‘QUARY_NULL’]=’LINE 44 : NO QUERY SENT IN THE FUNCTION [executeNonQuery]';

return 0;

} else {

$this->mySQLConnet();

$SELDB=mysql_query($QUARY);

if(!$SELDB) {

$this->ERROR[‘QUARY_ERROR’]=’LINE 50 : PLEASE CHECK THE QUERY [ ‘ . $QUARY . ‘ ]. ‘ . mysql_error() . ‘ . [resultSET]';

} else {

while($RESULTSET=mysql_fetch_array($SELDB)) {

$RECORDSET[]=$RESULTSET;

}

mysql_close($this->LINK);

return $RECORDSET;

}

}

}

function noofRECORDS($QUARY) {

if($QUARY==”) {

$this->ERROR[‘QUARY_NULL’]=’LINE 44 : NO QUERY SENT IN THE FUNCTION [executeNonQuery]';

return 0;

} else {

$this->mySQLConnet();

$SELDB=@mysql_query($QUARY);

if(!$SELDB) {

$this->ERROR[‘QUARY_ERROR’]=’LINE 50 : PLEASE CHECK THE QUERY [ ‘ . $QUARY . ‘ ]. ‘ . mysql_error() . ‘ . [resultSET]';

} else {

return @mysql_num_rows($SELDB);

}

}

}

function lastID() {

$this->mySQLConnet();

return mysql_insert_id();

}

function __debug() {

$MSG='<div style=”margin-top:10px margin-buttom:10px; border:1px dashed #000000; background-color:#d8d8d8;”><ul>';

if($this->ERROR!=”) {

foreach($this->ERROR as $KEY=>$VALUE) {

$MSG.= ‘<li style=”font-family:verdana; font-size:12px; color:#ff0000;”>’ . $KEY .': ‘ .¬† $VALUE . ‘</li>';

}

echo $MSG . ‘</ul></div>';

} else {

echo ‘<div style=”margin-top:10px margin-buttom:10px; border:1px dashed #000000; background-color:#d8d8d8; font-family:verdana; font-size:12px; color:#ff0000;”>SUCCESS. CONTINUE</div>';

}

}

function check_email($mail_address) {

$pattern = “/^[\w-]+(\.[\w-]+)*@”;

$pattern .= “([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i”;

if (preg_match($pattern, $mail_address)) {

$parts = explode(“@”, $mail_address);

if (checkdnsrr($parts[1], “MX”)){

return “1”;

// return true;

} else {

return “The e-mail host is not valid.”;

// return false;

}

} else {

return “The e-mail address contains invalid charcters.”;

// return false;

}

}

}

Cross Browser Window – Open In Javascript

Now a days, browser dependent scripts like javascript create problems due to the varieties of clients and versions of different browsers. So, the programmers or the web developers should be alert to implement such scripts on web. The scripts should be necessarily cross browser compatible …..

Check the simple window.open function….

var myPopupWindow = ”;
function openPopupWindow(url)
{
//If it is already open
width=getSize();
width=width-200;
//alert(encodeURI(url));
if (!myPopupWindow.closed && myPopupWindow.location)
{
myPopupWindow.location.href = encodeURI(url);
}
else
{
myPopupWindow= window.open(encodeURI(url),name, “location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=” + width + “, height=600,top=250,left=150″);
if (!myPopupWindow.opener) myPopupWindow.opener = self;
}
//If my main window has focus – set it to the popup
if (window.focus) {myPopupWindow.focus()}
}

The web programmer can never ignore the importance of cross browser applications as the browsers of the individuals are completely obscured from the programmer at the time of programming.

WORKING WITH REST

rest-client.php

<?
$rs=”http://localhost/rest/rest-server.php”;
$qs=””;
$parray=array(‘amount’=>”15.00″);
foreach($parray as $par=>$value){
$qs=$qs.”$par=”.urlencode($value).”&”; }
$uri=”$rs?$qs” . “aid=01″;
echo $qs . “<br>” . $uri . “<br>”;
$cobj=curl_init($uri);
curl_setopt($cobj,CURLOPT_RETURNTRANSFER,1);
$xml=curl_exec($cobj);
curl_close($cobj);
echo htmlspecialchars($xml);
?>

rest-server.php

<?
$amount=$_GET[“amount”];
if ($_GET[‘aid’]!=”010915780″)
{
echo “Invalid A ID”;

}
else
{
$taxcalc=$amount;
echo “<?xml version=\”1.0\”?>”;
echo “<taxinfo>”;
echo “<result>”.$taxcalc.”</result>”;
echo “<result>”.$taxcalc * 20 .”</result>”;
echo “</taxinfo>”;
}
?>

Test It.

AJAX GET IN PHP

var http_request = false;
function makePOSTRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,…
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType(‘text/xml’);
http_request.overrideMimeType(‘text/html’);
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}
if (!http_request) {
alert(‘Cannot create XMLHTTP instance’);
return false;
}

http_request.onreadystatechange = alertContents;
http_request.open(‘GET’, url, true);
http_request.send(null);
}

function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById(‘img_spin’).style.display=’none';
alert(result);
if(result==’1′) {
document.getElementById(‘txtuser’).disabled=true
document.getElementById(‘txtpass’).disabled=true
document.getElementById(‘div_err’).style.display=’none';
}
else if(result==’0′){
document.getElementById(‘txtuser’).disabled=true
document.getElementById(‘txtpass’).disabled=true
document.getElementById(‘div_err’).style.display=’block';
}
} else {
alert(‘There was a problem with the request.’);
}
}
}

function get() {
document.getElementById(‘img_spin’).style.display=’block';
var poststr = “user=” + encodeURI( document.getElementById(“txtuser”).value ) +
“&pass=” + encodeURI( document.getElementById(“txtpass”).value );
//alert(poststr);
makePOSTRequest(‘__pro/pro-post.php?’ + poststr);
}

How TO Handle Ajax POST With PHP

var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,…
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType(‘text/xml’);
http_request.overrideMimeType(‘text/html’);
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}
if (!http_request) {
alert(‘Cannot create XMLHTTP instance’);
return false;
}

http_request.onreadystatechange = alertContents;
http_request.open(‘POST’, url, true);
http_request.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
http_request.setRequestHeader(“Content-length”, parameters.length);
http_request.setRequestHeader(“Connection”, “close”);
http_request.send(parameters);
}

function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById(‘img_spin’).style.display=’none';
//alert(result);
if(result==1) {
document.getElementById(‘txtuser’).disabled=true;
document.getElementById(‘txtpass’).disabled=true;
//alert(result);
document.getElementById(‘div_go’).style.display=’none';
document.getElementById(‘div_err’).style.display=’none';
}
else if(result==0){
document.getElementById(‘div_err’).style.display=’block';
}
} else {
alert(‘There was a problem with the request.’);
}
}
}
Call this function in OnClick Event Of Image/Button To get the effect.
function get(obj) {
document.getElementById(‘img_spin’).style.display=’block';
var poststr = “txtuser=” + encodeURI( document.getElementById(“txtuser”).value ) +
“&txtpass=” + encodeURI( document.getElementById(“txtpass”).value );
//alert(poststr);
makePOSTRequest(‘__pro/pro-post.php’, poststr);
}