Archive for January 2013

Exception handling in php when using mysql statements.

Exception handling in php when using mysql statements.

try { 
                        if(!@mysql_connect($db['hostname'],$db['username'],$db['password'])){
                            throw new Exception("Database connection failed. Please correct it and continue.");
                        } 
                    } 
                    catch(exception $e) {
                        echo $e->getMessage();
                        exit;
                    }

Formas de Entrar y salir de PHP

Para interpretar un archivo, php símplemente interpreta el texto del archivo hasta que encuentra uno de los carácteres especiales que delimitan el inicio de código PHP. El intérprete ejecuta entonces todo el código que encuentra, hasta que encuentra una etiqueta de fin de código, que le dice al intérprete que siga ignorando el código siguiente. Este mecanismo permite embeber código PHP dentro de HTML: todo lo que está fuera de las etiquetas PHP se deja tal como está, mientras que el resto se interpreta como código.

Hay cuatro conjuntos de etiquetas que pueden ser usadas para denotar bloques de código PHP. De estas cuatro, sólo 2 (<?php. . .?> y <script language="php">. . .</script>) están siempre disponibles; el resto pueden ser configuradas en el fichero de php.ini para ser o no aceptadas por el intérprete. Mientras que el formato corto de etiquetas (short-form tags) y el estilo ASP (ASP-style tags) pueden ser convenientes, no son portables como la versión de formato largo de etiquetas. Además, si se pretende embeber código PHP en XML o XHTML, será obligatorio el uso del formato <?php. . .?> para la compatibilidad con XML.

Las etiquetas soportadas por PHP son:

Ejemplo: Formas de escapar de HTML

1. <?php echo("si quieres servir documentos XHTML o XML, haz como aquí\n"); ?>

2. <? echo ("esta es la más simple, una instrucción de procesado SGML \n"); ?>

<?= expression ?> Esto es una abreviatura de "<? echo expression ?>"

3. <script language="php">

