SlideShare una empresa de Scribd logo
1 de 14
FILE UPLOAD To upload files from your browser to your hosting, using PHP,the first thing we need to do is create an  HTML form that  allows people to choose the file  they want to upload . < form enctype=&quot;multipart/form-data&quot; action=&quot;upload.php&quot; method=&quot;POST&quot;> Please choose a file:   <input name=&quot;uploaded&quot; type=&quot;file&quot; /><br /  >  <input type=&quot;submit&quot; value=&quot;Upload&quot; /> </form>
Continue... This form sends data to the file &quot;upload.php&quot;, which is  what we will be creating next to actually upload the  file. The actual file upload is very simple:  <?php  $target = &quot;upload/&quot;;  $target = $target .  basename( $_FILES['uploaded'] ['name']) ;  $ok=1;  if(move_uploaded_file($_FILES['uploaded'] ['tmp_name'], $target))  { echo &quot;The file &quot;.
Continue... basename( $_FILES['uploadedfile'] ['name']). &quot; has been uploaded&quot;; }  else  { echo &quot;Sorry, there was a problem uploading your file.&quot;; }?>  This very small piece of code will upload files sent to  it by your HTML form. 1.The first line  $target = &quot;upload/&quot;;  is where we  assign the  folder that files will be uploaded to. As  you can see in the second line, this folder is relative to the upload.php file
Continue... 2.We are not using  $ok=1;  at the moment but we will later in the tutorial.  3.We then move the uploaded file to where it belongs using  move_uploaded_file () . This places it in the directory we  specified at the beginning of our script. If this fails the   is given an error message, otherwise they are told that the file has been  uploaded.
SESSION A PHP session variable is used to store information  about,change settings for a user session. Session variables holinformation about one single user, and are available to allpages in one application.  Starting a PHP Session: Before you can store user information in your PHP session, you must first start up the session. <?php session_start(); ?>   <html>   <body>   </body>   </html>
Continue... The code above will register the user's session with the   server, allow you to start saving user information, and assign a UID for that user's session. Storing a Session Variable: The correct way to store and retrieve session variables is to use the PHP $_SESSION variable: <?php   session_start();   // store session data   $_SESSION['views']=1;   ?>   <html>
Continue <body>   <?php   //retrieve session data   echo &quot;Pageviews=&quot;. $_SESSION['views'];   ?>   </body>   </html>  Output: Pageviews=1  Destroying a Session: If you wish to delete some session data, you can use the unset() or the session_destroy() function.   ?>
Continue... The unset() function is used to free the specified  session  va riable: <?php   unset($_SESSION['views']);   ?>  You can also completely destroy the session by calling the session_destroy() function: <?php   session_destroy();   ?>
COOKIES A cookie is often used to identify a user. A cookie is a small  file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values. How to Create a Cookie? The setcookie() function is used to set a cookie. setcookie(name, value, expire, path, domain);
Continue... How to Retrieve a Cookie Value? The PHP $_COOKIE variable is used to retrieve a cookie  value. Example <?php   // Print a cookie   echo $_COOKIE[&quot;user&quot;];   // A way to view all cookies   print_r($_COOKIE);   ?>
Continue.... How to Delete a Cookie? When deleting a cookie you should assure that the expiratio   date is in the past . Example <?php   // set the expiration date to one hour ago   setcookie(&quot;user&quot;, &quot;&quot;, time()-3600);   ?>
TYPES OF ERRORS 1.Notices: These are trivial, non-critical errors that PHP  encounters while executing a script -for example, accessing a variable  that has not  yet been defined by default,  such errors are not displayed to the user at all -although you can  change this default behavior.
Continue... 2.Warnings: These are more serious errors – for example  attempting to include() a file which  does not exist. By default, these errors are displayed to the user, but they do not result in script termination. 3.Fatal errors: These are critical errors – for example,   instantiating an object of a non- existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when  they take plac
PHP error_log() Function The error_log() function sends an error to the server  error log, a file or a remote destination. This funtion returns TRUE on success, or FALSE  on  failure. Syntax: error_log(error,type,destination,headers)  PHP parse_ini_file() Function The parse_ini_file() function parses a configuration (ini) file and returns the settings in it in an array. Syntax: parse_ini_file(file,process_sections)

Más contenido relacionado

La actualidad más candente

New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPRupesh Kumar
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rulesnagarajhubli
 
JSON Rules Language
JSON Rules LanguageJSON Rules Language
JSON Rules Languagegiurca
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applicationsMilan Korsos
 
PHP Programming: Intro
PHP Programming: IntroPHP Programming: Intro
PHP Programming: IntroThings Lab
 

La actualidad más candente (10)

New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPP
 
Js unit testing
Js unit testingJs unit testing
Js unit testing
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rules
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
JSON Rules Language
JSON Rules LanguageJSON Rules Language
JSON Rules Language
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 
My mule esb first http flow
My mule esb first http flowMy mule esb first http flow
My mule esb first http flow
 
Compressing & decompressing in mule
Compressing & decompressing in muleCompressing & decompressing in mule
Compressing & decompressing in mule
 
PHP Programming: Intro
PHP Programming: IntroPHP Programming: Intro
PHP Programming: Intro
 

Destacado (7)

Els lleons
Els lleonsEls lleons
Els lleons
 
