06 Jun 2011 @ 12:54 AM 








Setelah saya menulis Membuat Sitemap WordPress dengan Google Sitemap Generator. Kali ini saya akan membahas tentang bagaimana cara membuat file sitemap.xml. apa itu sitemap.xml…? sitemap.xml adalah sebuah file yang mengandung alamat-alamat url dari sebuah website yang dikirm ke seach engine sebagai acuan search engine untuk mencari content website.
untuk membuat file sitemap.xml bisa dengan mengetikkan satu persatu tetapi misalkan content website anda sudah ribuan artikel, apa anda mau menuliskan manual..?

di sini mau saya bahas sebuah class script php yang bisa secara otomatis akan membuat file sitemap.xml. berikut cara memasang class php script tersebut.

  1. download file sitemapgenerator-2008-01-18.zip File ini di buat oleh Felipe Ribeiro – http://feliperibeiro.com yang dapat memudahkan untuk membuat file sitemap.xml
  2. extract file tersebut di directory root website, anda akn mempunyai 2 file php yaitu SiteMapGenerator.class.php dan example.php
  3. buat file sitemap.xml dan upload ke directory root website anda.
  4. rubah permission file sitemap.xml menjadi 777. untuk operasi ini anda bisa menggunakan file manager di cpanel atau bisa juga menggunakan filezilla ftp Client.
  5. buka file example.php dan rubah url yang berada pada baris ke 4 menjadi alamat website anda
  6. sampai di sini anda sudah berhasil memasang sitemap generator untuk mengujinya anda dapat menjalankan di browser dengan url www.websiteanda.com/example.php
  7. jika berhasil maka file sitemap.xml akan terisi dengan url-url website anda. nah jika ini berhasil anda bisa mensubmitnya ke google webmaster , Baca (Submit Sitemap ke Google Webmaster Tools).

cara diatas adalah untuk membuat sitemap.xml secara custom dengan script php. jika anda menggunakan wordpress atau cms lain anda bisa menginstall pluginnya baca (Membuat Sitemap WordPress dengan Google Sitemap Generator). Selamat Mencoba



Tags Tags:
Categories: php
Posted By: asbin
Last Edit: 06 Jun 2011 @ 12 54 AM

EmailPermalinkComments (0)
 20 Aug 2009 @ 11:52 PM 








this script read the numeric and writing to the sentence. the data numeric can be covert using function. if you will use this function,  you must call function with parameter included. output this script for indonesian format sentence…

terbilang.php


using function :


          
Tags Tags: , , , ,
Categories: php
Posted By: asbin
Last Edit: 11 Jun 2010 @ 12 15 AM

EmailPermalinkComments (0)
 04 Aug 2009 @ 4:30 AM 

we have discused about dumping structure table into sql file before. now we can discus about dumping data table script using php.

this is a function to export table to data sql  file :


PHP Example :

<?


function _mysqldump_table_data($table)
{

$sql=”select * from `$table`;”;
$result=mysql_query($sql);
if( $result)
{
$num_rows= mysql_num_rows($result);
$num_fields= mysql_num_fields($result);

if( $num_rows > 0)
{
echo “/*d*/\n”;

$field_type=array();
$i=0;
while( $i < $num_fields)
{
$meta= mysql_fetch_field($result, $i);
array_push($field_type, $meta->type);
$i++;
}

//print_r( $field_type);
echo “insert into `$table` values\n”;
$index=0;
while( $row= mysql_fetch_row($result))
{
$row[0]=”””;
echo “(“;
for( $i=0; $i < $num_fields; $i++)
{
if( is_null( $row[$i]))
echo “null”;
else
{
switch( $field_type[$i])
{
case ‘int’:
echo $row[$i];
break;
case ‘string’:
case ‘blob’ :
default:
echo “‘”.mysql_real_escape_string($row[$i]).”‘”;

}
}
if( $i < $num_fields-1)
echo “,”;
}
echo “)”;

if( $index < $num_rows-1)
echo “,”;
else
echo “;”;
echo “\n”;

$index++;
}
}
}
mysql_free_result($result);

echo “\n”;
}


?>

Usage Example:

PHP Example :

<?
$con= mysql_connect ( “127.0.0.1″, “root”, “”);


header(‘Content-type: text/plain’);
header(‘Content-Disposition: attachment; filename=”dumpdata.sql”‘);
//echo “/*mysqldump.php version $mysqldump_version */\n”;
_mysqldump_table_data(‘table’);

