Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, 10 January 2013

how to set default timezone in php?

<?php

date_default_timezone_set('Europe/London');

echo date('Y-m-d H:i:s');

?>

how to fetch all supported timezones in PHP?

<?php

$timezone_offsets = array();

foreach(timezone_identifiers_list() as $timezone_identifier)

{

$date_time_zone = new DateTimeZone($timezone_identifier);

$date_time = new DateTime('now', $date_time_zone);

$timezone_offsets[$timezone_identifier] = $date_time_zone->getOffset($date_time);

}

echo "<pre>";

print_r($timezone_offsets);

?>

Wednesday, 31 October 2012

how to refresh particular div tag content without reloading page using jquery?

// Note : First include jquery.js file.....
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_div').load('load.php').fadeIn("slow");
}, 100000); // refresh every 10000 milliseconds
</script>

//index.php

<div id="load_div">
</div>

//load.php

In this page you can write your code.
like load randam user,image etc....

Tuesday, 23 October 2012

How to pass data from one domain to another domain(cross domain) using json?‏

//Javascript code

<script type="text/javascript">

$(document).ready(function()
{

var surl =  "http://www.example.com/json.php";

email_id=document.getElementById("email").value;

$.ajax({
url: surl,
data: {email:email_id},
dataType: "jsonp",
jsonp : "callback",
jsonpCallback: "jsonpcallback"
});
});

function jsonpcallback(rtndata)
{
document.getElementById("disp_data").innerHTML=rtndata.message;
}

</script>

//json.php file code

<?php

$display="<b>HI Json</b>";

$display.="<p>HI This is testing json.</p>";

$rtnjsonobj->message = $display;

echo $_GET['callback']. '('. json_encode($rtnjsonobj) . ')';

?>

Tuesday, 16 October 2012

error page using htaccess file

first create .htaccess  file and save it.

then write below code

ErrorDocument 404 /404.html

 

here

404 means when page not found then it occurs

404.html means that page which you want to display.

 

 

Tuesday, 3 April 2012

how to make captcha in php?

Captcha Code:

<?php
session_start();

$num='';

$string = "abcdefghijklmnopqrstuvwxyz0123456789";
for($i=0;$i<7;$i++){
$num1=rand(0,35);
$num .= $string{$num1};
}

$_SESSION["num1"]=$num;

$img=imagecreatefrompng('captcha.png');
$color=imagecolorallocate($img,255,255,255);
$color1=imagecolorallocate($img,0,0,0);
imagestring($img,9,10,3,$num,30);
$fontsize=20;
$fontcolor = imagecolorallocate($img, 0, 0, 0);
$x = 0;
$y = $fontsize;

header('Content-type : image/png');
imagepng($img);
imagedestroy($img);

?>

How to use in php?

<img id="cap" style="margin-left: 15px;" src="comman/captcha.php" alt="" />

How to refresh captcha?

Call the below function  onclick

<script >
function captcha()
{
document.getElementById('cap').src = document.getElementById('cap').src+ '?';
}
</script>

Save as captcha.png file

Monday, 2 April 2012

how to check path of ffmpeg or mencoder in linux in php?

<?php
$output = shell_exec('whereis ffmpeg');
echo "<pre>".$output."</pre>";
echo "";

$output = shell_exec('whereis mencoder');
echo "<pre>".$output."</pre>";
echo "";
?>

Output in browser :

Saturday, 17 March 2012

how to backup mysql database using php?

<?php
$backfile="a.sql";
$command="mysqldump  -u root test>$backfile";//
system($command);
?>

Saturday, 3 March 2012

PHP mail with attachment

<?php

//Set Email Subject
$subject = $_POST['sub'];
$message_email=$_POST['message'];
$message_email.='<br><br><br>'.$data;

//define the from \ reply to headers
$headers = "From: darshakkumarshah@mkics.in\r\nReply-To: darshakkumarshah@mkics.in";

//create a unique boundary string to delimit different parts of the email (plain text, html, file attachment)
$random_hash = md5(date('r', time()));

//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks for sending
$attachment = chunk_split(base64_encode(file_get_contents($file_nm)));

//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"
."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the plain text message.
$message .= strip_tags($data);
$message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
."Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the html message.
$message .= $message_email;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";

//include attachment
if(isset($_POST['checkbox']))
{
$message .= "--PHP-mixed-$random_hash\r\n"
."Content-Type: application/pdf; name=".$file_nm."\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
}

//send the email
$mail = mail( $to, $subject , $message, $headers );

?>

Friday, 19 August 2011

Display data dynamically in Matrix format using PHP with pagination

<?php
$per_page = 6;
$display_columns = 3;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(*) FROM projects")));
//$pages= $pages/$display_columns;
$pages = ceil($pages / $per_page);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&amp;";
}
echo "Pages: ";
for ($i = 1; $i <= $pages; $i++) {
echo "<a " . ($i == $page ? "class=\"selected\" " : "");
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
$i="";

$sqlm="select * from projects LIMIT " . (($page - 1) * $per_page) . ", $per_page";
$rsm=mysql_query($sqlm) or die("Database Error".mysql_error());
$count = mysql_num_rows($rsm);
$padding = ($display_columns-1)-(($count-1)%$display_columns);
echo '<table cellpadding=10>';
while($row=mysql_fetch_array($rsm))
{

if($i%$display_columns == 0)
echo '<tr>';
echo '<td>';

$id=$row["id"];
$in_sql="select * from projects where id=$id";
$r=mysql_query($in_sql) or die("Database Error".mysql_error());
if($rw=mysql_fetch_array($r))
{
$image=$rw['img'];
}

?>
<td>
<img src="admin/pages/Upload/<?=$image; ?>" width="160" height="160" style="border:#999;border:double"><br />
<h4><a href="projects_view.php?id=<?=$id?>"><?=$rw['title'];?></a></h4><h4 align="center"><?=$rw['cat_id'];?></h4>
</td>
<?
echo '</td>';

if($i%$display_columns == $display_columns-1)
echo '</tr>';
$i++;
}
if($padding!=0)
{
for($i=0;$i<$padding;$i++)
echo '<td></td>';
echo '</tr>';
}
echo '</table>';


?>

Saturday, 16 July 2011

PHP: Mail with HTML and mail() function.

<?php
include ("include/config.php");

$fname=$_POST['name'];
$email="From:".$_POST['email'];
$comp=$_POST['company'];
$msg1=$_POST['message'];

$tomail="swapn_developers@yahoo.com";
$msg="Company Name : " .$comp."
"."Message : " .$msg1;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

mail($tomail,"Contact Us Message",$msg,$headers);
?>

How to Download Image , txt file or any file without save as or without open in php?

<?php

$file=$_GET['file'];//get the file name

//$file = 'monkey.gif';

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>