Professional Documents
Culture Documents
Dynamic Web Programming: Application and Transfer
Dynamic Web Programming: Application and Transfer
ASP Introduction
Microsoft’s
VBScript Tutorial & Language Reference
(also here)
WebMonkey’s tutorial
ColdFusion
Easy-to-learn Server-Side Scripting Language:
CFML, or Cold Fusion Markup Language, is
embedded in HTML code
CF code is enclosed in or by CF tags:
– <CFtagname CF code >
– <Cftagname > CF Code </Cftagname >
Documents must end in .cfm
ColdFusion is Case Insensitive
Example (code, copy of database)
ColdFusion Key Points (1)
Ubiquitous
– Originally designed to be a better general purpose
tool than a Unix shell, it has grown and spread to
be supported from Windows to Macintosh to VMS.
Powerful but Cryptic
Example (code)
Perl Key Points (1)
The file itself must end in “.cgi” or “.pl”
First line must specify the location of the Perl
engine (The DBI module will not work for
“#!/usr/local/bin /perl[5]” – see below):
– #!/uva/bin/perl -w
First printed line must be the following if you
want its response to go to a browser:
– print "Content-type: text/html\n\n";
Perl Key Points (3)
Example
Add Source
Index Source
PHP: Hypertext Preprocessor (PHP
)
HTML embedding scripting language (see the
PHP online manual
When a browser calls a PHP document, the
Server reads the PHP document and
– Runs the PHP code
– Returns the resulting HTML code to the browser
Example (code)
PHP Key Points (1)
#!/usr/local/bin/php
<html>
<body>
<?php
echo “Hello I am a PHP script”;
?>
</body>
</html>
First file
Save the file with a PHP extension in your
public_html folder.
Give the webserver execute permission
(chmod 755 hello.php is the easiest way to
do this)
Point a webserver at the file
Let’s look at the first line of the file
#!/usr/local/bin/php
Something more Useful
<?php
echo $_SERVER["REMOTE_ADDR”];
?>
What is echo(); ?
echo() is a PHP function which prints output to the webpage, php has
many functions that do this, print(), printf() are two examples.
What is $_SERVER?!
$_SERVER is a special reserved PHP variable that contains all web server
information. It's known as an Autoglobal (or Superglobal).
Mixin and matchin PHP & HTML
<?php
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {
?>
<h3>strstr must have returned true</h3>
<center><b>You are using Internet Explorer</b> </center>
<?php
} else { ?>
<h3>strstr must have returned false</h3> <center><b>You are not using Internet
Explorer</b></center>
<?php } ?>
Here we see you can mix and match HTML and PHP together, this is because PHP does the PHP bit
first, it’s output is HTML and then bangs all the HTML together.
PHP Forms
Forms are a useful part of any internet site, and I’m sure you’ve used
them in the past. Forms are part of HTML, however you can pass their
values to a PHP script. Here is a simple HTML form which you can put
in any HTML file:
<form action="action.php" method="POST">
Your name: <input type="text" name="name">
Your age: <input type="text" name="age">
<input type="submit">
</form>
This isn’t specific to PHP, the only thing to notice is how we pass the
values to “action.php”
Handling POST data
If:
$hey = TRUE;
If($hey) {
printf(“Hello\n”);
} else {
printf(“Never gona see this!\n”);
}
While
$a = 0;
While($a < 100) {
printf(“hello $a\n”);
a++;
}
Prints all the numbers from 0 to 99.
For & others
For($a = 0; $a < 100; $a++){
printf(“Hello $a\n”);
}
//prints all the numbers from 0 to 99 again
PHP has also all the other control structures you can think of, until, do,
switch, : ?
Global Variables
We’ve already seen the use of some global or Super variables in
$_POST and $_SERVER. There’s a good few of them which
can be useful to make your site more personal. To get a list of
them, create this PHP file.
#!/usr/local/bin/php
This helpdesk tutorial like the others is just geared to get you started at
PHP coding. PHP’s website is the best resource for consultation,
www.php.net it has a simple to follow tutorial (you might find striking
resemblances with tonite’s!), as well as a manual page for every
function in PHP. I recommend you go to the site for more detailed
descriptions of what we did tonite.
Why is PHP good?