Conference Package - Holiday Inn Express &amp; Suites Gananoque
Conference Package - Holiday Inn Express &amp; Suites GananoqueConference Package - Holiday Inn Express &amp; Suites Gananoque
Conference Package - Holiday Inn Express &amp; Suites Gananoque
 
Can unit 1 2o.
Can unit 1 2o.Can unit 1 2o.
Can unit 1 2o.
 
The colors
The colorsThe colors
The colors
 
Mysql
MysqlMysql
Mysql
 
Quality Inn Tower Room Package
Quality Inn Tower Room PackageQuality Inn Tower Room Package
Quality Inn Tower Room Package
 
Chapitre 7
Chapitre 7Chapitre 7
Chapitre 7
 

Similar a Ph

Similar a Ph (20)

Php
PhpPhp
Php
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Php BASIC
Php BASICPhp BASIC
Php BASIC
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Unusual Web Bugs
Unusual Web BugsUnusual Web Bugs
Unusual Web Bugs
 
Web Bugs
Web BugsWeb Bugs
Web Bugs
 
PHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for phpPHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for php
 
PHP
PHPPHP
PHP
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Web application security
Web application securityWeb application security
Web application security
 
Php intro
Php introPhp intro
Php intro
 
PHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxPHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptx
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
 
Download It
Download ItDownload It
Download It
 
Web Security
Web SecurityWeb Security
Web Security
 
Parameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHPParameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHP
 
PHP Security
PHP SecurityPHP Security
PHP Security
 

Ph

  • 1. FILE UPLOAD To upload files from your browser to your hosting, using PHP,the first thing we need to do is create an HTML form that allows people to choose the file they want to upload . < form enctype=&quot;multipart/form-data&quot; action=&quot;upload.php&quot; method=&quot;POST&quot;> Please choose a file: <input name=&quot;uploaded&quot; type=&quot;file&quot; /><br / > <input type=&quot;submit&quot; value=&quot;Upload&quot; /> </form>
  • 2. Continue... This form sends data to the file &quot;upload.php&quot;, which is what we will be creating next to actually upload the file. The actual file upload is very simple: <?php $target = &quot;upload/&quot;; $target = $target . basename( $_FILES['uploaded'] ['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded'] ['tmp_name'], $target)) { echo &quot;The file &quot;.
  • 3. Continue... basename( $_FILES['uploadedfile'] ['name']). &quot; has been uploaded&quot;; } else { echo &quot;Sorry, there was a problem uploading your file.&quot;; }?> This very small piece of code will upload files sent to it by your HTML form. 1.The first line $target = &quot;upload/&quot;; is where we assign the folder that files will be uploaded to. As you can see in the second line, this folder is relative to the upload.php file
  • 4. Continue... 2.We are not using $ok=1; at the moment but we will later in the tutorial. 3.We then move the uploaded file to where it belongs using move_uploaded_file () . This places it in the directory we specified at the beginning of our script. If this fails the is given an error message, otherwise they are told that the file has been uploaded.
  • 5. SESSION A PHP session variable is used to store information about,change settings for a user session. Session variables holinformation about one single user, and are available to allpages in one application. Starting a PHP Session: Before you can store user information in your PHP session, you must first start up the session. <?php session_start(); ?> <html> <body> </body> </html>
  • 6. Continue... The code above will register the user's session with the server, allow you to start saving user information, and assign a UID for that user's session. Storing a Session Variable: The correct way to store and retrieve session variables is to use the PHP $_SESSION variable: <?php session_start(); // store session data $_SESSION['views']=1; ?> <html>
  • 7. Continue <body> <?php //retrieve session data echo &quot;Pageviews=&quot;. $_SESSION['views']; ?> </body> </html> Output: Pageviews=1 Destroying a Session: If you wish to delete some session data, you can use the unset() or the session_destroy() function. ?>
  • 8. Continue... The unset() function is used to free the specified session va riable: <?php unset($_SESSION['views']); ?> You can also completely destroy the session by calling the session_destroy() function: <?php session_destroy(); ?>
  • 9. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values. How to Create a Cookie? The setcookie() function is used to set a cookie. setcookie(name, value, expire, path, domain);
  • 10. Continue... How to Retrieve a Cookie Value? The PHP $_COOKIE variable is used to retrieve a cookie value. Example <?php // Print a cookie echo $_COOKIE[&quot;user&quot;]; // A way to view all cookies print_r($_COOKIE); ?>
  • 11. Continue.... How to Delete a Cookie? When deleting a cookie you should assure that the expiratio date is in the past . Example <?php // set the expiration date to one hour ago setcookie(&quot;user&quot;, &quot;&quot;, time()-3600); ?>
  • 12. TYPES OF ERRORS 1.Notices: These are trivial, non-critical errors that PHP encounters while executing a script -for example, accessing a variable that has not yet been defined by default, such errors are not displayed to the user at all -although you can change this default behavior.
  • 13. Continue... 2.Warnings: These are more serious errors – for example attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination. 3.Fatal errors: These are critical errors – for example, instantiating an object of a non- existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take plac
  • 14. PHP error_log() Function The error_log() function sends an error to the server error log, a file or a remote destination. This funtion returns TRUE on success, or FALSE on failure. Syntax: error_log(error,type,destination,headers) PHP parse_ini_file() Function The parse_ini_file() function parses a configuration (ini) file and returns the settings in it in an array. Syntax: parse_ini_file(file,process_sections)