Wednesday, October 21, 2009
Friday, October 2, 2009
URL To PDF -PHP
function fnURL2PDF($varURL, $varFileName = "pdf.pdf", $varSavePath = "")
{
$varSocket = fsockopen("www.easysw.com", 80, $errno, $errstr, 1000);
if (!$varSocket) die("$errstr ($errno)\n");
fwrite($varSocket, "GET /htmldoc/pdf-o-matic.php?URL=" . $varURL . "&FORMAT=.pdf HTTP/1.0\r\n");
fwrite($varSocket, "Host: www.easysw.com\r\n");
fwrite($varSocket, "Referer: http://www.easysw.com/htmldoc/pdf-o-matic.php\r\n");
fwrite($varSocket, "\r\n");
$varHeaders = "";
while ($varStr = trim(fgets($varSocket, 4096)))
$varHeaders .= "$varStr\n";
$varBody = "";
while (!feof($varSocket))
$varBody .= fgets($varSocket, 4096);
if ($varSavePath != '')
{
// Save the File
$varFileHandle = @fopen($varSavePath,'w');
$varBytes = @fwrite($varFileHandle, $varBody);
}
else
{
//Download file
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE'))
Header('Content-Type: application/force-download');
else
Header('Content-Type: application/octet-stream');
if(headers_sent())
die('Some data has already been output to browser, can\'t send PDF file');
Header('Content-Length: '.strlen($varBody));
Header('Content-disposition: attachment; filename='.$varFileName);
echo $varBody;
}
return(true);
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
{
$varSocket = fsockopen("www.easysw.com", 80, $errno, $errstr, 1000);
if (!$varSocket) die("$errstr ($errno)\n");
fwrite($varSocket, "GET /htmldoc/pdf-o-matic.php?URL=" . $varURL . "&FORMAT=.pdf HTTP/1.0\r\n");
fwrite($varSocket, "Host: www.easysw.com\r\n");
fwrite($varSocket, "Referer: http://www.easysw.com/htmldoc/pdf-o-matic.php\r\n");
fwrite($varSocket, "\r\n");
$varHeaders = "";
while ($varStr = trim(fgets($varSocket, 4096)))
$varHeaders .= "$varStr\n";
$varBody = "";
while (!feof($varSocket))
$varBody .= fgets($varSocket, 4096);
if ($varSavePath != '')
{
// Save the File
$varFileHandle = @fopen($varSavePath,'w');
$varBytes = @fwrite($varFileHandle, $varBody);
}
else
{
//Download file
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE'))
Header('Content-Type: application/force-download');
else
Header('Content-Type: application/octet-stream');
if(headers_sent())
die('Some data has already been output to browser, can\'t send PDF file');
Header('Content-Length: '.strlen($varBody));
Header('Content-disposition: attachment; filename='.$varFileName);
echo $varBody;
}
return(true);
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
Random Password Generator - PHP
function fnRandomPasswordGenerator($length = 6)
{
$pass = '';
$new = '';
// all the chars we want to use
$all = explode(" ",
"a b c d e f g h i j k l m n o p q r s t u v w x y z "
."A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
."0 1 2 3 4 5 6 7 8 9");
for($i=0; $i < $length; $i++)
{
srand((double)microtime()*1000000);
$pass .= $all[rand(0,61)];
$arr[] = $all[rand(0,61)];
$new .= $arr[$i];
}
return $new;
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
{
$pass = '';
$new = '';
// all the chars we want to use
$all = explode(" ",
"a b c d e f g h i j k l m n o p q r s t u v w x y z "
."A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
."0 1 2 3 4 5 6 7 8 9");
for($i=0; $i < $length; $i++)
{
srand((double)microtime()*1000000);
$pass .= $all[rand(0,61)];
$arr[] = $all[rand(0,61)];
$new .= $arr[$i];
}
return $new;
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
Validate Email -PHP
function fnValidateEmail($varEmail)
{
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $varEmail))
return(true);
else
return(false);
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
{
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $varEmail))
return(true);
else
return(false);
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
Read From File - PHP
function fnReadFromFile($sFileName)
{
$sReturn = '';
$fHandle = fopen($sFileName, "r");
while (!feof($fHandle))
$sReturn .= fread($fHandle, 4096);
fclose($fHandle);
return($sReturn);
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
{
$sReturn = '';
$fHandle = fopen($sFileName, "r");
while (!feof($fHandle))
$sReturn .= fread($fHandle, 4096);
fclose($fHandle);
return($sReturn);
}
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
Common Validations - Javascript
//
function CheckRadio_2()
{
if(document.getElementById("checkbox_email_backup").checked)
{
successmail = CheckEmail();
if(successmail)
{
if(document.getElementById("mail_hosts").value == "")
{
alert("Invalid Mail Server");
document.getElementById("mail_hosts").focus();
return false;
}
else
return successmail;
}
else
return successmail;
}
if(document.getElementById("checkbox_ftp_backup").checked)
{
if(document.getElementById("ftp_hosts").value == "")
{
alert("Invalid FTP Server");
document.getElementById("ftp_hosts").focus();
return false;
}
else
{
return true;
}
}
}
function CheckEmail()
{
if(!ValidEmail())
{
alert("Please Enter Valid E-Mail");
document.getElementById("text_mail_to").focus();
return false;
}
else
{
return true;
}
}
function ValidEmail()
{
var EmailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
var Email = document.getElementById("text_mail_to").value;
if(Email.match(EmailReg))
return true;
else
return false;
}
function CheckRadio()
{
var success = false;
var successmail = false;
if(document.getElementById("checkbox_email_backup").checked)
{
successmail = CheckEmail();
if(successmail)
{
if(document.getElementById("mail_hosts").value == "")
{
alert("Invalid Mail Server");
document.getElementById("mail_hosts").focus();
return false;
}
}
}
else
{
successmail = true;
}
if(document.getElementById("checkbox_ftp_backup").checked)
{
if(document.getElementById("ftp_hosts").value == "")
{
alert("Invalid FTP Server");
document.getElementById("ftp_hosts").focus();
return false;
}
}
if(successmail)
{
if(document.getElementById("radio_large_size_skip").checked)
{
//document.getElementById("text_include_large_size_show").value = "";
if(document.getElementById("text_skip_large_size_show").value != "")
{
if(!IsvalidInteger(document.getElementById("text_skip_large_size_show").value))
{
alert("Invalid Integer Value");
document.getElementById("text_skip_large_size_show").value = "";
// document.getElementById("divskiperror").innerHTML = "Invalid Integer Value";
document.getElementById("text_skip_large_size_show").focus();
return false;
}
else
{
if(document.getElementById("cmbskipfile").value== "KB")
{
document.getElementById("text_skip_large_size").value = document.getElementById("text_skip_large_size_show").value * 1024;
}
if(document.getElementById("cmbskipfile").value== "MB")
{
document.getElementById("text_skip_large_size").value = document.getElementById("text_skip_large_size_show").value * 1024*1024;
}
//document.getElementById("divskiperror").innerHTML = "";
success = true;
}
}
else
{
alert("Please Enter Value For 'Skip Larger' Option");
document.getElementById("text_skip_large_size_show").focus();
//success = false;
return false;
}
}
if(document.getElementById("radio_large_size_include").checked)
{
//document.getElementById("text_skip_large_size_show").value = "";
if(document.getElementById("text_include_large_size_show").value != "")
{
if(!IsvalidInteger(document.getElementById("text_include_large_size_show").value))
{
alert("Invalid Integer Value");
document.getElementById("text_include_large_size_show").value = "";
//document.getElementById("divincludeerror").innerHTML = "Invalid Integer Value";
document.getElementById("text_include_large_size_show").focus();
return false;
}
else
{
if(document.getElementById("cmbincludefile").value== "KB")
{
document.getElementById("text_include_large_size").value = document.getElementById("text_include_large_size_show").value * 1024;
}
if(document.getElementById("cmbincludefile").value== "MB")
{
document.getElementById("text_include_large_size").value = document.getElementById("text_include_large_size_show").value * 1024*1024;
}
//document.getElementById("divincludeerror").innerHTML = "";
success = true;
}
}
else
{
alert("Please Enter Value For 'Include Larger File' Option");
document.getElementById("text_include_large_size_show").focus();
return false;
//success = false;
}
}
}
if(successmail)
{
return true;
}
else
{
return false;
}
}
function IsvalidInteger(val)
{
if(isInteger(val))
return true;
else
return false;
}
function isInteger(val){
for(var i=0;i1){return false;}
var string="1234567890";
if (string.indexOf(num)!=-1){return true;}
return false;
}
function folderview(cfolderval)
{
document.FileList.cfolder.value = cfolderval;
document.FileList.submit();
}
function Assign(count)
{
document.getElementById("hidden_count").value = count;
}
function CheckAll()
{
var count = document.getElementById("hidden_count").value;
for(i = 1; i <= count ; i++)
{
document.getElementById("chb_"+ i).checked = true;
// document.getElementById("chb_" + rootItem).checked = true;
}
}
function UnCheckAll()
{
var count = document.getElementById("hidden_count").value;
for(i = 1; i <= count ; i++)
{
document.getElementById("chb_"+ i).checked = false;
// document.getElementById("chb_" + rootItem).checked = true;
}
}
function checkpath()
{
if(document.getElementById("select_send_type").value =="send_mail")
{
if(document.getElementById("sendmail_path_1").value == "")
{
alert("Please Enter The Sendmail Path");
return false;
}
else
return true;
}
else
return true;
}
//
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
function CheckRadio_2()
{
if(document.getElementById("checkbox_email_backup").checked)
{
successmail = CheckEmail();
if(successmail)
{
if(document.getElementById("mail_hosts").value == "")
{
alert("Invalid Mail Server");
document.getElementById("mail_hosts").focus();
return false;
}
else
return successmail;
}
else
return successmail;
}
if(document.getElementById("checkbox_ftp_backup").checked)
{
if(document.getElementById("ftp_hosts").value == "")
{
alert("Invalid FTP Server");
document.getElementById("ftp_hosts").focus();
return false;
}
else
{
return true;
}
}
}
function CheckEmail()
{
if(!ValidEmail())
{
alert("Please Enter Valid E-Mail");
document.getElementById("text_mail_to").focus();
return false;
}
else
{
return true;
}
}
function ValidEmail()
{
var EmailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
var Email = document.getElementById("text_mail_to").value;
if(Email.match(EmailReg))
return true;
else
return false;
}
function CheckRadio()
{
var success = false;
var successmail = false;
if(document.getElementById("checkbox_email_backup").checked)
{
successmail = CheckEmail();
if(successmail)
{
if(document.getElementById("mail_hosts").value == "")
{
alert("Invalid Mail Server");
document.getElementById("mail_hosts").focus();
return false;
}
}
}
else
{
successmail = true;
}
if(document.getElementById("checkbox_ftp_backup").checked)
{
if(document.getElementById("ftp_hosts").value == "")
{
alert("Invalid FTP Server");
document.getElementById("ftp_hosts").focus();
return false;
}
}
if(successmail)
{
if(document.getElementById("radio_large_size_skip").checked)
{
//document.getElementById("text_include_large_size_show").value = "";
if(document.getElementById("text_skip_large_size_show").value != "")
{
if(!IsvalidInteger(document.getElementById("text_skip_large_size_show").value))
{
alert("Invalid Integer Value");
document.getElementById("text_skip_large_size_show").value = "";
// document.getElementById("divskiperror").innerHTML = "Invalid Integer Value";
document.getElementById("text_skip_large_size_show").focus();
return false;
}
else
{
if(document.getElementById("cmbskipfile").value== "KB")
{
document.getElementById("text_skip_large_size").value = document.getElementById("text_skip_large_size_show").value * 1024;
}
if(document.getElementById("cmbskipfile").value== "MB")
{
document.getElementById("text_skip_large_size").value = document.getElementById("text_skip_large_size_show").value * 1024*1024;
}
//document.getElementById("divskiperror").innerHTML = "";
success = true;
}
}
else
{
alert("Please Enter Value For 'Skip Larger' Option");
document.getElementById("text_skip_large_size_show").focus();
//success = false;
return false;
}
}
if(document.getElementById("radio_large_size_include").checked)
{
//document.getElementById("text_skip_large_size_show").value = "";
if(document.getElementById("text_include_large_size_show").value != "")
{
if(!IsvalidInteger(document.getElementById("text_include_large_size_show").value))
{
alert("Invalid Integer Value");
document.getElementById("text_include_large_size_show").value = "";
//document.getElementById("divincludeerror").innerHTML = "Invalid Integer Value";
document.getElementById("text_include_large_size_show").focus();
return false;
}
else
{
if(document.getElementById("cmbincludefile").value== "KB")
{
document.getElementById("text_include_large_size").value = document.getElementById("text_include_large_size_show").value * 1024;
}
if(document.getElementById("cmbincludefile").value== "MB")
{
document.getElementById("text_include_large_size").value = document.getElementById("text_include_large_size_show").value * 1024*1024;
}
//document.getElementById("divincludeerror").innerHTML = "";
success = true;
}
}
else
{
alert("Please Enter Value For 'Include Larger File' Option");
document.getElementById("text_include_large_size_show").focus();
return false;
//success = false;
}
}
}
if(successmail)
{
return true;
}
else
{
return false;
}
}
function IsvalidInteger(val)
{
if(isInteger(val))
return true;
else
return false;
}
function isInteger(val){
for(var i=0;i
var string="1234567890";
if (string.indexOf(num)!=-1){return true;}
return false;
}
function folderview(cfolderval)
{
document.FileList.cfolder.value = cfolderval;
document.FileList.submit();
}
function Assign(count)
{
document.getElementById("hidden_count").value = count;
}
function CheckAll()
{
var count = document.getElementById("hidden_count").value;
for(i = 1; i <= count ; i++)
{
document.getElementById("chb_"+ i).checked = true;
// document.getElementById("chb_" + rootItem).checked = true;
}
}
function UnCheckAll()
{
var count = document.getElementById("hidden_count").value;
for(i = 1; i <= count ; i++)
{
document.getElementById("chb_"+ i).checked = false;
// document.getElementById("chb_" + rootItem).checked = true;
}
}
function checkpath()
{
if(document.getElementById("select_send_type").value =="send_mail")
{
if(document.getElementById("sendmail_path_1").value == "")
{
alert("Please Enter The Sendmail Path");
return false;
}
else
return true;
}
else
return true;
}
//
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
Validation (Select ,selectedCount,checkpassword) - Javascript
//
function setSelectOptions(the_form, the_select, do_check)
{
var selectObject = document.forms[the_form].elements[the_select];
var selectCount = selectObject.length;
for (var i = 0; i < selectCount; i++) {
selectObject.options[i].selected = do_check;
} // end for
return true;
}
function selectedCount(the_form, the_select)
{
var count = 0;
var selectObject = document.forms[the_form].elements[the_select];
var selectCount = selectObject.length;
for (var i = 0; i < selectCount; i++) {
if (selectObject.options[i].selected) count = count + 1;
} // end for
return count;
}
function checkpassword()
{
if(document.getElementById("oldpassword").value == "")
{
alert("Pleae Enter Old Password Value");
document.getElementById("oldpassword").focus();
return false;
}
if(document.getElementById("newpassword").value == "")
{
alert("Pleae Enter New Password Value");
document.getElementById("newpassword").focus();
return false;
}
if(document.getElementById("confirmnewpassword").value == "")
{
alert("Pleae Enter Confirm New Password Value");
document.getElementById("confirmnewpassword").focus();
return false;
}
if(document.getElementById("newpassword").value != null && document.getElementById("confirmnewpassword").value != null)
{
if(document.getElementById("newpassword").value != document.getElementById("confirmnewpassword").value)
{
alert("New Password AND Confirm New Password should be same");
document.getElementById("newpassword").value = "";
document.getElementById("confirmnewpassword").value = "";
document.getElementById("newpassword").focus();
return false;
}
}
}
//
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
function setSelectOptions(the_form, the_select, do_check)
{
var selectObject = document.forms[the_form].elements[the_select];
var selectCount = selectObject.length;
for (var i = 0; i < selectCount; i++) {
selectObject.options[i].selected = do_check;
} // end for
return true;
}
function selectedCount(the_form, the_select)
{
var count = 0;
var selectObject = document.forms[the_form].elements[the_select];
var selectCount = selectObject.length;
for (var i = 0; i < selectCount; i++) {
if (selectObject.options[i].selected) count = count + 1;
} // end for
return count;
}
function checkpassword()
{
if(document.getElementById("oldpassword").value == "")
{
alert("Pleae Enter Old Password Value");
document.getElementById("oldpassword").focus();
return false;
}
if(document.getElementById("newpassword").value == "")
{
alert("Pleae Enter New Password Value");
document.getElementById("newpassword").focus();
return false;
}
if(document.getElementById("confirmnewpassword").value == "")
{
alert("Pleae Enter Confirm New Password Value");
document.getElementById("confirmnewpassword").focus();
return false;
}
if(document.getElementById("newpassword").value != null && document.getElementById("confirmnewpassword").value != null)
{
if(document.getElementById("newpassword").value != document.getElementById("confirmnewpassword").value)
{
alert("New Password AND Confirm New Password should be same");
document.getElementById("newpassword").value = "";
document.getElementById("confirmnewpassword").value = "";
document.getElementById("newpassword").focus();
return false;
}
}
}
//
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script
Subscribe to:
Posts (Atom)