echo ("muchos editores (como FrontPage) no

aceptan instrucciones de procesado");

</script>

4. <% echo ("Opcionalmente, puedes usar las etiquetas ASP"); %>

<%= $variable; # Esto es una abreviatura de "<% echo . . ." %>

El método primero, <?php. . .?>, es el más conveniente, ya que permite el uso de PHP en código XML como XHTML.

El método segundo no siempre está disponible. El formato corto de etiquetas está disponible con la función short_tags() (sólo PHP 3), activando el parámetro del fichero de configuración de PHP short_open_tag, o compilando PHP con la opción --enable-short-tags del comando configure. Aunque esté activa por defecto en php.ini-dist, se desaconseja el uso del formato de etiquetas corto.

El método cuarto sólo está disponible si se han activado las etiquetas ASP en el fichero de configuración: asp_tags.

nota: El soporte de etiquetas ASP se añadió en la versión 3.0.4.

nota: No se debe usar el formato corto de etiquetas cuando se desarrollen aplicaciones o bibliotecas con intención de redistribuirlas, o cuando se desarrolle para servidores que no están bajo nuestro control, porque puede ser que el formato corto de etiquetas no esté soportado en el servidor. Para generar código portable y redistribuíble, asegúrate de no usar el formato corto de etiquetas.

La etiqueta de fin de bloque incluirá tras ella la siguiente línea si hay alguna presente. Además, la etiqueta de fin de bloque lleva implícito el punto y coma; no necesitas por lo tanto añadir el punto y coma final de la última línea del bloque PHP.

PHP permite estructurar bloques como:

Ejemplo: Métodos avanzados de escape

<?php

if ($expression) {

?>

<strong>This is true.</strong>

<?php

} else {

?>

<strong>This is false.</strong>

<?php

}

?>

Este ejemplo realiza lo esperado, ya que cuando PHP encuentra las etiquetas ?> de fin de bloque, empieza a escribir lo que encuentra tal cual hasta que encuentra otra etiqueta de inicio de bloque. El ejemplo anterior es, por supuesto, inventado. Para escribir bloques grandes de texto generamente es más eficiente separalos del código PHP que enviar todo el texto mediante las funciones echo(), print() o similares.

PHP Basic syntax

Escaping from HTML

When PHP parses a file, it looks for opening and closing tags, which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows php to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. Most of the time you will see php embedded in HTML documents, as in this example.

<p>This is going to be ignored.</p>

<?php echo 'While this is going to be parsed.'; ?>

<p>This will also be ignored.</p>

You can also use more advanced structures:

Example#1 Advanced escaping

 

<?php

if ($expression) {

?>

<strong>This is true.</strong>

<?php

} else {

?>

<strong>This is false.</strong>

<?php

}

?>

This works as expected, because when PHP hits the ?> closing tags, it simply starts outputting whatever it finds (except for an immediately following newline - see instruction separation ) until it hits another opening tag. The example given here is contrived, of course, but for outputting large blocks of text, dropping out of PHP parsing mode is generally more efficient than sending all of the text through echo() or print().

There are four different pairs of opening and closing tags which can be used in php. Two of those, <?php ?> and <script language="php"> </script>, are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.

Note: Also note that if you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards.

Example#2 PHP Opening and Closing Tags

 

1. <?php echo 'if you want to serve XHTML or XML documents, do like this'; ?>

2. <script language="php">

echo 'some editors (like FrontPage) don\'t

like processing instructions';

</script>

3. <? echo 'this is the simplest, an SGML processing instruction'; ?>

<?= expression ?> This is a shortcut for "<? echo expression ?>"

4. <% echo 'You may optionally use ASP-style tags'; %>

<%= $variable; # This is a shortcut for "<% echo . . ." %>

While the tags seen in examples one and two are both always available, example one is the most commonly used, and recommended, of the two.

Short tags (example three) are only available when they are enabled via the short_open_tag php.ini configuration file directive, or if php was configured with the --enable-short-tags option.

Note: If you are using PHP 3 you may also enable short tags via the short_tags() function. This is only available in PHP 3!

ASP style tags (example four) are only available when they are enabled via the asp_tags php.ini configuration file directive.

Note: Support for ASP tags was added in 3.0.4.

Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

Preventing MySQL Injection with PHP

SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on your database.

We can get two expected responses with a correct injection inserted, one is when the sentence is returning the same result withouth injection, and other with blank results, error page or redirection, or defaulted. The results will be diferent if we use AND or OR sintax in the injected sentence. Let me explain:

- OR sintax: could be used to display multiple results from an abused injection.
- AND sintax: could be used to guess values, as deterministic operator.

It would be usefull to determinate different attack vectors in MySQL injection to stress the database and get it's structure:

- The use of INTO OUTFILE, or LOADFILE. The use of files will help a lot in several attack vectors.

SQL Injection Example


$name = "Sachin";
$query = "SELECT * FROM Players WHERE name= '$name'";
echo "Ordinary: " . $query . "
";

// user input that uses SQL Injection
$name_bad = "' OR 1'";

// our MySQL query builder, however, not a very safe one
$query_bad = "SELECT * FROM Players WHERE name= '$name_bad'";

// display what the new query will look like, with injection
echo "Injection: " । $query_bad;

Output


Normal: SELECT * FROM Players WHERE name= 'sachin

Injection: SELECT * FROM Players WHERE name= '' OR 1''

For Prevention - mysql_real_escape_string()

//NOTE: you must be connected to the database to use this function!
// connect to MySQL

$name_bad = "' OR 1'";

$name_bad = mysql_real_escape_string($name_bad);

$query_bad = "SELECT * FROM players name= '$name_bad'";
echo "Escaped Bad Injection:
" . $query_bad . "
";


$name_evil = "'; DELETE FROM players 1 or name= '";

$name_evil = mysql_real_escape_string($name_evil);

$query_evil = "SELECT * FROM Players WHERE name = '$name_evil'";
echo "Escaped Evil Injection:
" । $query_evil;

Notice that those evil quotes have been escaped with a backslash \, preventing the injection attack. Now all these queries will do is try to find a username that is just completely ridiculous:

  • Bad: \' OR 1\'
  • Evil: \'; DELETE FROM customers WHERE 1 or username = \'

Gunanya Sesion Di PHP


Apa sih gunanya session di PHP?
Secara umum, session digunakan untuk menyimpan suatu informasi antar proses request, baik request dalam bentuk POST atau GET. Bingung yah ?? He.. he.. he… OK saya akan ambil contoh untuk menggambarkan hal ini.

Salah satu contoh yang menggambarkan penggunaan session adalah proses login. Dalam hal ini user akan memasukkan usernamenya melalui form login. Setelah login berhasil, user tersebut dihadapkan pada link menu navigasi yang menuju ke beberapa halaman web. Nah… apabila kita ingin username tersebut akan selalu tampil atau tercatat di halaman-halaman web tersebut, maka username tadi haruslah disimpan dalam session.

Untuk memudahkan lagi pemahaman, silakan Anda buat script yang menggambarkan keadaan di atas.

Pertama-tama kita buat form login terlebih dahulu

login.htm

<form method="post" action="submit.php">
Usename <input type=text name="username">
Password <input type="password" name="password">
<input type="submit" name="submit" value="Submit">
</form>
Nah… selanjutnya kita buat script untuk mengolah proses login. Oya, dalam hal ini andaikan password login diabaikan dahulu ya… karena saya akan fokuskan pembahasan ke konsep session, bukan proses loginnya. Dengan arti lain, untuk contoh ini anggap saja proses loginnya sukses. Login dikatakan sukses bila password yang dimasukkan user yang bersangkutan ketika dalam form login sama dengan passwordnya yang tersimpan dalam aplikasi.

submit.php

<?php
$namauser = $_POST['username'];
$password = $_POST['password'];

if (login sukses)
{
echo "<p>Selamat datang ".$namauser."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";
}

?>
Dari script di atas tampak bahwa username akan muncul atau dikenal di halaman submit.php. Username ini akan ditampilkan di ucapan selamat datang. Mengapa username ini dikenal di halaman ini? Ya… karena halaman submit.php ini merupakan halaman tujuan langsung setelah proses request melalui form login. Selanjutnya perhatikan, bahwa setelah login sukses terdapat 3 link menuju ke suatu halaman tertentu. Harapan kita, di setiap halaman tersebut username akan selalu tercatat dan ditampilkan. OK… kita buat script untuk masing-masing halaman tersebut.

hal1.php

<?php

echo "<h1>Ini halaman pertama</h1>";
echo "<p>Anda login sebagai ".$namauser."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
hal2.php

<?php

echo "<h1>Ini halaman kedua</h1>";
echo "<p>Anda login sebagai ".$namauser."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
hal3.php

<?php

echo "<h1>Ini halaman ketiga</h1>";
echo "<p>Anda login sebagai ".$namauser."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
Nah… Anda perhatikan bahwa dalam ketiga script masing-masing halaman tujuan, username akan ditampilkan dalam statu login. Namun apa yang terjadi bila Anda menuju ke halaman-halaman tersebut? Munculkah username tersebut? Bim… salabim… ternyata username tidak muncul. Sehingga dari contoh ini dapat kita simpulkan bahwa username ini hanya akan dikenal pada proses request pertama (login), setelah itu bila menuju ke halaman-halaman lain pada link (proses request kedua, ketiga dst…) maka username tersebut tidak dikenali lagi. So… gimana donk, supaya username tersebut masih bisa dikenali? Yup… kita bisa menggunakan session untuk menyimpan username tersebut. Kenapa kok istilahnya ‘bisa’, bukannya ‘harus’ ? Ya… karena penggunaan session ini merupakan salah satu cara saja, cara yang lain Anda bisa menggunakan cookies.

OK… jadi kita bisa menggunakan session, lantas caranya bagaimana menyimpan username ini ke dalam session? Caranya adalah memberikan perintah berikut ini:

$_SESSION['namauser'] = $username;
Perintah di atas disisipkan pada script submit.php. Oya.. jangan lupa sebelum perintah tersebut diberikan, session harus dijalankan terlebih dahulu dengan perintah session_start(). Sehingga isi dari script submit.php menjadi seperti ini

submit.php

<?php
session_start();

$namauser = $_POST['username'];
$password = $_POST['password'];

if (login sukses)
{
$_SESSION['namauser'] = $namauser;

echo "<p>Selamat datang ".$namauser."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";
}

?>
Secara umum, perintah untuk menyimpan nilai ke dalam session adalah sebagai berikut

$_SESSION['nama session'] = value;
Mmm… untuk nama session tidak boleh ada spasi. Kita tidak hanya bisa menyimpan suatu nilai berbentuk tunggal ke dalam session, namun bisa juga nilai berupa array.

Sekarang… bagaimana cara menampilkan nilai yang telah tersimpan dalam session? ya… caranya hanya dengan memanggil sessionnya. Berikut ini contoh untuk menampilkan username yang telah disimpan ke dalam session pada kasus di atas.

submit.php

<?php
session_start();

$namauser = $_POST['username'];
$password = $_POST['password'];

if (login sukses)
{
$_SESSION['namauser'] = $namauser;

echo "<p>Selamat datang ".$_SESSION['namauser']."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";
}

?>
Jangan lupa untuk menerapkan hal yang sama pada ketiga halaman lain.

hal1.php

<?php
session_start();

echo "<h1>Ini halaman pertama</h1>";
echo "<p>Anda login sebagai ".$_SESSION['namauser']."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
hal2.php

<?php
session_start();

echo "<h1>Ini halaman kedua</h1>";
echo "<p>Anda login sebagai ".$_SESSION['namauser']."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
hal3.php

<?php
session_start();

echo "<h1>Ini halaman ketiga</h1>";
echo "<p>Anda login sebagai ".$_SESSION['namauser']."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
Oya… satu lagi, setiap akan menampilkan nilai session perintah session_start() harus diberikan terlebih dahulu. Perhatikan pada script di atas untuk melihat hal ini!

Setelah menggunakan session, dapat Anda lihat bahwa username ini akan selalu tampak pada setiap halaman yang ada.

Nah… mungkin ada pertanyaan lain. Bagaimana cara menghapus nilai session yang telah tersimpan? Nilai session ini akan terhapus otomatis begitu browser ditutup atau keluar dari browser. Cara lain adalah dengan menggunakan perintah session_destroy() atau unset($_SESSION['nama session']). Bedanya apa antara kedua perintah tersebut? session_destroy() digunakan untuk menghapus semua session. Jadi, misalkan dalam script Anda terdapat 10 nama session, dan misalkan Anda ingin menghapus semua session tersebut maka gunakan session_destroy(). Lalu unset($_SESSION['nama session']) digunakan untuk menghapus session tertentu saja.

Konsep penghapusan nilai session ini, dapat diterapkan pada proses logout. Karena pada prinsipnya proses logout ini adalah menghapus nilai session (dalam hal ini adalah username) yang telah tersimpan. Berikut ini contoh script logout.

logout.php

<?php
session_start();

unset($_SESSION['namauser']);
echo "Anda telah logout";
?>
Apabila script logout ini dijalankan, maka username yang telah tersimpan tadi tidak akan muncul lagi di halaman-halaman yang ada.

Manfaat session yang lain adalah dapat mencegah user mengakses halaman-halaman tertentu yang sifatnya private tanpa melakukan login (by pass). Dalam contoh di atas, Anda akan dapat mengakses halaman 1, halaman 2 dan 3 secara langsung tanpa proses login terlebih dahulu. Nah… dengan session, Anda dapat membuat ketiga halaman tersebut tidak bisa diakses oleh user yang masuk tanpa proses login. Idenya adalah dengan mendeteksi session username. Pendeteksian ini dilakukan di ketiga halaman tersebut. Bila terdeteksi nilai session username ini masih kosong, maka dianggap user yang mengakses tersebut tidak melakukan login terlebih dahulu, sehingga akses harus diblok. Berikut ini script untuk mendeteksi session username yang masih kosong.

cek.php

<?php
session_start();

if (!isset($_SESSION['namauser']))
{
echo "Anda belum login";
exit;
}

?>
Script di atas nantinya akan disisipkan ke ketiga halaman private menggunakan include(). Perintah ini disisipkan sebelum menampilkan konten yang ada pada halaman tersebut. Berikut ini contoh menyisipkan script cek.php ke halaman pertama. Untuk halaman yang lain, caranya sama.

hal1.php

<?php
session_start();
include "cek.php";

echo "<h1>Ini halaman pertama</h1>";
echo "<p>Anda login sebagai ".$_SESSION['namauser']."</p>";
echo "<p>Berikut ini menu navigasi Anda</p>";
echo "<p><a href='hal1.php'>Menu 1</a> <a href='hal2.php'>Menu 2</a> <a href='hal3.php'>Menu 3</a></p>";

?>
Begitu terdeteksi user yang mengakses halaman tersebut tanpa login, maka akan muncul ‘Anda belum login’, sedangkan konten halaman aslinya tidak akan muncul. Hal ini karena efek dari perintah ‘exit’. Penjelasan ini pernah saya tulis di artikel Membuat Autentifikasi User dengan PHP.

OK… demikian penjelasan penggunaan session dan manfaatnya. Mudah-mudahan penjelasan panjang lebar ini bisa bermanfaat bagi Anda semuanya.

Hire Php Web Developer India Articles on opensourcexperts.com

Hello Friends,

PHP Known as Hypertext Preprocessor, is a widely used and general-purpose scripting language it was originally designed for PHP Web Development Application, to produce dynamic web pages. PHP is the widely-used free and efficient alternative to other competitors. All types of open source PHP code and applications are available on Open Source Related Materials.

Open Source Expert PHP Web Development Company in India

Indian Php Web Design Website Development Companies are Expert to use PHP WordPress Joomla Open source technologies for Custom Web Application Development in India

Global Corporate Companies are Hiring PHP Open Source Expert Developers Designers and Programmers from Indian Web Development Company

This all information can be used to get various leads and detail about Open Source Technologies like PHP WordPress Joomal etc.. Also it helps to find Company Provide Outsource Web Development Services like Outsourcing PHP Projects, Offshore Web Development, Web Developers India, Open Source Web Development, Open Source Web Developer, etc..

Thanks & Regards

www.WeTheDevelopers.com

Create CRUD Model

CRUD is stand for:
  1. Create
  2. Read
  3. Update
  4. Delete
Through this model you can create record in a database like mySQL, SQL, Oracle etc. You can Read or retrieve your records, update and delete.

How this model can work, i will explain it further.
  

Almacenamiento de objetos binarios (imagenes, codigo, etc.) en MySQL desde PHP

Un tema interesante en Mysql es usar la base de datos para guardar además de datos de tipo texto datos binarios como por ejemplo código html o imágenes.
El primer paso es crear la base de datos:

CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
descripction CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
);