die();

?>

for usage, you must connect to the database, then calling _mysqldump_table_data(‘table’); and enter the  table name into parameter function.

header(‘Content-type: text/plain’);
header(‘Content-Disposition: attachment; filename=”dumpdata.sql”‘);

header script used to create file sql and saved on your directory.

Tags Tags: , ,
Categories: php
Posted By: asbin
Last Edit: 04 Aug 2009 @ 04 30 AM

EmailPermalinkComments (1)
 04 Aug 2009 @ 4:12 AM 

Sometimes you might need a function to create sql table structure to entire sql file . This function will help you do that.

this is a function to export table to structure sql  file :

PHP Example :
<?

function _mysqldump_table_structure($table)
{
echo “/* Table structure for table `$table` */\n”;
if( isset($_REQUEST['sql_drop_table']))
{
echo “DROP TABLE IF EXISTS `$table`;\n\n”;
}
//if( isset($_REQUEST['sql_create_table']))    {

$sql=”show create table `$table`; “;
$result=mysql_query($sql);
if( $result){
if($row= mysql_fetch_assoc($result))
{
echo $row['Create Table'].”;\n\n”;
}
}
mysql_free_result($result);
//}

}

?>

Usage Example:

PHP Example :

<?

$con= mysql_connect ( “127.0.0.1″, “root”, “”);


header(‘Content-type: text/plain’);
header(‘Content-Disposition: attachment; filename=”dumpstructure.sql”‘);
//echo “/*mysqldump.php version $mysqldump_version */\n”;
_mysqldump_table_structure(‘table’);

die();

?>

for usage, you must connect to the database, then calling _mysqldump_table_structure(‘table’); and enter the  table name into parameter function.

header(‘Content-type: text/plain’);
header(‘Content-Disposition: attachment; filename=”dumpstructure.sql”‘);

header script used to create file sql and saved on your directory.

Tags Tags: , , ,
Categories: php
Posted By: asbin
Last Edit: 04 Aug 2009 @ 04 21 AM

EmailPermalinkComments (0)
 04 Aug 2009 @ 3:34 AM 

Author : Ravi Valmikam
this is script function import sql to the database

we have 2 function
1. mysql_import_file : simply imports a file as is
2. mysql_install_db : creates a given DB as well as imports a given SQL file for that DB

PHP Example :

<?
/* Accepts a filename and imports the SQL script in it.

Returns: true if all is well
false if something is wrong
(error message is embedded in $errmsg)

One can also use mysql_error() if this function
returns an error.

*/

function mysql_import_file($filename, &$errmsg)
{
/* Read the file */
$lines = file($filename);

if(!

$lines)
{
$errmsg = "cannot open file $filename";
return
false;
}

$scriptfile = false;

/* Get rid of the comments and form one jumbo line */
foreach($lines as $line)
{
$line = trim($line);

if(!

ereg('^--', $line))
{
$scriptfile.=" ".$line;
}
}

if(!

$scriptfile)
{
$errmsg = "no text found in $filename";
return
false;
}

/* Split the jumbo line into smaller lines */

$queries = explode(';', $scriptfile);

/* Run each line as a query */

foreach($queries as $query)
{
$query = trim($query);
if(
$query == "") { continue; }
if(!
mysql_query($query.';'))
{
$errmsg = "query ".$query." failed";
return
false;
}
}

/* All is well */
return true;
}

/* Installs a DB with a given name with the help of a given
.sql file

Returns: true if all is well
false if something is wrong
(error message is embedded in $errmsg)

One can also use mysql_error() if this function
returns an error.

*/

function mysql_install_db($dbname, $dbsqlfile, &$errmsg)
{
$result = true;

if(!

mysql_select_db($dbname))
{
$result = mysql_query("CREATE DATABASE $dbname");
if(!
$result)
{
$errmsg = "could not create [$dbname] db in mysql";
return
false;
}
$result = mysql_select_db($dbname);
}

if(!

$result)
{
$errmsg = "could not select [$dbname] database in mysql";
return
false;
}

$result = mysql_import_file($dbsqlfile, $errmsg);

return

$result;
}
?>

Usage Example:

PHP Example :

<?

$link

= mysql_connect ( "127.0.0.1", "root", "");

