Tizag.com Webmaster Tutorials - A collection of webmaster tutorials from HTML to PHP.

Sunday, October 26, 2008

Setting Cron Job

Open putty and log in to the server using user name and password

type crontab -l to see the list of cron jobs.

type which php to see the location of the installation of php location

type crontab -e to edit the cron job.
minute hour day month day-of-week command-line-to-execute

The acceptable values for each of the 6 fields are:

FieldRange of values
minute0-59
hour0-23
day1-31
month1-12
day-of-week0-7 (where both 0 and 7 mean Sun, 1 = Mon, 2 = Tue, etc)
command-line-to-executethe command to run along with the parameters to that command if any

So if I want my cron job to run every at 9:30 pm
we Write

39 21 * * 6 /usr/bin/php /home/www/htdocs/biraj/testbiraj.php

and press ESC :wq

/usr/bin/php /=="PHP LOCATION"

home/www/htdocs/biraj/testbiraj.php == "LOCATION OF THE EXECUTABLE FILE"

for more details refer http://www.thesitewizard.com/general/set-cron-job.shtml

Monday, October 6, 2008

Upload and Read file line by line in PHP

<?php
include_once("includes/connect.php");

?>
<script language="JavaScript">
<!--
function refreshParent() {
window.opener.location.href = window.opener.location.href;

if (window.opener.progressWindow)

{
window.opener.progressWindow.close()
}
window.close();
}
//-->
</script>
<?php

if($_POST){

/*------------------| Upload the file in Server |------------------*/
//print_r($_FILES);
$max_photo_size=50000;
$upload_required=true;
$upload_dir='mails/';
$err_msg=false;
do{
if(!isset($_FILES['book_image'])){
$err_msg="The form was not sent in completely.";
break;
}else{
$book_image=$_FILES['book_image'];
}
switch ($book_image['error']){
case UPLOAD_ERR_INI_SIZE:
$err_msg = 'The size of the image is too large.';
break 2;

case UPLOAD_ERR_PARTIAL:
$err_msg = 'An error occured while uploading the files.';
break 2;

case UPLOAD_ERR_NO_FILE:
$err_msg = 'You did not select a file to upload.';
break 2;

case UPLOAD_ERR_OK:
if($book_image['size'] > $max_photo_size){
$err_msg = 'The size of the file is too large.';
}
break 2;

default:
$err_msg = 'An unknown error occured.';
break 2;
}
if(!in_array($book_image['type'], array('text/plain'))){
$err_msg = 'You need to upload a text file';
break;
}
}while (0);
if(!$err_msg){
if(!move_uploaded_file($book_image['tmp_name'], $upload_dir. $book_image['name'])){
$err_msg='Error moving file in destination';
}
}
/*---------------| Uploading file is over |---------------------*/

/*---------------| Reading file data |----------------------*/
$myFile = $upload_dir.$book_image['name'];
//$myFile = 'mails/example.txt';
//echo $myFile;
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
echo $theData;
echo "<hr/>";
fclose($fh);

/*---------------| Counting the number of results |----------------*/
$countSpace = substr_count($theData, "\n");
echo $countSpace;

$emailArray=explode("\n", $theData);
$rid = mysql_real_escape_string($_REQUEST['txt_rid']);
$wb='Y';

/*----------------| Inserting the records in the db |---------------*/
for($i=0; $i<=$countSpace; $i++){

$email = mysql_real_escape_string($emailArray[$i]);

/*-------| Save value in primary table |--------------------*/
$query0="SELECT id FROM mailaddr WHERE email like '%".$email."%'";
$query0_execute=mysql_query($query0) or die(mysql_error());
$query0_rows=mysql_num_rows($query0_execute);
if($query0_rows>=1){
$query0_result=mysql_fetch_assoc($query0_execute);
$id=$query0_result[id];
//echo $id;
}else{
$query1="INSERT INTO mailaddr (priority, email) VALUES('7','".$email."')";
echo $query1;
mysql_query($query1) or die('Insert Error 1');
}

/*-------| Get last record from primary table |------------*/
$query2="SELECT max(id) FROM mailaddr";
$query2_execute=mysql_query($query2) or die('error');
$query2_show=mysql_fetch_row($query2_execute);


/*-------| Blacklist/Whitelist Values |--------------------*/
if($query0_rows>=1){
$query3="INSERT INTO wblist (rid, sid, wb) VALUES('".$rid."', '".$id."','".$wb."')";
}else{
$query3="INSERT INTO wblist (rid, sid, wb) VALUES('".$rid."', '".$query2_show[0]."','".$wb."')";
}
mysql_query($query3) or die("Email already blacklisted or whitelisted.<br/><input type=\"button\" value=\"Close\" onclick=\"window.close();\">");

$query_insert="Data Successfully inserted";





}

unlink($myFile);
echo "<script>refreshParent();</script>";

}

?>
<body bgcolor="#B7C9E1">
<br/>
<?php
if($err_msg){
echo $err_msg;
}
?>
<form id="frmAddNewUser" enctype="multipart/form-data" method="post" action="import_whitelist.php">

<table border="0" cellspacing="0" cellpadding="0" width="300">
<tr>
<td width="33%" class="policyContent">File :</td>
<td width="67%" class="policyInput">
<input type="hidden" name="MAX_FILE_SIZE" value="16000"/>
<input type="file" name="book_image" style="border: #2D3191 2px solid;">
</td>
</tr>
<tr>
<td> ;</td>
<td> ;</td>
</tr>
<tr>
<td> ;</td>
<td class="policyContent" align="center">
<input type="hidden" name="txt_hidval" id="txt_hidval" value="0"><input type="hidden" name="txt_rid" id="txt_rid" value="<?php echo $_REQUEST['rid'];?>"><input type="Submit" value="Save" class="button"></td>
</tr>
</table>

</form>
</body>

Saturday, October 4, 2008

Display Page after Interval

<label id=d2> </label>
<script>




var milisec=0
var seconds=5
//document.frm2.d2.value='10'
document.getElementById("d2").innerHTML='5';

function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
//document.frm2.d2.value=seconds+"."+milisec
document.getElementById("d2").innerHTML=seconds+"."+milisec
setTimeout("display()",100)
}
display()

function delayer(){
if(document.getElementById("hidval").value==1){
//window.location = "http://www.apps4rent.com/payment-cpanel.html";
window.location = "validcc.html";
}else{
//window.location = "index.php";
window.location = "invalidcc.html";
}
}
setTimeout('delayer()', 5000)
</script>