El siguiente script puede usarse para insertar objetos binarios en la base de datos desde un browser. Notar que se usa el tag input type=”file” de un form html para subir un archivo.


<HTML>
<HEAD><TITLE>Almacenamiento de datos binarios en una base
de datos MySql</TITLE></HEAD>
<BODY>
<?php
if ($submit) {
//codigo que se ejecuta si se presiono el botón submit
MYSQL_CONNECT( "localhost", "root", "contraseña");
mysql_select_db( "binary_data");
$data = addslashes(fread(fopen($form_data, "r"),
filesize($form_data)));
$result=MYSQL_QUERY( "INSERT INTO binary_data(description,
bin_data,filename,filesize,filetype) ". "VALUES
('$form_description','$data',
'$form_data_name',
'$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// sino mostrar el formulario para nuevos datos:
?>
<form method="post" action=" <?php echo $PHP_SELF; ?>"
enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>Cargar archivo en base de datos:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</BODY>
</HTML>

Notar el uso de la variable predefinida $PHP_SELF que tiene el nombre del script de esta forma el formulario se llama a si mismo independientemente del nombre que se le ponga al archivo.

El siguiente script (getdata.php) puede usarse para recuperar los datos desde la base de datos, notar que el script espera recibir la variable $id con el id del registro a recuperar de la tabla.

<?php
if($id) {
@MYSQL_CONNECT( "localhost", "root", "contraseña");
@mysql_select_db( "binary_data");
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0, "bin_data");
$type = @MYSQL_RESULT($result,0, "filetype");
Header( "Content-type: $type");
echo $data;
};
?>

Para usar una imagen que se obtiene de la base de datos se puede usar:


<img src="getdata.php?id=3">

Notar como se le pasa la variable id al script para saber cual es el registro a recuperar de la base.



readdir() in php

<?php
//Open send directory

if(@$dir = opendir("send"))

{//List files in send directory

while (($file = readdir($dir)) !== false)

{

echo "filename: ". $file ."<br />";

}

closedir($dir);

}

else

{

echo 'directory not opened';

}

?>

outputs :
 1)
directory not opened

2)
filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

PHP control statements

We need to control PHP code based upon different condition for example, if the user click on the registration button, then a registration form will show to the users. To control the PHP code we use different types of PHP control statement such as if, else, for loop, break etc. PHP control statement has been broken into three types of category. 

  1. PHP selection statement
  2. PHP iteration statement
  3. PHP jump statement

From those statements, using PHP selection statement we can easily select different types of PHP code based upon condition. We can divide the PHP selection statement into two parts 
  • PHP if statement 
  • PHP switch statement 
Using PHP iteration statement we can repeat PHP code based upon condition. We can divide PHP iteration statement into three types
  • PHP for loop
  • PHP while loop 
  • PHP do-while loop 
Using PHP jump statement we can break PHP condition and we can jump one code snippet to another code snippet. PHP jump statements are two types
  • PHP break statement 
  • PHP continue statement