Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Sameer Verma 2001 The Scripting Triangle Sameer Verma [http://verma.sfsu.edu/]http://verma.sfsu.edu/ San Francisco State University All icons or logos.

Similar presentations


Presentation on theme: "© Sameer Verma 2001 The Scripting Triangle Sameer Verma [http://verma.sfsu.edu/]http://verma.sfsu.edu/ San Francisco State University All icons or logos."— Presentation transcript:

1 © Sameer Verma 2001 The Scripting Triangle Sameer Verma [http://verma.sfsu.edu/]http://verma.sfsu.edu/ San Francisco State University All icons or logos are properties of respective owners

2 © Sameer Verma 2001 Script A text file with commands. A sequence of commands. Not compiled, but interpreted. Purpose: Rapid light-weight development.

3 © Sameer Verma 2001 The Code Cycle EditLink CompileRun 12 34

4 © Sameer Verma 2001 The Script Cycle EditLink CompileRun Most user activity takes place here 12 22

5 © Sameer Verma 2001 “Scripting” Engines Good old Perl Active Server Pages (VB Script) Java Server Pages (Java) PHP:Hypertext Preprocessor (PHP) Others

6 © Sameer Verma 2001 PHP A scripting language invented by Rasmus LerdorfRasmus Lerdorf PHP is free: freedom to download and use. PHP is cross-platform. PHP is scalable and reliable. Apache is the most widely used web server in the world (66.49%). PHP is the most widely used module for Apache web server (38.59%). http://www.securityspace.com/s_survey/data/index.html

7 © Sameer Verma 2001 PHP and platforms PHP works on Windows 95, Windows 98, Windows NT Workstation, Windows NT Server, Windows 2000 Professional, all Windows 2000 Server lines and Windows XP. PHP works with all Linux distributions, and variants of Unix. MacOS X

8 © Sameer Verma 2001 PHP and Web servers PHP works with: Apache Microsoft IIS Netscape Server Microsoft PWS Xitami and a handful others.

9 © Sameer Verma 2001 PHP and Databases MySQL mSQL Access MS-SQL Oracle DB2 LDAP* Paradox PostGreSQL Velocis IMAP* Sybase ODBC dBase filePro Informix * LDAP is a Directory Service and IMAP is an email protocol. Both are databases, but used in non-database applications.

10 © Sameer Verma 2001 PHP + MySQL + Apache Free + Free + Free = Value Added PHP works on Windows, Linux, Unix MySQL works on Windows, Linux, Unix Apache works on Windows, Linux, Unix Free = Freedom to use and modify. Free does not necessarily mean $0.00 OpensourceOpensource or GPL ≠ FreewareGPL E-commerce web sites. Database powered portals. Development environment = Production environment. Develop on a Win 98 Laptop. Host on a Unix or Linux based ISP. How:Where:

11 © Sameer Verma 2001 CGI Web server (e.g. Apache) PHP, ASP, etc. Browser CGI x [ ] -? PHP and Apache run as two programs Server-Side Client-Side

12 © Sameer Verma 2001 Module or Server API Web server (e.g. Apache) PHP, ASP, etc. Browser x [ ] -? PHP and Apache run as one program Server-Side Client-Side

13 © Sameer Verma 2001 PHP files PHP files work like HTML. Need no special cgi-bin type directories. Can be embedded inside HTML documents. Can also be written as stand-alone “class” type files for data-processing only.

14 © Sameer Verma 2001 PHP files & more Adding a database to the mix increases the portability of your application. MySQL works really well with PHP. Store user preferences, login/password, content, inventory, etc. in the database. Use the database as a cache for web data.

15 © Sameer Verma 2001 Applications E-commerce sites. Portals. Forums/discussions groups. Web-based E-mail programs. Calendars. Personal Information Managers. WAP, XML

16 © Sameer Verma 2001 Who uses PHP? Dialpad.com, Sourceforge.net, Six.de Audi, Subaru, Honda, Volvo Apache, Be, Fujitsu, NASA, US Army, W3C, Freshmeat, MP3.com, Lycos, SF Giants, Oakland Raiders, NY Yankees, Ericsson, Sprint Canada, Lufthansa, Swatch. BICS 565, BICS 814, ISYS814

17 © Sameer Verma 2001 PHP Sample Create a text file in notepad and type the following green text as-is. Name this file sample.php <?PHP echo (‘This is a test page. This line is printed via an echo statement.’); echo(‘ ’); $remote_ip=getenv('REMOTE_ADDR'); print ("You are accessing the page from $remote_ip"); ?> Note: If you view this on your off-line computer, make sure you open the file in the browser as http://127.0.0.1/sample.php or http://localhost/sample.php http://127.0.0.1/sample.phphttp://localhost/sample.php not file:///C|/Program Files/Apache Group/Apache/htdocs/sample.php If you look at the file as a file:/// it will simply show the source of the php file. To make sure php actually gets processed, ensure that the php file is accessed via a web server. A properly written and processed php file will never leave the server. Only the result of your php code will leave the server. See the source of your page in the browser. Do you see any php? Only HTML. Your php file along with its intellectual copyright is quite intact.

18 © Sameer Verma 2001 PHP Sample You should see something like this: Correct Wrong If you see the php source code as-is, then either check your web server, or check to see how you are accessing the page. It should NOT be a file:/// type URL in the location bar.

19 © Sameer Verma 2001 PHP Sample + More Here is a modification on the sample.php file with more stuff. <?PHP echo (‘This is a test page. This line is printed via an echo statement.’); echo(‘ ’); $remote_ip=getenv(‘remote_addr’); $remote_host=gethostbyaddr($remote_ip); print ("You are accessing the page from numeric IP address $remote_ip"); print ("You are accessing the page from DNS entry $remote_host"); ?> Here we simply re-use the $remote_ip variable to generate another variable namely, $remote_host, which is simply the host name assigned to this IP address. This type of “cascading variable set” is quite common in scripts.

20 © Sameer Verma 2001 PHP Sample + More Here is a script to obtain data from a MySQL database. <?PHP $connection = mysql_connect(“localhost”,“userid”,“password”) or die ("Unable to connect to MySQL server."); $db = mysql_select_db(“database”, $connection) or die ("Unable to select database."); $sql = "SELECT fname, lname, email, nick FROM student WHERE uid = '$uid'"; $sql_result = mysql_query($sql,$connection) or die ("Couldn't get student information"); echo(‘ ’); while ($row = mysql_fetch_row($sql_result)) { print (" First Name: $row[0], Last Name: $row[1] E-mail: $row[2] "); } echo (‘ ’); mysql_close($connection); ?> We connect to a MySQL database using login ”userid” and password ”password” and store it in $connection Then we select the database ”database” and store it in $db Next we specify an SQL statement and store it in $sql We run the query ($sql) and store its result in $sql_result Finally, we use the resulting row(s) to populate a simple HTML table using the values in the query result ($sql_result) Closing the MySQL connection is not really required, but is a nice practice.

21 © Sameer Verma 2001 Get Started This information should get you started. Search for more information on the web. Many PHP projects are available as opensource/free for use. Follow up the links to see more examples of real world applications.

22 © Sameer Verma 2001 Links http://www.php.net http://www.mysql.com http://www.apache.org/ http://www.phpbuilder.com/ http://www.phpwizard.net/ http://www.weberdev.com/ http://www.phpclub.net/ http://px.sklar.com/ http://tecfa.unige.ch/guides/php/ http://www.nusphere.com/ http://www.phorum.org/ http://www.thickbook.com/ http://www.hawhaw.de/ http://www.phpnuke.org/ http://www.midgard-project.org/ http://www.phpworld.com/ http://www.zend.com/ http://www.gimpster.com/php/ http://www.edomex.net/phpopenmonitor/ http://www.hotscripts.com/PHP/


Download ppt "© Sameer Verma 2001 The Scripting Triangle Sameer Verma [http://verma.sfsu.edu/]http://verma.sfsu.edu/ San Francisco State University All icons or logos."

Similar presentations


Ads by Google