PHP
<ul><li>PHP stands for Hypertext Preprocessor and is a server-side language.  </li></ul><ul><li>This means that the script...
PHP.INI <ul><li>The php.ini file is a special file for suPHP (pronounced sue-p-h-p). </li></ul><ul><li>The php.ini file is...
PHP SYNTAX <ul><li>A PHP scripting block always starts with  <?php  and ends with  ?> . A PHP scripting block can be place...
PHP VARIABLES <ul><li>A variable is used to store information, like text strings, numbers or arrays. </li></ul><ul><li>Whe...
PHP STRINGS <ul><li>String variables are used for values that contains characters. </li></ul><ul><li>After we create a str...
PHP OPERATORS <ul><li>In all programming languages, operators are used to manipulate or perform operations on variables an...
ASSIGNMENT OPERATOR <ul><li>Assignment operators are used to set a variable equal to a value or set a variable to another ...
ARITHMETIC OPERATOR <ul><li>The arithmetic operators in php are as follows : </li></ul>OPERATOR MEANING + Addition - Subtr...
COMPARISON OPERATOR <ul><li>Comparisons are used to check the relationship between variables and/or values. If you would l...
STRING OPERATORS <ul><li>The operator “.” is the string operator used in PHP. </li></ul><ul><li>The string operator is use...
COMBINATION ARITHMETIC AND ASSIGNMENT OPERATOR <ul><li>It is a combination of assignment and arithmetic operators. </li></...
PHP ECHO <ul><li>The echo() function outputs one or more strings. </li></ul><ul><li>It can output all types of data and mu...
PHP GET  <ul><li>The GET method sends the encoded user information appended to the page request. The page and the encoded ...
PHP POST <ul><li>The POST method transfers information via HTTP headers. The information is encoded as described in case o...
PHP FILES <ul><li>Manipulating files is a basic necessity for serious programmers and PHP gives you a great deal of tools ...
CREATE FILE <ul><li>In PHP, a file is created using a command that is also used to open files. </li></ul><ul><li>In PHP th...
OPEN FILE <ul><li>The fopen function is used to open a file. </li></ul><ul><li>There are different modes to open a file. T...
CLOSE FILE <ul><li>The fclose function is used to close a file in php. </li></ul><ul><li>The genral structure for closing ...
PHP SESSIONS <ul><li>In PHP, a &quot;session&quot; is the time that a user spends on a web site. </li></ul><ul><li>A PHP S...
PHP COOKIES <ul><li>Cookies have been around for quite some time on the internet. They were invented to allow webmaster's ...
PHP COOKIES (Contd...) <ul><li>The following sample code is used to  retrieve a cookie : </li></ul><ul><li><?php </li></ul...
THANK YOU
Upcoming SlideShare
Loading in...5
×

Php

