Sunday, October 31, 2010
Wednesday, October 27, 2010
Simple wordpress widget
Take new php file then copy the below code to file and put the file in plugins folder and activate the plugin
Now you can see the widget in widgetarea of wordpress named 'My First Widget'
/* Plugin Name: Simple Widget */
function widget_myuniquewidget() {
echo "This is simple widget";
}
register_sidebar_widget('My First Widget','widget_myuniquewidget');
Now you can see the widget in widgetarea of wordpress named 'My First Widget'
/* Plugin Name: Simple Widget */
function widget_myuniquewidget() {
echo "This is simple widget";
}
register_sidebar_widget('My First Widget','widget_myuniquewidget');
wordpress admin menu page
/* Plugin Name: Simple Admin Menu */
add_action('admin_menu', 'mt_add_pages');
function mt_add_pages() {
add_menu_page('Main Page','Main Page', 'manage_options', 'main-page-handle', 'main_page' );
add_submenu_page('main-page-handle','Sub Page1', 'Sub Page1', 'manage_options', 'sub-page1', 'sub_page1');
add_submenu_page('main-page-handle', 'Sub Page2', 'Sub Page2', 'manage_options', 'sub-page2', 'sub_page2');
}
function main_page() {
echo "Main Page";
}
function sub_page1() {
echo "Sub Page1";
}
function sub_page2() {
echo "Sub Page2";
}
add_action('admin_menu', 'mt_add_pages');
function mt_add_pages() {
add_menu_page('Main Page','Main Page', 'manage_options', 'main-page-handle', 'main_page' );
add_submenu_page('main-page-handle','Sub Page1', 'Sub Page1', 'manage_options', 'sub-page1', 'sub_page1');
add_submenu_page('main-page-handle', 'Sub Page2', 'Sub Page2', 'manage_options', 'sub-page2', 'sub_page2');
}
function main_page() {
echo "Main Page";
}
function sub_page1() {
echo "Sub Page1";
}
function sub_page2() {
echo "Sub Page2";
}
Enable Htaccess in localhost
Open AppSer installed folder in that find conf folder and find httpd.conf file. In that file find below line(LoadModule rewrite_module modules/mod_rewrite.so)
For Example In Windows: D:\AppServ\Apache2.2\conf\
"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") or (";") symbol and save the file and restart the AppServer to work
For Example In Windows: D:\AppServ\Apache2.2\conf\
"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") or (";") symbol and save the file and restart the AppServer to work
Monday, October 25, 2010
Enable curl in php localhost Apache
Open your php.ini file and found the line 'extension=php_curl.dll' and remove the semicolon (; Here semicolon is comment). After that save the file and restart the apache server. You have done.
It is also helpful in future. Find the line 'extension=php_mcrypt.dll' and remove the semicolon before it if there. Save the file and restart the apache server.
It is also helpful in future. Find the line 'extension=php_mcrypt.dll' and remove the semicolon before it if there. Save the file and restart the apache server.
increase execution time in php
We can increase it in different ways based on server
Method 1: It will work in most servers. Add this function in top of page.
ini_set('max_execution_time', 600); //600 seconds
Method 2: We can set it by using .htaccess. Adding the below line in .htaccess file. It will work almost all servers.
max_execution_time 600
Method 3: If it is localhost. Open php.ini file and this word ('max_execution_time') where you can see like this by default max_execution_time = 30. You can change that 30 to your required based on your execution time for example (600) after that you have to restart the apache server.
Method 1: It will work in most servers. Add this function in top of page.
ini_set('max_execution_time', 600); //600 seconds
Method 2: We can set it by using .htaccess. Adding the below line in .htaccess file. It will work almost all servers.
max_execution_time 600
Method 3: If it is localhost. Open php.ini file and this word ('max_execution_time') where you can see like this by default max_execution_time = 30. You can change that 30 to your required based on your execution time for example (600) after that you have to restart the apache server.
Sunday, October 24, 2010
Create csv file in php
$data = "Id, FirstName, LastName, Email, Phone, ZipCode"."\n";
$data .= "1,'Test1','Test2','Test@gmail.com','546435','10001'"."\n";
$myFile = "userinfo.csv";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
$data .= "1,'Test1','Test2','Test@gmail.com','546435','10001'"."\n";
$myFile = "userinfo.csv";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
Saturday, October 9, 2010
difference between curl and file_get_contents
file_get_contents - It is a function to get the contents of a file(simply view source items i.e out put html file contents).
curl - It is a library to do more operations, for example get the contents like file_get_contents, sending and receiving data from one site to another site and it also supports different types of protocols like http, https, ftp, gopher, telnet, dict, file, and ldap. curl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.
You can read more about these in http://php.net/
curl - It is a library to do more operations, for example get the contents like file_get_contents, sending and receiving data from one site to another site and it also supports different types of protocols like http, https, ftp, gopher, telnet, dict, file, and ldap. curl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.
You can read more about these in http://php.net/
Sunday, September 12, 2010
Get archives by date in wordpress
Click the below link to free download for this plugin.
http://www.ziddu.com/download/12019925/posts-by-date.zip.html
http://www.ziddu.com/download/12019925/posts-by-date.zip.html
Labels:
get archives by date,
get posts by date
Tuesday, July 27, 2010
days difference in php
$date2 = '2010-06-20';
$date1 = '2010-06-24';
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);
echo $days;
some other ways are also there. can any one reply as a comments
$date1 = '2010-06-24';
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);
echo $days;
some other ways are also there. can any one reply as a comments
Monday, July 26, 2010
Sunday, July 25, 2010
Monday, July 19, 2010
Validate Image Using Javascript
function validate_image()
{
frmobj = document.frmRegistration; //Here "frmRegistration" is Form name
var image_file = frmobj.upload_file.value; /*Here "upload_file" is in this tag like input type="file" name="upload_file" */
var image_length = frmobj.upload_file.value.length;
var pos = image_file.lastIndexOf('.') + 1;
var ext = image_file.substring(pos, image_length);
var final_ext = ext.toLowerCase();
if(final_ext != 'jpg' && final_ext != 'jpeg' && final_ext != 'gif' && final_ext != 'png')
{
alert('Upload valid image');
return false;
}
return true;
}
Usage:
if(!validate_image()) return false;
{
frmobj = document.frmRegistration; //Here "frmRegistration" is Form name
var image_file = frmobj.upload_file.value; /*Here "upload_file" is in this tag like input type="file" name="upload_file" */
var image_length = frmobj.upload_file.value.length;
var pos = image_file.lastIndexOf('.') + 1;
var ext = image_file.substring(pos, image_length);
var final_ext = ext.toLowerCase();
if(final_ext != 'jpg' && final_ext != 'jpeg' && final_ext != 'gif' && final_ext != 'png')
{
alert('Upload valid image');
return false;
}
return true;
}
Usage:
if(!validate_image()) return false;
Sunday, July 18, 2010
create dynamic images in php
//Create Image By Url Method - 2
function create_image_by_url2($url)
{
$path_parts = pathinfo($url);
copy($url,$path_parts['basename']);
}
create_image_by_url2($url);
function create_image_by_url2($url)
{
$path_parts = pathinfo($url);
copy($url,$path_parts['basename']);
}
create_image_by_url2($url);
create dynamic images using php
$url = "http://technmarketing.com/wp-content/uploads/2009/03/twitter-wallpaper2.jpg";
//Create Image By Url Method - 1
function create_image_by_url1($url)
{
$target_path = $url;
$imgdir="";
$path_parts = pathinfo($url);
$file_name = $path_parts['basename'];
$imgext = $path_parts['extension'];
if($imgext=='jpg' || $imgext=='JPG')
$src_img=imagecreatefromjpeg($target_path);
if($imgext=='gif' || $imgext=='GIF')
$src_img=imagecreatefromgif($target_path);
if($imgext=='png' || $imgext=='PNG')
$src_img=imagecreatefrompng($target_path);
if($imgext=='jpeg' || $imgext=='jpeg')
$src_img=imagecreatefromjpeg($target_path);
$size = getimagesize($target_path);
$dst_img = imagecreatetruecolor($size[0],$size[1]);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$size[0],$size[1],$size[0],$size[1]);
if(($imgext=='jpg') || ($imgext=='JPG') || ($imgext=='jpeg') || ($imgext=='JPEG'))
{
imagejpeg($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='gif') || ($imgext=='GIF')){
imagegif($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='png') || ($imgext=='PNG')){
imagepng($dst_img, $imgdir.$file_name,5);
}
}
create_image_by_url1($url);
//Create Image By Url Method - 1
function create_image_by_url1($url)
{
$target_path = $url;
$imgdir="";
$path_parts = pathinfo($url);
$file_name = $path_parts['basename'];
$imgext = $path_parts['extension'];
if($imgext=='jpg' || $imgext=='JPG')
$src_img=imagecreatefromjpeg($target_path);
if($imgext=='gif' || $imgext=='GIF')
$src_img=imagecreatefromgif($target_path);
if($imgext=='png' || $imgext=='PNG')
$src_img=imagecreatefrompng($target_path);
if($imgext=='jpeg' || $imgext=='jpeg')
$src_img=imagecreatefromjpeg($target_path);
$size = getimagesize($target_path);
$dst_img = imagecreatetruecolor($size[0],$size[1]);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$size[0],$size[1],$size[0],$size[1]);
if(($imgext=='jpg') || ($imgext=='JPG') || ($imgext=='jpeg') || ($imgext=='JPEG'))
{
imagejpeg($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='gif') || ($imgext=='GIF')){
imagegif($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='png') || ($imgext=='PNG')){
imagepng($dst_img, $imgdir.$file_name,5);
}
}
create_image_by_url1($url);
Sunday, June 13, 2010
Enable Htaccess in localhost AppServ
Open AppSer installed folder in that find conf folder and find httpd.conf file. In that file find below line(LoadModule rewrite_module modules/mod_rewrite.so)
For Example In Windows: D:\AppServ\Apache2.2\conf\
"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") and save the file and restart the AppServer to work
For Example In Windows: D:\AppServ\Apache2.2\conf\
"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") and save the file and restart the AppServer to work
mysql command line windows
It is working for me like this
Set the path in command line to \mysql\bin i.e (in which directory mysql is installed)
For eg: (I had tried this one in localhost)
C:\AppServ\MySql\bin>
then enter a command mysql -u root -h localhost -p and "Press Enter" then it will ask for a password, then enter your password and "Press Enter" Then you got a message like this "Welcome to mysql moniter............... " like this
For testing type a command "Show databases;" without double Quotes now you can see the databases
Set the path in command line to \mysql\bin i.e (in which directory mysql is installed)
For eg: (I had tried this one in localhost)
C:\AppServ\MySql\bin>
then enter a command mysql -u root -h localhost -p and "Press Enter" then it will ask for a password, then enter your password and "Press Enter" Then you got a message like this "Welcome to mysql moniter............... " like this
For testing type a command "Show databases;" without double Quotes now you can see the databases
Saturday, January 30, 2010
Generate Random Value
function random_code()
{
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
$randval = '' ;
for($i = 0;$i <= 10;$i++)
{
$num = rand() % 62;
$tmp = substr($string, $num, 1);
$randval = $randval.$tmp;
}
echo $randval.uniqid();
}
random_code();
{
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
$randval = '' ;
for($i = 0;$i <= 10;$i++)
{
$num = rand() % 62;
$tmp = substr($string, $num, 1);
$randval = $randval.$tmp;
}
echo $randval.uniqid();
}
random_code();
Labels:
Generate-Random-Code,
Random-Code,
Random-UniqeId
Subscribe to:
Posts (Atom)