Tampilkan postingan dengan label php. Tampilkan semua postingan
Tampilkan postingan dengan label php. Tampilkan semua postingan

Selasa, 10 Mei 2016

PHP - Move Array to Beginning or End of array

Tidak ada komentar:
PHP - Move Array to Beginning or End of array

Move element to first array by key

$myArray = array('one' => $myArray['one']) + $myArray;


Move element to end array by key

$myArray = $myArray + array('one' => $myArray['one']);

Senin, 24 Juni 2013

Convert Date Format to YYYY-MM-DD with PHP

Tidak ada komentar:

How Convert Date Format to YYYY-MM-DD with PHP


$date = "07/12/2010";
$your_date = date("Y-m-d", strtotime($date));

Senin, 12 November 2012

How to Detect Browser Internet Explorer with PHP

Tidak ada komentar:

How to Detect Browser Internet Explorer with PHP


You know, if you are website programmer or website designer you will understand why so important to detect Internet Explorer browser, cause generaly this browser have different treatment  in processing html, css and javascript. So maybe you need different page for this browser.
So this is PHP script will help you for detect Internet Explorer Browser or not.

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], '(compatible; MSIE ')!==FALSE) {
   //action for internet explorer
   header('location:form-ie.php?idu='.$_GET['idu']);  
} else {
      //action for other browser
header('location:form.php?idu='.$_GET['idu']);
}


Senin, 22 Oktober 2012

Sejarah Bahasa Pemrograman PHP

Tidak ada komentar:

                 Sejarah Bahasa Pemrograman PHP

Logo PHP Banyak Programmer PHP tidak mengetahui sejarah dari PHP, berikut adalah sedikit sejarah pendek dari bahasa pemrograman yang sangat populer di seluruh dunia.  

PHP diciptakan oleh Rasmus Lerdorf, seorang pemrograman C yang andal. semula PHP hanya digunakan untuk mencatat jumlah pengunjung pada homepagenya. Pada waktu itu PHP masih bernama Form Interpreted (FI), yang wujudnya berupa sekumpulan skrip yang digunakan untuk mengolah data formulir dari web.
Selanjutnya Rasmus merilis kode sumber tersebut untuk umum dan menamakannya PHP/FI. Dengan perilisan kode sumber ini menjadi sumber terbuka, maka banyak pemrogram yang tertarik untuk ikut mengembangkan PHP.
zeev suraski PHPrasmus lerdorf Founder PHPandi gutsman PHP

Pada November 1997, dirilis PHP/FI 2.0. Pada rilis ini, interpreter PHP sudah diimplementasikan dalam program C. Dalam rilis ini disertakan juga modul-modul ekstensi yang meningkatkan kemampuan PHP/FI secara signifikan. Pada tahun 1997, sebuah perusahaan bernama Zend yang terdiri  dari sebuah kelompok pengembangan software yang terdiri dari Rasmus, Zeew Suraski, Andi Gutman, Stig Bakken, Shane Caraveo dan Jim Winstead bekerja selama tujuh bulan ulang interpreter PHP menjadi lebih bersih, lebih baik, dan lebih cepat. Kemudian pada Juni 1998, perusahaan tersebut merilis interpreter baru untuk PHP dan meresmikan rilis tersebut sebagai PHP 3.0 dan singkatan PHP diubah menjadi akronim berulang PHP: Hypertext Preprocessing.

zend logo php company

Pada pertengahan tahun 1999, Zend merilis interpreter PHP baru dan rilis tersebut dikenal dengan PHP 4.0. PHP 4.0 adalah versi PHP yang paling banyak dipakai pada awal abad ke-21. Versi ini banyak dipakai disebabkan kemampuannya untuk membangun aplikasi web kompleks tetapi tetap memiliki kecepatan dan stabilitas yang tinggi.
Pada Juni 2004, Zend merilis PHP 5.0. Dalam versi ini, inti dari interpreter PHP mengalami perubahan besar. Versi ini juga memasukkan model pemrograman berorientasi objek ke dalam PHP untuk menjawab perkembangan bahasa pemrograman ke arah paradigma berorientasi objek.