if(

mysql_install_db("testdb", "testdb.sql", $errmsg))
{
echo
"Success!!";
}else
{
echo
"failure: ".$errmsg."<br/>".mysql_error();
}
?>


this script is simple. you can try use on cake php by placing that function on your controller. you must call the function use $this->mysql_import_file(); if the script use on cake php controllers.

Tags Tags: , , , ,
Categories: php
Posted By: asbin
Last Edit: 04 Aug 2009 @ 03 34 AM

EmailPermalinkComments (0)
 31 Jul 2009 @ 4:19 AM 

You can download the required files at RSS WRITER

Usage:

  1. open index.php file on the file you’ve downloaded
  2. enter setting on mysql_connection database,  enter the host db, password db, user db, database name same as your database setting mysql_connect(“localhost”, “root”, “”);
    mysql_select_db(“feed”);
  3. enter the query you need to on line 21

example:

$result = mysql_query(“select * from beritas ORDER BY DESC id limit 25″);

now, you can try this script. that is very simple. good luck………

Tags Tags: , , ,
Categories: php
Posted By: asbin
Last Edit: 14 Aug 2009 @ 12 16 AM

EmailPermalinkComments (0)
 17 Jun 2009 @ 3:12 AM 

reduction date with mktime function

reduction date different with reduction number. the amount of time on php calculated on seconds unit.  because of that, to get the day time must be divided by seconds unit. 1 day have 86400 seconds, to get day time must be devided 86400.
following example :
(17-june-2009) – (1-mei-2009)    ….?

<?
$day=(mktime (0,0,0,6,17,2009) – mktime (0,0,0,5,1,2009))/86400;
$day=floor($day);
echo $day;
?>

result:  47 day.
result is 47. because between (17-june-2009) and (1-mei-2009) have 47 days.  this script is very simple but sometimes we need it to create a complicated algoritm.
Tags Tags:
Categories: php
Posted By: asbin
Last Edit: 17 Jun 2009 @ 03 12 AM

EmailPermalinkComments (0)
 11 Jun 2009 @ 5:37 AM 

The Extensible Markup Language (XML) is a markup language much like HTML or SGML. This is recommended by the World Wide Web Consortium and available as an open standard.

XML is a portable, open source language that allows programmers to develop applications that can be read by other applications, regardless of operating system and/or developmental language.

now I will talk about reading xml with php. php can read the xml script with the following code :
index.php
<?php
$xml = “”;
$f = fopen( ‘books.xml’, ‘r’ );
while( $data = fread( $f, 4096 ) ) {
$xml .= $data;
}
fclose( $f );

preg_match_all( “/\<Envelope\>(.*?)\<\/Envelope\>/s”,
$xml, $bookblocks );

foreach( $bookblocks[1] as $block )
{
preg_match_all( “/\<Filename\>(.*?)\<\/Filename\>/”,
$block, $author );
preg_match_all( “/\<MessageType\>(.*?)\<\/MessageType\>/”,
$block, $title );
preg_match_all( “/\<Owner\>(.*?)\<\/Owner\>/”,
$block, $publisher );
echo( $title[1][0].” – “.$author[1][0].” – “.
$publisher[1][0].”\n” );
}

?>

books.xml
<Envelope>
<Filename>CRQQGZNT.xml</Filename>
<MessageType>SMS:TEXT</MessageType>
<Owner>admin</Owner>
</Envelope>
because xml not server side script . xml can be read  by php to process in the server side.  script can be downloaded here
Tags Tags: , , , , , ,
Categories: php
Posted By: asbin
Last Edit: 11 Jun 2009 @ 05 37 AM

EmailPermalinkComments (2)
 27 May 2009 @ 11:44 PM 

bagi temen2 yang membutuhkan scrip barcode writer dengan php silahkan

download di sini

terima kasih……………….

AUTHOR: Walter Cattebeke
DATE: 08-July-2004
EMAIL: cachiweb@telesurf.com.py
LICENSE: This code is free. You can use it and/or modify it.
I only want to be mentioned and notified if you intend to do either.

Tags Tags:
Categories: php
Posted By: asbin
Last Edit: 29 May 2009 @ 04 59 AM

EmailPermalinkComments (0)
 20 May 2009 @ 6:36 AM 

Creating a Class with Properties and Methods on PHP programming

example (contoh):

A class can be created using code similar to the following:

