Server Side Scripting - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Server Side Scripting

Description:

arrays - (list) - collection of scalars - begins w ... All start w/ shebang line #! Contains the location of the Perl interpreter ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 13
Provided by: Pau1206
Category:

less

Transcript and Presenter's Notes

Title: Server Side Scripting


1
Server Side Scripting
  • CGI refresher
  • Part of HTTP protocol set
  • Non-platform dependent
  • Different languages used to implement
  • C / C
  • Java
  • Perl
  • Python
  • Tcl
  • Rexx

2
Server Side Scripting
  • Perl (Practical Extraction Reporting Lang.)
  • Created by Larry Wall in 1986 to create reports
  • Building blocks
  • numbers and strings
  • You have won 5
  • You have won prize

3
Server Side Scripting
  • Building Blocks (continued)
  • scalars - individual piece of data - begins w/
  • address 123 Woods Lane
  • arrays - (list) - collection of scalars - begins
    w/ _at_
  • _at_personalinfo (45, smith, 123 Woods Lane)
  • hashes - (associative array) - begins w/
  • collection of scalars in pairs - the first
    element in each pair is called the key and is the
    label for the second (value)
  • allinfo (age, 45, name, smith)

4
Server Side Scripting
  • Creating Perl CGI scripts
  • Vi and Pico vs. Notepad
  • Save w/ .cgi extension or .pl and put in cgi-bin
    subdirectory (/home/httpd/cgi-bin)
  • All start w/ shebang line !
  • Contains the location of the Perl interpreter
  • To find on your server, type which perl at
    prompt
  • ex. !/usr/bin/perl or !/usr/local/bin/perl
  • Example - CS299perl1.cgi

5
Server Side Scripting
  • Launching your code
  • perl -c filename (watch for post/get scripts)
  • a href URL to Perl script or type w/in browser
  • prompt - perl ltfilenamegt
  • Form action

6
Server Side Scripting
  • Environement Variables
  • Passed with each CGI connection
  • Stored in ENV hash
  • REQUEST_METHOD stores method
  • QUERY_STRING stores GET data
  • STDIN stores POST data
  • Example - CS299perl3.cgi
  • Parse subroutine needed to extract data
  • browser ENVHTTP_USER_AGENT

7
Server Side Scripting
  • Creating output for browsers
  • print Content-type text/html \n\n
  • lttagsgt used within
  • ltbrgt used for html, \n used for readability

8
Server Side Scripting
  • Email using Perl
  • Using installed mail service (sendmail)
  • Parse data w/in ENV hash
  • open and pipe data to mail service
  • Example - CS299perl5.cgi
  • Network configuration on server
  • default gateway set to 10.1.1.100
  • DNS set to 172.16.17.16

9
Server Side Scripting
  • Cookies
  • Setting a cookie
  • Print Set-Cookie
  • namevalue
  • expiresDD-MMM-YY HHMMSS (in GMT)
  • domainjuniata.edu
  • path/cgi-bin/
  • secure
  • \n

10
Server Side Scripting
  • Cookies (continued)
  • Expire date - specifies a date string that
    defines the valid life time of that cookie. If
    none given, the cookie expires when the user
    session ends.
  • Domain - validates which domain can retrieve
    cookie. Can be absolute or tail match
  • Path - used to specify the subset of URLs in a
    domain for which the cookie is valid. Must pass
    the domain first.
  • Secure - must be sent via SSL

11
Server Side Scripting
  • Cookie examples
  • setcookie.cgi
  • updcookie.cgi
  • delcookie.cgi
  • getcookie.cgi
  • Form examples
  • cs299perl4.cgi
  • cs299perl4a.cgi
  • cs299perl4b.cgi

12
Server Side Scripting
  • Hands-on and helpful tips
  • Complete cs299perl1.cgi and cs299perl3.cgi
  • Location - /home/httpd/cgi-bin/
  • reference http//10.1.1.x/cgi-bin/filename.cgi
  • Permission errors? Chmod 755
  • Configuration files (under /etc/httpd/conf)
  • access.conf - virtual directory setup for cgi-bin
  • srm.conf - script alias for cgi-bin and handler
    (.cgi .pl)
  • stop and restart httpd service
  • /etc/rc.d/init.d/httpd stop (start)
Write a Comment
User Comments (0)
About PowerShow.com