Kelebihan PHP dari bahasa Pemrograman lain

  1. 'Bahasa pemrograman PHP adalah sebuah bahasa script yang tidak melakukan sebuah kompilasi dalam penggunaanya.'
  2. 'Web Server yang mendukung PHP dapat ditemukan dimana - mana dari mulai apache, IIS, Lighttpd, hingga Xitami dengan konfigurasi yang relatif mudah.'
  3. 'Dalam sisi pengembangan lebih mudah, karena banyaknya milis - milis dan developer yang siap membantu dalam pengembangan.'
  4. 'Dalam sisi pemahamanan, PHP adalah bahasa scripting yang paling mudah karena memiliki referensi yang banyak.'
  5. 'PHP adalah bahasa open source yang dapat digunakan di berbagai mesin (Linux, Unix, Macintosh, Windows) dan dapat dijalankan secara runtime melalui console serta juga dapat menjalankan perintah-perintah system.'

sumber : - http://id.wikipedia.org/wiki/PHP
               - Pemrograman Web dengan PHP karya Yudhi Purwanto

Rabu, 10 Oktober 2012

Rabu, 22 Februari 2012

How to POST data with cURL PHP

Tidak ada komentar:
<?php
$url = 'http://api.myurl.com/mm/status/0/'
$data = 'name=me&address=mystreeet&phone=1234';
        $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, null);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Senin, 19 Desember 2011

How To Create Array to XML with PHP

Tidak ada komentar:
How to Create Array to XML with PHP

Extensible Markup Language (XML) is a markup language which defines a set of rules for encoding documents in a format which is both human-readable and machine-readable. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all  open standards.

<?php
$data = array(
  'name' => array(
    'first' => 'Randy',
    'last' => 'Septian'
  ),
  'phone' => array(
    'personal' => array(
      'mobile' => '085687xxxxx',
      'home' => '0217788xxxx'
    ),
    'office' => array(
      'fax' => '0217788xxxx'
    )
  ),
  'gender' => 'male'
);

$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('root');

function write(XMLWriter $xml, $data){
    foreach($data as $key => $value){
        if(is_array($value)){
            $xml->startElement($key);
            write($xml, $value);
            $xml->endElement();
            continue;
        }
        $xml->writeElement($key, $value);
    }
}
write($xml, $data);
$xml->endElement();
echo $xml->outputMemory(true);
?>

Minggu, 11 Desember 2011

Get Date Yesterday in PHP

Tidak ada komentar:
 How to get date of yesterday in php ??
$yesterday = date("Y-m-d",strtotime("-1 day"));

echo $yesterday;

Kamis, 24 November 2011

How To Insert and View Vietnam Font To Mysql And PHP

Tidak ada komentar:
Later I 've got problem with Vietnam Font when I insert Vietnam font on my web, can't save on Mysql, then i change colation with utf8_general_ci