class Foo
{
var $foo;
var $bar;

function setBar ($bar)
{
$this->bar = $bar;
}
function getBar ()
{
return $this->bar;
}
}

This class has the following characteristics:

* The name of the class is ‘Foo’.
* It contains the variables (properties) ‘$foo’ and ‘$bar’.
* It contains functions (methods) called ‘setBar’ and ‘getBar’.
* Function ‘setBar’ is used to insert data into the object variable ‘$bar’.
* Function ‘getBar’ is used to retrieve data from the object variable ‘$bar’.

In theory you are supposed to have a ‘set’ method and a ‘get’ method for each variable within the class, one to put data in and the other to get data out. These are commonly referred to as ‘setters’ and ‘getters’.

Note here that the syntax $this->bar is used to reference an object variable from within that object. These variables can be referenced by any function/method within the class. The syntax $bar identifies a variable whose scope is limited to the current function only.
The ‘constructor’ method

A class can contain a special method known as a ‘constructor’ which is automatically processed whenever an instance of that class is created. In PHP 4 this is a method which has the same name as the class. This can be used to set initial data for the object, as shown in the following example:

class Foo
{
var $foo;
var $bar;

function Foo ()
{
$this->foo = ‘initial value for $foo’;
$this->bar = ‘initial value for $bar’;
}
}

In PHP 5 you can use the standard name __construct() as the constructor.
Extending a Class

It is possible to create a new class which ‘extends’ an existing class. By this I mean that you can inherit all the properties and methods of the existing class, and either provide alternative code for existing methods or add completely new methods. An example of how to do this is shown below:

require_once ‘foo.class.inc’;
class Bar extends Foo
{
var $tom;
var $dick;
var $harry;

function setTom ($tom)
{
$this->tom = $tom;
}
function getTom ()
{
return $this->tom;
}
}

Note that you have to include the definition of the parent class before you can extend it.

Class Bar is now an extension of class Foo. It has the following characteristics:

* It has all the properties and methods of class Foo plus some properties and methods of its own.
* If class Bar contained a method with the same name as a method within class Foo then the Bar method would replace the Foo method.
* If class Bar does not have a constructor of its own then the constructor in class Foo will be used instead.

Creating an Object

Now that we have created a class how do we use it? The first step is to create an instance of the class known as an object. Note that you must include the definition of the class before you can create an object from that class, as shown below:

include ‘foo.class.inc’;
$object = new Foo;

Here the object is called ‘$object’, but I could have used any name. Note that it is possible to create more than one object from the same class:

include ‘foo.class.inc’;
$tom = new Foo;
$dick = new Foo;
$harry = new Foo;

Accessing an Object’s Properties and Methods

In order to perform a method within an object you need to specify both the object name and the function name as in:

$result = $tom->setFoo(‘value’);

It is also possible to access an object’s properties directly without going through a method, as in:

$var = $tom->Foo;
$tom->Foo = $var;

Although this approach is perfectly valid I should point out that if at some time in the future you decide that it is necessary to do some extra processing on the data before it is moved in or out of your object then you will have to modify all those places where the data is referenced. On the other hand if you force all object properties to be accessed though a get or set method then you will only have to change the contents of that method just the once.

You may have noticed that when you are outside of an object and you want to access the object’s properties or methods you must specify the object’s identifier as in $tom-> or $dick-> or $harry->, but when you are inside an object you can use the magic word $this-> as the object identifier.
Objects and Sessions

You may or may not be aware that you can maintain data between the execution of one script and another by using PHP’s session capability. It is also possible to save an object’s properties in this session data so that it can be reinstated by the next script within the same session. You can save an object’s properties by using the serialize() command as follows:

include ‘foo.class.inc’;
$dbobject = new Foo;


$_SESSION['dbobject'] = serialize($dbobject);

In a subsequent script you can reinstate the object to exactly the same condition by using the unserialize() command like this:

include ‘foo.class.inc’;
if (isset($_SESSION['dbobject'])) {
$dbobject = unserialize($_SESSION['dbobject']);
} else {
$dbobject = new Foo;
} // if

Tags Tags:
Categories: php
Posted By: asbin
Last Edit: 31 May 2009 @ 08 13 PM

EmailPermalinkComments (0)
\/ More Options ...
Change Theme...
  • Users » 1
  • Posts/Pages » 49
  • Comments » 50
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.