SlideShare uma empresa Scribd logo
1 de 32
PHP HYPERTEXT PREPROCESSOR
[object Object],[object Object],[object Object],CONTENTS
INTRODUCTION
PHP stands for Hypertext Preprocessor and is a server-side language. 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. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becoming one of the most popular scripting languages on the INTERNET. INTRODUCTION
WRITING PHP Writing PHP on your computer is actually very simple. You don't need any special software, except for a text editor (like Notepad in Windows). Run this and you are ready to write your first PHP script.
DECLARING PHP PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP. The three different forms are as follows: <? PHP Code In Here ?>
PHP COMMANDS
To output text in your PHP script is actually very simple. . The main one you will be using, though, is print. Print will allow you to output text, variables or a combination of the two so that they display on the screen. EXAMPLE: <? print(&quot;Hello world!&quot;); ?> Which will display: Hello world! on the screen. PRINTING TEXT
VARIABLES As with other programming languages, PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code: $welcome_text = &quot;Hello and welcome to my website.&quot;; This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string.
OUTPUTING VARIABLES To display a variable on the screen uses exactly the same code as to display text but in a slightly different form. The following code would display your welcome text: <? $welcome_text = &quot;Hello and welcome to my website.&quot;; print($welcome_text); ?>
FORMATTING THE TEXT Formatting the text in PHP includes the color in codes and not in namesFor this example I will change the text to the Arial font in red. The normal code for this would be: <font face=&quot;Arial&quot; color=&quot;#FF0000&quot;></font>  You can now include this in your print statement: print(&quot;<font face=amp;quot;Arialamp;quot; coloramp;quot;#FF0000amp;quot;>Hello and welcome to my website.</font>&quot;); which will make the browser display: Hello and welcome to my website.
If statements are used to compare two values and carry out different actions based on the results of the test. If statements take the form IF, THEN, ELSE. Basically it checks the condition. If it is true, the then statement is executed. If not, the else statement is executed. The structure of an IF statement is as follows: IF (something == something else) {THEN Statement } else { ELSE Statement} THE BASIC IF STRUCTURE
VARIABLES IN IF STATEMENT The most common use of an IF statement is to compare a variable to another piece of text, a number, or another variable. For example: if ($username == &quot;webmaster&quot;) which would compare the contents of the variable to the text string. The THEN section of code will only be executed if the variable is exactly the same as the contents of the quotation marks so if the variable contained 'Web master' or 'WEBMASTER' it will be false.
CONSTRUCTING THEN  To add to your script, you can now add a THEN statement: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;;} This will only display this text if the username is webmaster. If not, nothing will be displayed. You can actually leave an IF statement like this, as there is no actual requirement to have an ELSE part. This is especially useful if you are using multiple IF statements.
CONSTRUCTING ELSE Adding The ELSE statement is as easy as the THEN statement. Just add some extra code: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;; } else { echo &quot;We are sorry but you are not a recognized user&quot;;} Of course, you are not limited to just one line of code. You can add any PHP commands in between the curly brackets. You can even include other IF statements (nested statements).
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],FOR LOOP
WHILE STATEMENT If you have a piece of code which you want to repeat several times without retyping it, you can use a while loop. For instance if you wanted to print out the words &quot;Hello World&quot; 5 times you could use the following code: $times = 5; $x = 0; while ($x < $times) { echo &quot;Hello World&quot;; ++$x;}
USING $X The variable counting the number of repeats ($x in the above example) can be used for much more than just counting. For example if you wanted to create a web page with all the numbers from 1 to 1000 on it, you could either type out every single one or you could use the following code: $number = 1000; $current = 0; while ($current < $number) { ++$current; echo &quot;$current<br>&quot;;}
ARRAY Arrays are common to many programing languages. They are special variables which can hold more than one value, each stored in its own numbered 'space' in the array. Arrays are extremely useful, especially when using WHILE loops.
TYPES OF ARRAY In PHP, there are three kind of arrays: * Numeric array - An array with a numeric index * Associative array - An array where each ID key is associated with a value * Multidimensional array - An array containing one or more arrays
SETTING UP AN ARRAY Setting up an array is slightly different to setting up a normal variable. In this example I will set up an array with 5 names in it: $names[0] = 'John'; $names[1] = 'Paul'; $names[2] = 'Steven'; As you can see, the parts of an array are all numbered, starting from 0. To add a value to an array you must specify the location in the array by putting a number in [ ].
PHP WITH FORMS Setting up a form for use with a PHP script is exactly the same as normal in HTML. As this is a PHP tutorial I will not go into depth in how to write your form but I will show you three of the main pieces of code you must know: <input type=&quot;text&quot; name=&quot;the box&quot; value=&quot;Your Name&quot;> Will display a text input box with Your Name written in it as default. The value section of this code is optional. The information defined by name will be the name of this text box and should be unique. <textarea name=&quot;message&quot;> Please write your message here. </textarea> Will display a large scrolling text box with the text 'Please write your message here.' as default. Again, the name is defined and should be unique. <input type=&quot;submit&quot; value=&quot;Submit&quot;> This will create a submit button for your form. You can change what it says on the button by changing the button's value.
GET METHOD  The built-in $_GET function is used to collect values from a form sent with method=&quot;get&quot;. Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max. 100 characters). Example <form action=&quot;welcome.php&quot; method=&quot;get&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL sent to the server could look something like this: http://www.w3schools.com/welcome.php?fname=Peter&age=37 The &quot;welcome.php&quot; file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array): Welcome <?php echo $_GET[&quot;fname&quot;]; ?>.<br /> You are <?php echo $_GET[&quot;age&quot;]; ?> years old!
POST METHOD The built-in $_POST function is used to collect values from a form sent with method=&quot;post&quot;.Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.Example <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL will look like this: http://www.w3schools.com/welcome.php The &quot;welcome.php&quot; file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome <?php echo $_POST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old.
READING FROM AN ARRAY Reading from an array is just the same as putting information in. All you have to do is to refer to the array and the number of the piece of data in the array. So if I wanted to print out the third name I could use the code: echo &quot;The third name is $names[2]&quot;; Which would output: The third name is Steven
PHP FUNCTIONS In PHP, there are more than 700 built-in functions.  This chapter shows how to create your own functions. A function will be executed by a call to the function. You may call a function from anywhere within a page. Syntax: function functionName() { code to be executed; }
E-MAIL WITH PHP
Mail is extremely easy to send from PHP, unlike using scripting languages which require special setup (like CGI). There is actually just one command, mail() for sending mail. It is used as follows: mail($to,$subject,$body,$headers); In this example I have used variables as they have descriptive names but you could also just place text in the mail command. Firstly, $to. This variable (or section of the command) contains the e-mail address to which the mail will be sent. $subject is the section for the subject of the e-mail and $body is the actual text of the e-mail.The section $headers is used for any additional e-mail headers you may want to add. The most common use of this is for the From field of an e-mai but you can also include other headers like cc and bcc. MAIL COMMAND
SENDING MAIL Before sending your mail, if you are using variables, you must, of course, set up the variable content beforehand. Example: $to = &quot;php@gowansnet.com&quot;; $subject = &quot;PHP Is Great&quot;; $body = &quot;PHP is one of the best scripting languages around&quot;; $headers = &quot;From: webmaster@gowansnet.com&quot;; mail($to,$subject,$body,$headers); echo &quot;Mail sent to $to&quot;; This code will acutally do two things. Firstly it will send a message to php@gowansnet.com with the subject 'PHP Is Great' and the text: PHP is one of the best scripting languages around and the e-mail will be from webmaster@gowansnet.com. It will also output the text: Mail sent to php@gowansnet.com
ERROR CONTROL As anyone who has been scripting for a while will know, it is extremely easy to make mistakes in your code and it is also very easy to input an invalid e-mail address (especially if you are using your script for form to mail). Because of this, you can add in a small piece of code which will check if the e-mail is sent: if(mail($to,$subject,$body,$headers)) { echo &quot;An e-mail was sent to $to with the subject: $subject&quot;;} else { echo &quot;There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid&quot;;} This code is quite self explanatory If the mail is sent successfully it will output a message to the browser telling the user, if not, it will display an error message with some suggestions for correcting the problem.
PHP INSTALLATION The Windows PHP installer is available from the downloads page at » http://www.php.net/downloads.php. This installs the CGI version of PHP and for IIS, PWS, and Xitami, it configures the web server as well. The installer does not include any extra external PHP extensions (php_*.dll) as you'll only find those in the Windows Zip Package and PECL downloads.  First, install your selected HTTP (web) server on your system, and make sure that it works. Run the executable installer and follow the instructions provided by the installation wizard. Two types of installation are supported - standard, which provides sensible defaults for all the settings it can, and advanced, which asks questions as it goes along. The installation wizard gathers enough information to set up the php.ini file, and configure certain web servers to use PHP. One of the web servers the PHP installer does not configure for is Apache, so you'll need to configure it manually. Once the installation has completed, the installer will inform you if you need to restart your system, restart the server, or just start using PHP.
PHP INI FILE Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect. In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files. Two new INI directives, user_ini.filename and user_ini.cache_ttl control the use of user INI files. user_ini.filename sets the name of the file PHP looks for in each directory; if set to an empty string, PHP doesn't scan at all. The default is .user.ini. user_ini.cache_ttl controls how often user INI files are re-read. The default is 300 seconds (5 minutes).