1,702

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,702
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Php

  1. 1. PHP
  2. 2. <ul><li>PHP stands for Hypertext Preprocessor and is a server-side language. </li></ul><ul><li>This means that the script is run on your web server, not on the user's browser, so you do not need to worry about compatibility issues. </li></ul><ul><li>PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becomming one of the most popular scripting languages on the internet. </li></ul>WHAT IS PHP?
  3. 3. PHP.INI <ul><li>The php.ini file is a special file for suPHP (pronounced sue-p-h-p). </li></ul><ul><li>The php.ini file is where you declare changes to your PHP settings. You can edit the existing php.ini, or create a new text file in any subdirectory and name it php.ini. </li></ul><ul><li>Some common changes that you must make when moving from non-secure php environment to suPHP : </li></ul><ul><li>For example, if your site had these settings in a .htaccess file: </li></ul><ul><li>php_flag upload_max_filesize 10M </li></ul><ul><li>php_value post_max_size 10M </li></ul><ul><li>php_value max_execution_time 30 </li></ul>
  4. 4. PHP SYNTAX <ul><li>A PHP scripting block always starts with <?php and ends with ?> . A PHP scripting block can be placed anywhere in the document. </li></ul><ul><li>On servers with shorthand support enabled you can start a scripting block with <? and end with ?>. </li></ul><ul><li>For maximum compatibility, we use the standard form (<?php) rather than the shorthand form. </li></ul>
  5. 5. PHP VARIABLES <ul><li>A variable is used to store information, like text strings, numbers or arrays. </li></ul><ul><li>When a variable is declared, it can be used over and over again in your script. </li></ul><ul><li>All variables in PHP start with a $ sign symbol. </li></ul><ul><li>The declaration of php variables is : </li></ul><ul><li>$var_name = value; </li></ul>
  6. 6. PHP STRINGS <ul><li>String variables are used for values that contains characters. </li></ul><ul><li>After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable. </li></ul><ul><li>The declaration of a string looks like this : </li></ul><ul><li>$my_string = “ABSASDFSDF”; </li></ul>
  7. 7. PHP OPERATORS <ul><li>In all programming languages, operators are used to manipulate or perform operations on variables and values. </li></ul><ul><li>There are many operators used in PHP, so we have separated them into the following categories to make it easier to learn them all. </li></ul><ul><li>!) Assignment Operators </li></ul><ul><li>2) Arithmetic Operators </li></ul><ul><li>3) Comparison Operators </li></ul><ul><li>4) String Operators </li></ul><ul><li>5) Combination Arithmetic & Assignment Operators </li></ul>
  8. 8. ASSIGNMENT OPERATOR <ul><li>Assignment operators are used to set a variable equal to a value or set a variable to another variable's value. Such an assignment of value is done with the &quot;=&quot;, or equal character. Example: </li></ul><ul><li>$my_var = 4; </li></ul><ul><li>$another_var = $my_var; </li></ul><ul><li>Now both $my_var and $another_var contain the value 4. Assignments can also be used in conjunction with arithmetic operators. </li></ul>
  9. 9. ARITHMETIC OPERATOR <ul><li>The arithmetic operators in php are as follows : </li></ul>OPERATOR MEANING + Addition - Subtraction * Muktiplication / Division % Modulus (Division remainder) ++ Increment -- Decrement
  10. 10. COMPARISON OPERATOR <ul><li>Comparisons are used to check the relationship between variables and/or values. If you would like to see a simple example of a comparison operator in action, check out our If Statement Lesson. Comparison operators are used inside conditional statements and evaluate to either true or false. Here are the most important comparison operators of PHP. </li></ul><ul><li>The comparison operators in php are : </li></ul><ul><li>== means Equals to </li></ul><ul><li>!= means Not equal to </li></ul><ul><li>< means Less than </li></ul><ul><li>> means Greater than </li></ul><ul><li><= means Less than or Equal to </li></ul><ul><li>>= means Greater than or equal to </li></ul>
  11. 11. STRING OPERATORS <ul><li>The operator “.” is the string operator used in PHP. </li></ul><ul><li>The string operator is used to concatenate two strings. </li></ul>
  12. 12. COMBINATION ARITHMETIC AND ASSIGNMENT OPERATOR <ul><li>It is a combination of assignment and arithmetic operators. </li></ul><ul><li>The combination of arithmetic and assignment operators include ; </li></ul><ul><li>+= means Plus eqals </li></ul><ul><li>-= means Minus equals </li></ul><ul><li>*= means Multiply equals </li></ul><ul><li>/= means Divide equals </li></ul><ul><li>%= means Modulo equals </li></ul><ul><li>.= means Concatenate equals </li></ul>
  13. 13. PHP ECHO <ul><li>The echo() function outputs one or more strings. </li></ul><ul><li>It can output all types of data and multiple outputs can be made with only one echo () command. </li></ul><ul><li>For example </li></ul><ul><li><?php </li></ul><ul><li>echo “HI”; </li></ul><ul><li>?> </li></ul><ul><li>Prints the string “HI”. </li></ul>
  14. 14. PHP GET <ul><li>The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? Character. </li></ul><ul><li>The data sent by GET method can be accessed using QUERY_STRING environment variable. </li></ul><ul><li>The PHP provides $_GET associative array to access all the sent information using GET method. </li></ul>
  15. 15. PHP POST <ul><li>The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING. </li></ul><ul><li>The POST method does not have any restriction on data size to be sent. </li></ul><ul><li>The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure. </li></ul><ul><li>The PHP provides $_POST associative array to access all the sent information using GET method. </li></ul>
  16. 16. PHP FILES <ul><li>Manipulating files is a basic necessity for serious programmers and PHP gives you a great deal of tools for creating, uploading, and editing files. </li></ul><ul><li>PHP files deals with read, write, append, truncate, and uploading files. </li></ul>
  17. 17. CREATE FILE <ul><li>In PHP, a file is created using a command that is also used to open files. </li></ul><ul><li>In PHP the fopen function is used to open files. However, it can also create a file if it does not find the file specified in the function call. So if you use fopen on a file that does not exist, it will create it, given that you open the file for writing or appending (more on this later). </li></ul><ul><li>The fopen function needs two important pieces of information to operate correctly. First, we must supply it with the name of the file that we want it to open. Secondly, we must tell the function what we plan on doing with that file (i.e. read from the file, write information, etc). </li></ul><ul><li>The code for Creating a file is as follows : </li></ul><ul><li>$ourFileName = &quot;testFile.txt&quot;; </li></ul><ul><li>$ourFileHandle = fopen($ourFileName, 'w') or die(&quot;can't open file&quot;); </li></ul><ul><li>fclose($ourFileHandle); </li></ul>
  18. 18. OPEN FILE <ul><li>The fopen function is used to open a file. </li></ul><ul><li>There are different modes to open a file. They are : </li></ul><ul><li>(i) Read 'r' : - </li></ul><ul><li>Open a file for read only use. The file pointer begins at the front of the file. </li></ul><ul><li>(ii) Write 'w' :- </li></ul><ul><li>Open a file for write only use. In addition, the data in the file is erased and you will begin writing data at the beginning of the file. This is also called truncating a file, which we will talk about more in a later lesson. The file pointer begins at the start of the file. </li></ul><ul><li>(iii) Append 'a' :- </li></ul><ul><li>Opens and writes to the end of the file or creates a new file if it doesn't exist </li></ul>
  19. 19. CLOSE FILE <ul><li>The fclose function is used to close a file in php. </li></ul><ul><li>The genral structure for closing a file is : </li></ul><ul><li>$ourFileName = &quot;testFile.txt&quot;; </li></ul><ul><li>$ourFileHandle = fopen($ourFileName, 'w') or die(&quot;can't open file&quot;); </li></ul><ul><li>fclose($ourFileHandle); </li></ul>
  20. 20. PHP SESSIONS <ul><li>In PHP, a &quot;session&quot; is the time that a user spends on a web site. </li></ul><ul><li>A PHP Session allows certain data to be preserved across an access span, by assigning a unique ID called &quot;Session ID&quot;, to each visitor to the site. </li></ul><ul><li>This Session ID can be stored as a cookie at the client end, or passed through a URL. </li></ul><ul><li>To start a new session and to destroy a session, The following code must be used : </li></ul><ul><li><?php </li></ul><ul><li>session_start(); </li></ul><ul><li>//YOUR CODE HERE </li></ul><ul><li>session_destroy(); </li></ul><ul><li>?> </li></ul>
  21. 21. PHP COOKIES <ul><li>Cookies have been around for quite some time on the internet. They were invented to allow webmaster's to store information about the user and their visit on the user's computer. </li></ul><ul><li>When you create a cookie, using the function setcookie, you must specify three arguments. These arguments are setcookie(name, value, expiration): </li></ul><ul><li>1. name: </li></ul><ul><li>The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it! </li></ul><ul><li>2. value: </li></ul><ul><li>The value that is stored in your cookie. Common values are username(string) and last visit(date). </li></ul><ul><li>3. expiration: </li></ul><ul><li>The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted. </li></ul>
  22. 22. PHP COOKIES (Contd...) <ul><li>The following sample code is used to retrieve a cookie : </li></ul><ul><li><?php </li></ul><ul><li>if(isset($_COOKIE['lastVisit'])) </li></ul><ul><li> $visit = $_COOKIE['lastVisit']; </li></ul><ul><li>else </li></ul><ul><li> echo &quot;You've got some stale cookies!&quot;; </li></ul><ul><li>echo &quot;Your last visit was - &quot;. $visit; </li></ul><ul><li>?> </li></ul>
  23. 23. THANK YOU
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×