intro to php at winthrop csci 297 scripting languages day one

11
Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Upload: doris-todd

Post on 11-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Intro to PHP at Winthrop

CSCI 297 Scripting LanguagesDay One

Page 2: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

PHPO Server-Side scripting language

interpreted, not compiled

O PHP code is embedded in HTML

O PHP code is run on the server machine by the web server program when someone requests the file

O PHP's output is HTML

O PHP is Open Source

Page 3: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

MySQL

Orelational database management system

Oserver based

Oallows multiple users

Ofast, efficient, robust

Page 4: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

JavaScriptO client-side programming language

O embedded in HTML files

O instructs browser to react to particular events, set attributes of HTML elements, etc.O e.g. popup a new windowO e.g. check a cookie fileO e.g. only submit a form that contains

valid entries

Page 5: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Hello World - your PHP code<html>

<body><P><center>

<?php

function longdate ($timestamp){ return date("l F jS Y", $timestamp);}

echo "Hello World<P>Today is ";echo longdate(time());

?></body>

hello.php

On Deltona this file must end

with .phpnot .html

Page 6: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Hello World - what the user sees

Page 7: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Winthrop's Configuration

O Winthrop's PHP server for students is deltona.birdnest.org

O Your homepage:O http://deltona.birdnest.org/

~acc.yourid/

O The deltona web server looks for all web files in your public_html directory.

O You can edit your files from any linux box on the Winthrop network.

O Your homepage is index.html, not default.htm.

Page 8: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Steps to create your first PHP script

1. Go to your root directorycd

2. Create a public_html directory, if necessarymkdir public_html

3. Make your root directory and the html directory readable by the web server process (it is run by "nobody", not you).

chmod a+x .chmod a+x public_html

4. Move to the html directory and create your script file

cd public_htmlvi hello.phpchmod a+r hello.php

Page 9: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

A Better Example<html><head> <title>Test Program: Send Form to PHP script</title></head>

<Body>

<form method='post' action='simpleformproc.php'>Enter your name:<br><input type='text' name='yourname'><P><input type='submit'></form>

</Body></html>

simpleform.html

Page 10: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

A Better Example<html><head> <title>The processor of simpleform.html</title></head><body><center>Hello&nbsp;

<?php// get name from form$name = $_POST['yourname'];

// did they really enter something?if (strlen($name) == 0) echo "whoever you are.";else echo $name;?></body></html>

simpleformproc.php

Page 11: Intro to PHP at Winthrop CSCI 297 Scripting Languages Day One

Your First HomeworkO Type in my hello.php script and get it to

work.

O Add comments your name assignment number

O Follow the instructions for emailing your work. use the correct subject line