Welcome to Fluency in Technology

Download Report

Transcript Welcome to Fluency in Technology

SERVER
web page
repository
WEB PAGE
instructions stores
information and
instructions
BROWSER
retrieves web page
and follows
instructions
2
Web
Server
Pages
Server
1 3
Browser
Client

Two places you can
change
› Browser: JavaScript
› Server: php

General rule:
2
Web
Server
Pages
Server
1 3
› do it in the browser
if you can

Consider the
difference in the
date function…
Browser
Client
 PHP
› > 25 million websites use PHP
› 1/3 of the top million
 JavaScript
› Used by majority of websites
› Almost no browsers preclude its use
2
Web
Server
Retrieve the web page
 Reads each line
Server

› If NOT php, sends it on
› If php,
 Performs the action
 Sends it on
Pages
3

If I look in komodo
edit…
2
Web
Server
Pages
Server
1 3

If I look through
view page
source…
Browser
Client

Files must be .php rather than .html
› Servers will use index.php if no index.html

PHP command format
› <?php …; ?>
› Commands always end with ;

Comments
› Single line:
// comment
› Multiple line
/* line
continues */

Need to UPLOAD before viewing
The following is a basic example to output text using PHP
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo “<b>Hello World!</b>";
?>
</body>
</html>
Running on the server (isis), you would see “Hello World!” displayed.
Display content according to the day of the week
<?php
if (date(“w”) == 5){
{echo “See you Monday!”; }
else
{echo “See you tomorrow!”;}
?>
if statement checks
numerical day of the
week (0=Sunday…
6=Saturday)
If equal to 5 (Fri) ,
display everything
within the first { }
bracket
If not equal to 5,
display everything in
the second { } bracket
If we run the script on a Friday, we should see:
“See you Monday!”
On other days, we will see:
“See you tomorrow!”
- Any changes to header or footer only require editing of a
single file. This reduces the amount of work necessary for
site maintenance and redesign.
- Helps separate the content and design for easier maintenance
Header
Page 1
Content
Page 2
Content
Page 3
Content
Footer
Page 4
Content
Page 5
Content
Basic template to use on all of the pages.
Make sure you name the files with a .php extension
Assume the header and footer files are located in the same directory.
Note that comments are PHP comments.
<body>
<?php
// header
include(“header.php”);
?>
Insert content here!
<?php
// footer
include(“footer.php”);
?>
</body>
<!– header.php 
<table class=“header”>
<tr>
<td>
<div align=center> Page Title </div>
</td>
</tr>
</table>
<!– end header.php 
Any html can be used
 Best practice
 Use balanced HTML tags
 Start and end with comments for visibility

<!--footer.php 
<table class=“footer”>
<tr>
<td>
<div class=“center”>
UC Riverside Department
</div>
</td>
</tr>
</table>
<!– end footer.php 
You MAY, you NEED NOT
 If you are interested,

› Decide what function it brings
› Commands to start with
 echo to create HTML tags or text
 date