Mais conteúdo relacionado

Mais procurados (18)

Learn php with PSK
Learn php with PSKLearn php with PSK
Learn php with PSK
 
Php Loop
Php LoopPhp Loop
Php Loop
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Php(report)
Php(report)Php(report)
Php(report)
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Php
PhpPhp
Php
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
 
Php notes 01
Php notes 01Php notes 01
Php notes 01
 
Php
PhpPhp
Php
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 

Semelhante a Babitha5.php (20)

PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Php
PhpPhp
Php
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Php
PhpPhp
Php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
PHP Lesson
PHP LessonPHP Lesson
PHP Lesson
 
Php
PhpPhp
Php
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Php1
Php1Php1
Php1
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
06-PHPIntroductionserversicebasicss.pptx
06-PHPIntroductionserversicebasicss.pptx06-PHPIntroductionserversicebasicss.pptx
06-PHPIntroductionserversicebasicss.pptx
 

Mais de banubabitha

Mais de banubabitha (16)

Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha3.css
Babitha3.cssBabitha3.css
Babitha3.css
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Babitha.4appach
Babitha.4appachBabitha.4appach
Babitha.4appach
 
Babitha.4appach
Babitha.4appachBabitha.4appach
Babitha.4appach
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha2 Mysql
Babitha2 MysqlBabitha2 Mysql
Babitha2 Mysql
 
