Insert a PHP script
A PHP script starts with <?php and ends with ?>. A PHP script block can appear anywhere in a PHP file. In Microsoft Expression Web, you can quickly insert commonly used PHP code snippets into your page by clicking PHP Script on the Insert menu. You can then customize those scripts to meet your needs.
For more information about PHP, see the PHP Tutorial
on the W3 Schools website.
To insert a PHP script
-
On the Insert menu, point to PHP Script, and then click one of the following:
Form Variable
Inserts the following code block:
<?php $_POST[]; ?>The
$_POSTmethod is used to collect information from a form when the information is sent using the HTTP post method (method="post").For more information about PHP forms, see PHP Forms and User Input
on the W3 Schools website. For more information about the POST variable, see $_POST
on the W3 Schools website.URL Variable
Inserts the following code block:
<?php $_GET[]; ?>The
$_GETmethod is used to collect information from a form when the information is sent using the HTTP GET method (method="get"). Information collected using the GET method is displayed in the URL.For more information about PHP forms, see PHP Forms and User Input
on the W3 Schools website. For more information about the GET variable, see $_GET
on the W3 Schools website.Session Variable
Inserts the following code block:
<?php $_SESSION[]; ?>A session is the amount of time that an individual user spends at your website. By using a session variable, you can save information and make that information available to other pages that the user visits in the same session.
For more information about PHP sessions, see PHP Sessions
on the W3 Schools website.Cookie Variable
Inserts the following code block:
<?php $_COOKIE[]; ?>A cookie is a small file that is saved to the visitor's computer by the server in order to identify the computer. The PHP $_COOKIE variable is used to retrieve a cookie value from the computer.
For more information about PHP cookies, see PHP Cookies
on the W3 Schools website.Include
Inserts the following code block:
<?php include(); ?>You can insert a file into a page by using an
includestatement. When using anincludestatement, the included file is retrieved and then displayed in the page when the page is requested from the server. Theincludestatement is similar to arequirestatement, except that theincludestatement does not require the successful execution of the script in order to display the page.For more information about PHP include files and the include() function, see PHP Include Files
on the W3 Schools website.For more information on using PHP includes in Expression Web, see Include a file in a PHP page.
Require
Inserts the following code block:
<?php require(); ?>You can insert a file into a page by using a
requirestatement. Like theincludestatement, the included file is retrieved and then displayed in the page when the page is requested from the server. However, unlike theincludestatement, arequirestatement requires the successful execution of the script in order to display the page.For more information about PHP include files and the require() function, see PHP Include Files
on the W3 Schools website.Code Block
Inserts the following code block:
<?php ?>PHP scripts begin with
<?phpand end with?>. Any text typed between the start and end script tags will be interpreted as PHP scripting.For more information about PHP, see the PHP Tutorial
on the W3 Schools website. Echo
Inserts the following code block:
<?php echo ?>Echo statements are displayed as HTML in the browser. For example, the statement
<?php echo "<p>Hello World</p>"?>appears as<p>Hello World</p>in the source code of the page, and is displayed as Hello World in the browser.For more information about
echostatement, see PHP Syntax
on the W3 Schools website.Comment
Inserts the following code block:
/* */PHP comments begin with
/*and end with*/. Any text typed between the start tag and the end tag of the comment will not be displayed in the browser.For more information about PHP comments, see PHP Syntax
on the W3 Schools website.If
Inserts the following code block:
<?php if ?>An
ifstatement checks whether certain conditions exist. Anifstatement is usually followed by a statement or series of statements. If the condition is true, the statements following theifstatement are executed. If the condition is false, the statements following theifstatement are not executed.For more information about PHP
ifstatements, see PHP If…Else Statements
on the W3 Schools website.Else
Inserts the following code block:
<?php else ?>An
elsestatement is optional when using anifstatement. Like theifstatement, anelsestatement is usually followed by a statement or series of statements to be executed. Anelsestatement is only executed if the condition for theifstatement preceding it is false.For more information about PHP
elsestatements, see PHP If…Else Statements
on the W3 Schools website.