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

Friday, 10 June 2011

File Uploading concepts in PHP Types of errors at the time of file uploading in PHP


File Uploading concepts in PHP

Configuration directives related to the file uploads
File_uploads: By using this directive we can allow and stop the file uploads.
Upload_tmp_dir: By using this directive we can provide the exact location of temporary directory to upload files.
Upload_max_filesize: This configuration directive is used to provide the maximum file size to upload.

Types of errors at the time of file uploading in PHP
If the return value is 0, then uploaded successfully.
It returns 1, if the file size is maximum than upload_max_filesize value.
It returns 2, If the file size is maximum than browsers configuration settings value.
It returns 3, If there is any network problem , at the time of file upload.
It returns 4, If user clicks on submit button, without selecting any file.

Thursday, 9 June 2011

How To Execute PHP Script



How to execute php script?
Answer: To execute php script first you need to download Xampp software from the net. After downloading the software you can find Xampp icon on the desktop. Double click that icon. You can see the Apche and Mysql options on the window. Start these two servers.

To see if the Xampp is installed properly or not, open the browser and type http://localhost/xampp/

*Save every php script file in Xampp>htdocs location.

*save the file with ”.php” extension.
Now open the file with browser. 

Friday, 22 April 2011

Types of Print Function in PHP



Types of Print Function in PHP

Print: By using this function we can display the outputs on the browser. This function returns the Boolean value true. We cannot print the multiple statements using this function.
Ex:
<?php
$rval=print"welcome";
?>
Echo: By using this function we can display the multiple statements on the browser. Compare with print function, echo is very faster. Because it won’t return the any value.
Ex:
<?php
$rval="welcome";
echo $rval;
?>
Printf: By using this function we can display the output with the help of the formats specifies.
Ex:
<?php
$user="danPHP";
$cars=5;
printf("%s has %d cars",$user,$cars);
?>
sprintf: This is same as printf, but instead of displaying the output on the web page, it returns that output.
Ex:
<?php
$user="danphp";
$cars=5;
$rv=sprintf("%s has %d cars",$user,$cars);
echo $rv
?>
var_dump: This function displays the variable value along with the variable data type.
Ex:
<?php
$user="Danphp";
$cars=5;
var_dump($cars);
var_dump($Danphp);
?>
print_r: This function displays the r elements of array and properties of an object.
Ex:
<?php
$arr=array(10,20,30);
print_r($arr);
?>

Data Types in PHP



Types of Data Types in PHP

In PHP we have four types of data types.
1.Scalar Data Type.
2. Compound Data Type.
3. Special Data Type

Scalar Data Type: Scalar data type is divided into four types.


i)                    Boolean Data Type: This data type can hold true or false values.
is_bool -> This function checks the input variable is, Boolean or not.
Ex:
<?php
$x="false";
$x=(bool)$x;
echo is_bool ($x);
?>
ii)                  Integer Data Types: Integer data types holds the numeric value.
is_int -> By using this function we can check the input type variable is integer or not.
Ex:
<?php
$x="123";
$x=intval($x);
echo is_integer ($x);
?>
iii)                Float Data Type: Float variable holds the decimal values.
is_float -> By using this function we can check whether the input variable is float number or not.
(float)var-> to convert a variable into floating point numbers.
php.ini -> Precision is a directive to specify the number of significant digits > display in a floating point number. The default value is “12”.
iv)                 String Data Type: A string variable holds the collection of the characters. We can declare the string in two ways using single quotation(‘) and double quotations(“) using heredoc type.
Ex:
<?php
$x=100;
echo 'value of x is $x';
echo "value of x is $x";
?>
*By using this syntax we can design the html forums in php script.
<?php
$x=100;
echo <<<abcd
<input type="button" value="click">
abcd
?>


Compound Data types

Array Data Types: Array is the collection of elements. PHP is loosely typed language. That is why we can store any type of element in array.
Ex:
<?php
$arr=array('10','20','30');
echo $arr
?>
Special Data Types : Resource variable refreshes the external resources like data loose connections, file pointers, ftp connections.
Null Data Types : In php null is not a value, we can consider a variable as null variable based on 3 conditions.
i)                     The variable is not set with any variable.
ii)                   The variable is set with the null value.
iii)                  The value of the variable is deleted by using unset function.
*is_null: By using this function we can check whether the variable is null or not.
Ex:
<?php
$sno=100;
echo is_null($sno);
unset($no);
echo is_null($sno);
?>
In above script 1st is_null is not null 2nd is_null is a null.

Types of Errors in PHP



Errors in PHP

*We have four different types of errors in php.
1)  Notice Errors: Notice displays a massage to the end user and it will not stop the execution of the script.

Ex: If you are trying to access the undefined variable, the output is a notice massage. By default we cannot see the notices on the webpage. Because in “php.in” “error_reporting” is a configuration directive. The values of this directive is “E_ALL&~E_NOTICE”. It means browser displays all the errors expect notices.

*To display the notices, remove “&~E_NOTICE” from the configuration directives. Or use “error_reporting(E_ALL)” in the script , from where you want to display the notice massages.

2) Warning Errors: Warning errors are same as notice errors. Displays the same information to the users. Warning errors will not stop the execution of the script.

Ex: If you are trying to access the undefined constant then the output is warning error.
*In php we can declare the Constance using define keyword.
*define (<name>,<value>)
<?php
define ("city","hyd");
echo constant ("city")
echo constant ("stt")
echo "netline";
?>
*In above script “echo constant” is undefined constant.