Babitha2.mysql
Babitha2.mysqlBabitha2.mysql
Babitha2.mysql
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Babitha5.php

  • 2.
  • 4. PHP stands for Hypertext Preprocessor and is a server-side language. 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. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becoming one of the most popular scripting languages on the INTERNET. INTRODUCTION
  • 5. WRITING PHP Writing PHP on your computer is actually very simple. You don't need any special software, except for a text editor (like Notepad in Windows). Run this and you are ready to write your first PHP script.
  • 6. DECLARING PHP PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP. The three different forms are as follows: <? PHP Code In Here ?>
  • 8. To output text in your PHP script is actually very simple. . The main one you will be using, though, is print. Print will allow you to output text, variables or a combination of the two so that they display on the screen. EXAMPLE: <? print(&quot;Hello world!&quot;); ?> Which will display: Hello world! on the screen. PRINTING TEXT
  • 9. VARIABLES As with other programming languages, PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code: $welcome_text = &quot;Hello and welcome to my website.&quot;; This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string.
  • 10. OUTPUTING VARIABLES To display a variable on the screen uses exactly the same code as to display text but in a slightly different form. The following code would display your welcome text: <? $welcome_text = &quot;Hello and welcome to my website.&quot;; print($welcome_text); ?>
  • 11. FORMATTING THE TEXT Formatting the text in PHP includes the color in codes and not in namesFor this example I will change the text to the Arial font in red. The normal code for this would be: <font face=&quot;Arial&quot; color=&quot;#FF0000&quot;></font> You can now include this in your print statement: print(&quot;<font face=amp;quot;Arialamp;quot; coloramp;quot;#FF0000amp;quot;>Hello and welcome to my website.</font>&quot;); which will make the browser display: Hello and welcome to my website.
  • 12. If statements are used to compare two values and carry out different actions based on the results of the test. If statements take the form IF, THEN, ELSE. Basically it checks the condition. If it is true, the then statement is executed. If not, the else statement is executed. The structure of an IF statement is as follows: IF (something == something else) {THEN Statement } else { ELSE Statement} THE BASIC IF STRUCTURE
  • 13. VARIABLES IN IF STATEMENT The most common use of an IF statement is to compare a variable to another piece of text, a number, or another variable. For example: if ($username == &quot;webmaster&quot;) which would compare the contents of the variable to the text string. The THEN section of code will only be executed if the variable is exactly the same as the contents of the quotation marks so if the variable contained 'Web master' or 'WEBMASTER' it will be false.
  • 14. CONSTRUCTING THEN To add to your script, you can now add a THEN statement: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;;} This will only display this text if the username is webmaster. If not, nothing will be displayed. You can actually leave an IF statement like this, as there is no actual requirement to have an ELSE part. This is especially useful if you are using multiple IF statements.
  • 15. CONSTRUCTING ELSE Adding The ELSE statement is as easy as the THEN statement. Just add some extra code: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;; } else { echo &quot;We are sorry but you are not a recognized user&quot;;} Of course, you are not limited to just one line of code. You can add any PHP commands in between the curly brackets. You can even include other IF statements (nested statements).
  • 16.
  • 17. WHILE STATEMENT If you have a piece of code which you want to repeat several times without retyping it, you can use a while loop. For instance if you wanted to print out the words &quot;Hello World&quot; 5 times you could use the following code: $times = 5; $x = 0; while ($x < $times) { echo &quot;Hello World&quot;; ++$x;}
  • 18. USING $X The variable counting the number of repeats ($x in the above example) can be used for much more than just counting. For example if you wanted to create a web page with all the numbers from 1 to 1000 on it, you could either type out every single one or you could use the following code: $number = 1000; $current = 0; while ($current < $number) { ++$current; echo &quot;$current<br>&quot;;}
  • 19. ARRAY Arrays are common to many programing languages. They are special variables which can hold more than one value, each stored in its own numbered 'space' in the array. Arrays are extremely useful, especially when using WHILE loops.
  • 20. TYPES OF ARRAY In PHP, there are three kind of arrays: * Numeric array - An array with a numeric index * Associative array - An array where each ID key is associated with a value * Multidimensional array - An array containing one or more arrays
  • 21. SETTING UP AN ARRAY Setting up an array is slightly different to setting up a normal variable. In this example I will set up an array with 5 names in it: $names[0] = 'John'; $names[1] = 'Paul'; $names[2] = 'Steven'; As you can see, the parts of an array are all numbered, starting from 0. To add a value to an array you must specify the location in the array by putting a number in [ ].
  • 22. PHP WITH FORMS Setting up a form for use with a PHP script is exactly the same as normal in HTML. As this is a PHP tutorial I will not go into depth in how to write your form but I will show you three of the main pieces of code you must know: <input type=&quot;text&quot; name=&quot;the box&quot; value=&quot;Your Name&quot;> Will display a text input box with Your Name written in it as default. The value section of this code is optional. The information defined by name will be the name of this text box and should be unique. <textarea name=&quot;message&quot;> Please write your message here. </textarea> Will display a large scrolling text box with the text 'Please write your message here.' as default. Again, the name is defined and should be unique. <input type=&quot;submit&quot; value=&quot;Submit&quot;> This will create a submit button for your form. You can change what it says on the button by changing the button's value.
  • 23. GET METHOD The built-in $_GET function is used to collect values from a form sent with method=&quot;get&quot;. Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max. 100 characters). Example <form action=&quot;welcome.php&quot; method=&quot;get&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL sent to the server could look something like this: http://www.w3schools.com/welcome.php?fname=Peter&age=37 The &quot;welcome.php&quot; file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array): Welcome <?php echo $_GET[&quot;fname&quot;]; ?>.<br /> You are <?php echo $_GET[&quot;age&quot;]; ?> years old!
  • 24. POST METHOD The built-in $_POST function is used to collect values from a form sent with method=&quot;post&quot;.Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.Example <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL will look like this: http://www.w3schools.com/welcome.php The &quot;welcome.php&quot; file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome <?php echo $_POST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old.
  • 25. READING FROM AN ARRAY Reading from an array is just the same as putting information in. All you have to do is to refer to the array and the number of the piece of data in the array. So if I wanted to print out the third name I could use the code: echo &quot;The third name is $names[2]&quot;; Which would output: The third name is Steven
  • 26. PHP FUNCTIONS In PHP, there are more than 700 built-in functions. This chapter shows how to create your own functions. A function will be executed by a call to the function. You may call a function from anywhere within a page. Syntax: function functionName() { code to be executed; }
  • 28. Mail is extremely easy to send from PHP, unlike using scripting languages which require special setup (like CGI). There is actually just one command, mail() for sending mail. It is used as follows: mail($to,$subject,$body,$headers); In this example I have used variables as they have descriptive names but you could also just place text in the mail command. Firstly, $to. This variable (or section of the command) contains the e-mail address to which the mail will be sent. $subject is the section for the subject of the e-mail and $body is the actual text of the e-mail.The section $headers is used for any additional e-mail headers you may want to add. The most common use of this is for the From field of an e-mai but you can also include other headers like cc and bcc. MAIL COMMAND
  • 29. SENDING MAIL Before sending your mail, if you are using variables, you must, of course, set up the variable content beforehand. Example: $to = &quot;php@gowansnet.com&quot;; $subject = &quot;PHP Is Great&quot;; $body = &quot;PHP is one of the best scripting languages around&quot;; $headers = &quot;From: webmaster@gowansnet.com&quot;; mail($to,$subject,$body,$headers); echo &quot;Mail sent to $to&quot;; This code will acutally do two things. Firstly it will send a message to php@gowansnet.com with the subject 'PHP Is Great' and the text: PHP is one of the best scripting languages around and the e-mail will be from webmaster@gowansnet.com. It will also output the text: Mail sent to php@gowansnet.com
  • 30. ERROR CONTROL As anyone who has been scripting for a while will know, it is extremely easy to make mistakes in your code and it is also very easy to input an invalid e-mail address (especially if you are using your script for form to mail). Because of this, you can add in a small piece of code which will check if the e-mail is sent: if(mail($to,$subject,$body,$headers)) { echo &quot;An e-mail was sent to $to with the subject: $subject&quot;;} else { echo &quot;There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid&quot;;} This code is quite self explanatory If the mail is sent successfully it will output a message to the browser telling the user, if not, it will display an error message with some suggestions for correcting the problem.
  • 31. PHP INSTALLATION The Windows PHP installer is available from the downloads page at » http://www.php.net/downloads.php. This installs the CGI version of PHP and for IIS, PWS, and Xitami, it configures the web server as well. The installer does not include any extra external PHP extensions (php_*.dll) as you'll only find those in the Windows Zip Package and PECL downloads. First, install your selected HTTP (web) server on your system, and make sure that it works. Run the executable installer and follow the instructions provided by the installation wizard. Two types of installation are supported - standard, which provides sensible defaults for all the settings it can, and advanced, which asks questions as it goes along. The installation wizard gathers enough information to set up the php.ini file, and configure certain web servers to use PHP. One of the web servers the PHP installer does not configure for is Apache, so you'll need to configure it manually. Once the installation has completed, the installer will inform you if you need to restart your system, restart the server, or just start using PHP.
  • 32. PHP INI FILE Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect. In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files. Two new INI directives, user_ini.filename and user_ini.cache_ttl control the use of user INI files. user_ini.filename sets the name of the file PHP looks for in each directory; if set to an empty string, PHP doesn't scan at all. The default is .user.ini. user_ini.cache_ttl controls how often user INI files are re-read. The default is 300 seconds (5 minutes).