ALTER TABLE `table-name` CHANGE  `table-name`. `field_name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL

Jumat, 18 November 2011

PHP Error Logging Reporting Handler

Tidak ada komentar:
PHP Error, Logging, Reporting and Handler 


1. error_get_last()
example:
echo $testing;print_r(error_get_last());?>
Output :
Array([type] => 8[message] => Undefined variable: testing[file] => C:\webfolder\test.php[line] => 2)



2. error_log(error,type,destination,headers)
ParameterDescription
errorRequired. The error message to log
typeOptional. Specifies the error log type.
Possible log types:
  • 0 - Default. The error is sent to the servers logging system or a file, depending on how the error_log configuration is set in the php.ini file
  • 1 - The error is sent by email to the address in the destination parameter. This message type is the only one that uses the headers parameter
  • 2 - The error is sent through the PHP debugging connection. This option is only available in PHP 3
  • 3 - The error is added to the file destination string
destinationOptional. Specifies where to send the error message. The value of this parameter depends on the value of the "type" parameter
headersOptional. Only used if the "type" parameter is "1". Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file.
example:
$test=2;
if ($test>1){error_log("A custom error has been triggered",1,"someone@example.com","From: webmaster@example.com");}?>
Output:
A custom error has been triggered


3. error_reporting(report_level)
ValueConstantDescription
1E_ERRORFatal run-time errors. Errors that can not be recovered from. Execution of the script is halted
2E_WARNINGNon-fatal run-time errors. Execution of the script is not halted
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally
16E_CORE_ERRORFatal errors at PHP startup. This is like an E_ERROR in the PHP core
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like an E_WARNING in the PHP core
64E_COMPILE_ERRORFatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine
256E_USER_ERRORFatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
512E_USER_WARNINGNon-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
1024E_USER_NOTICEUser-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
2048E_STRICTRun-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code
4096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
8191E_ALLAll errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)
example:
//Disable error reportingerror_reporting(0);
//Report runtime errorserror_reporting(E_ERROR | E_WARNING | E_PARSE);
//Report all errorserror_reporting(E_ALL);?>


4. restore_error_handler()
example:
//custom error handler functionfunction customError($errno, $errstr, $errfile, $errline)  {  echo "Custom error: [$errno] $errstr
";
  echo " Error on line $errline in $errfile
";
  }
//set user-defined error handlerset_error_handler("customError");
$test=2;
//trigger errorif ($test>1)  {  trigger_error("A custom error has been triggered");  }
//restore built-in error handlerrestore_error_handler();
//trigger error againif ($test>1)  {  trigger_error("A custom error has been triggered");  }?>
Output
Custom error: [1024] A custom error has been triggeredError on line 14 in C:\webfolder\test.php
Notice: A custom error has been triggered in C:\webfolder\test.php on line 21

Jumat, 04 November 2011

Case Studies on PHP Website Security from XSS Attack and Sql Injection

Tidak ada komentar:
XSS (Cross Side Scripting) is a way to enter tag/script HTML  (injection) in to website for disrupt thats website.
Example attack with XSS: entered HTML or Javascript Code in some form, such like Comment Form. entered comment like this

I want to enter comment with  <script>alert('this xss attack'); </scipt>

if thats website don't have XSS filtering, when the comment appear, the alert script will working.
In PHP there are so many function, where we can use for xss attack filtering, and we can combine to make own xss filtering function



function xss_filtering($text) {
     $f = stripslashes (strip_tags (htmlspecialchars ($text, ENT_QUOTES)));
    return $f;
}
$text_comment = xss_filtering($_POST['comment']);



SQL Injection is a technic for manipulation sql command ..
Example Sql Injection in login form with " 'OR 1=1;//     " , thats logic will like this

SELECT * FROM user_table WHERE username=' ' OR 1=1;// ' AND password ='anything';

the logic is true, and whos ever can enter, ok lets make anti sql injection with PHP.

function sql_injection_filtering($data){
    $filter = mysql_real_escape_string($data);
     return $filter;
}
$username = sql_injection_filtering($_POST['username']);
$password = sql_injection_filtering($_POST['password']);
if (!ctype_alnum($username) OR !ctype_alnum($password)){
    echo "Only alpha numeric";
} else {
    echo "Login Succes";
}

Kamis, 06 Oktober 2011

How to install PHP PCNTL

Tidak ada komentar:

How to install PHP-PCNTL




Create directory to your home folder or wherever you want
Ex.
me@ubuntu:# mkdir /home/me/php
Navigate to that directory.
me@ubuntu:# cd /home/me/php


Download source.
Issue command as root.
me@ubuntu:/home/me/php# sudo apt-get source php5
me@ubuntu:/home/me/php# cd php5(Release Version)/ext/pcntl
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo phpize
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo ./configure
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo make
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo make install
Copy pcntl.so to /usr/lib/php5/200***(your version)/

Ex.
me@ubuntu:/home/me/php/php5(release_version)/ext/pcntl# cp /modules/pcntl.so /usr/lib/php5/200***(your version)/

Plus:
me@ubuntu:# echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini
If pcntl.ini doesn't exist, create it and issue the command written above.


Manual PCNTL

Senin, 26 September 2011

Running a Case Sensitive Query Select String in MySql

Tidak ada komentar:
contoh / example :
I have data in table user structure like this :
_ _ _ _ _ _ _ _ _
| ID  |  Name |
-------------------
| 1    |  Andre |
-------------------
| 2    |  andre  |
----------------------

when i using Select `ID`,`Name` from user where name = 'andre';
result is 2 row in set but i just need name 'andre' not 'Andre' , so you need case sensitive string

solution :

Select `ID`,`Name` from user where binary name = 'andre';
result is 1 row in set

Sabtu, 24 September 2011

Random PHP Code with Capital, Text and Number

Tidak ada komentar:

<?php
function createRandomPassword($long=4) {
    $charsL = "abcdefghijklmnopqrstuvwxyz";
$charsU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$int = "0123456789";
    srand((double)microtime()*1000000);
    $i = 1;
    $pass = '' ;
$randStart = rand(1,3);
    while ($i <= $long) {
   
if ($randStart == 1){
$num = rand() % 26;
$tmp = substr($charsL, $num, 1);
}
if ($randStart == 2){
$num = rand() % 26;
$tmp = substr($charsU, $num, 1);
}
if ($randStart == 3){
$num = rand() % 10;
$tmp = substr($int, $num, 1);
}
        $pass = $pass . $tmp;
if ($randStart <= 2 )
$randStart = $randStart +1;
else
$randStart = $randStart -2;
        $i++;
    }
    return $pass;
}
echo createRandomPassword();  // 

Rabu, 21 September 2011

Intalasi ActiveMQ pada Ubuntu

Tidak ada komentar:
bisa di download di http://activemq.apache.org/download.html
copy folder activemq ke /opt/chmod 777 folder activemq
sudo /opt/activemq/bin/activemq start

akses http://localhost:8161/admin/ pada browser






Selasa, 20 September 2011

Menggunakan Smarty Template Engine PHP

2 komentar:

Mengapa menggunakan Smarty?
-Memisahkan logika presentasi dari logika bisnis (Kode dan desain dipisahkan)
-Jika kita menggunakan PHP inti dengan dicampur dengan HTML kemudian berantakan untuk mengelola.
-Tidak ada pengetahuan PHP diperlukan untuk mengelola template Smarty.
-Web desainer dan pengembang PHP dapat dengan mudah bekerja dan tidak saling menyalahkan. (Ketika mereka mengembangkan website besar)

Smarty menawarkan alat
- Data granular caching
- Template warisan
- Fungsional sandboxing untuk beberapa nama

Dimana menemukan?
Download paket dari smarty.net / men-download versi yang kompatibel dengan PHP Anda.

Bagaimana menginstal?
Unzip file yang didownload ke appserv smarty Anda / folder www dan menjalankan aplikasi.

Dasar sintaks di smarty yang
Pada file index.php (Di root folder aplikasi Anda)

a) Sertakan kelas smarty (Yang libs folder).
membutuhkan ('libs / Smarty.class.php');
b) Membuat obyek untuk kelas smarty yang
$ Smarty = new Smarty;
c) Menetapkan variabel
$ Smarty-> assign ("var_name", "Smarty");

Di sini:
"Var_name" adalah untuk digunakan dalam template Smarty (. Tpl file)
"Smarty" adalah nilai yang

Tambahkan Styles dan file Javascript dalam file template (. Tpl file)
Control Structure in smarty

{literal}
<link rel="stylesheet" href="css/style.css" type="text/css">
<script>
function display(){
document.write(“Welcome to smarty”);
}
</script>
{ /literal}
Conditions
{if (condition)}
----- statements ----
{/if}

{if (condition)}
----- statements ----
{else}
----- statements ----
{/if}

{if (condition)}
----- statements ----
{elseif (condition)}
----- statements ----
{/if}
{/if}

in the conditions: “eq” is for “=”, “neq” is for “!=”

Loops
{section name=i loop=$ptquestionary}
{$ptquestionary[i]}
{/section}

http://www.9lessons.info/