Fatal Errors: Fatal errors stop the execution of the rest of the script. If you are trying to access the undefined functions, then the output is fatal error.
Ex:
<?php
function fun1()
{
echo "hi";
}
fun1();
fun2();
echo "next";
?>


Parse errors (syntax errors): If there is any syntax mistake in the script, the output is Parse errors. It stops the execution of entire script.
Ex: If you observe the below script, the second line does not contains “;” .
<?php
echo "line1";
echo "line2"
echo "line3";
?>

PHP Introduction and Files



PHP Introduction and Files

PHP stands for personal homepage and implemented by Rasmus Lerdorf in1950. 
The alias name of PHP is Hypertext Preprocessor
.
Wamp: Wamp is an environment to work with the php and wamp stands for windows apache mysql and php.

Lamp: Lamp stands for linux, apache, mysql and php.

Xampp: Xampp stands for any operating system. It supports different types of operating systems. The latest version of Xampp is 1.8.

*Install Xampp

After installation of Xampp a folder is available in destination location with the name. Xampp contains number of sub folder.
After the installation we have to start the ‘Apache’ server by using xampp control panel.
To check whether the Xampp is installed successfully or not, open the browser and type “http//localhost/xampp”. If you can see the xapmm icon it means Xapmm is successfully installed.

htdocs: This is the document root php application. Web server searches the requested file from this server.

tmp: This is the temporary location to maintain the session data and upload files.

Php: This folder contains php configuration settings. Php.ini is a file contains the all configuration directives (settings).

Apache: This folder contains the Apache configuration settings.

httpd.conf: This is apache configuration setting files.

Phpmyadmin: It is an environment to work with the Mysql data base.

Mysql: This folder contains the Mysql configuration settings My.cnf. My.cnf is a file contains configuration directives.

Open note pad and type below script , save the file with extension ‘.php’ and save in ‘htdocs’ folder whoch is located in xampp folder.


Sample Script:
<?php
print(“welcome”);
?>

By default Apache server port number is ‘80’. To change the port number , we have to change the values of 2 configurations. Listen and server name local host.
When we modify the values of configuration directives, we have to save that file and restart the web server.
To change the document root of web server, change the values of 2 directives. One is document root and another one is directive.

Versions Of PHP



Versions Of PHP

PHP 1.0 Version
It is the first release of PHP in 1995 used to handle the server side request. It is not a server side scripting language. Implemented with C and Perl technology.

PHP 2.0 Version
Introduced as server side scripting language in 1997 November. Supports different data base servers. Supports files uploads and many more functions.

PHP3.0 Version
2 Israeli programmers named “Zeev Sursky” and Andy rewritten the entire script of PHP from the basic and released PHP 3.0 version in 1998 June. It is fully server side scripting language and it supports different types of operating systems. PHP3.0 supports email functions. The name of PHP (Personal Homepage) renamed as Hyper Text Pre Processor.

PHP4.0  Version
Zend engine 1.0 is introduced PHP 4.0 in 2000 May. It is a cross server. It includes advance features like HTTP Sassing, Output, buffering Etc. PHP4.0 supports smarty template system which is used to develop web applications.

PHP5.0 Version
PHP 5.0 was released in 2005 includes more object oriented concepts like abstract, Inherence, Interfaces, Etc. Zend engine 2.0 was introduced. My SQL library was introduced which gives more support to My SQL. PHP5.0 supports exception. PHP5.0 includes web services and “XML” support.
XML = Grabbing the information of the web sites like Score, temperature.

PHP6.0 Version
PHP 6.0 is major upgrade to the PHP language. The main focus is native unique code supports. PHP6.0 supports OOP concepts such as name space and late static binding.
Native Unique code support means programmers can able to name their functions and classes in their own native language.

PHP History And Advantages



PHP History :
PHP was implemented by “Rasmus Lerdorf” in 1995 using “C” and “PERL” languages.  Rasmus Lerdorf implemented this script to find out, how many company’s accessing his resume.

PHP USE
PHP is a server side script language just like Jsp and Asp to develop the dynamic web applications. (Server Side = Interacting with the server). Not only dynamic web applications we can also develop the stand alone applications with PHP. (Stand alone applications = desktop applications, imaging applications).

PHP Advantages
PHP is a cross flat form. Cross flat form means it supports any type of Data Base Server like Windows, SQL, Linux.

PHP is providing building functions to interact with Mysql database. With Jsp and Asp we cannot function directly to Mysql database. To function directly to Mysql database in Jsp and Asp, we need to use third party functions. Third party functions are not secure.
Ex. 2 years back Google stopped services to China, because of hacking the google.com. google.com was made by Jsp and Asp using third party tools. It reopened with the PHP.

Present PHP
PHP is cross server. It means it supports any time of web services.
PHP application is very fast. Zen Engine is the run time environment supporting number of functionalities at the time of application execution.
PHP supports object oriented programming concepts. CMS is providing all common functioning like “Login and Registration form and comment box.
PHP is supporting number of CMS software’s like Joomla, Wordpress, Roopal.
Zend organization is maintaining the PHP software. Zend introduced number of editors and Debuggs to work with PHP.
We can use different types of IDES to work with the PHP.
PHP is extendable. We can add the new features to the PHP software.
PHP is open source. It is free and easy to develop. We no need to buy a license from anywhere like Windows ex.