source: trunk/username.cgi @ 41

Last change on this file since 41 was 41, checked in by Earle Martin, 19 years ago

fixed incorrect comparison operator

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1#!/usr/bin/perl -w
2
3use strict;
4use CGI;
5use CGI::Carp qw/fatalsToBrowser/;
6use CGI::Cookie;
7
8my $cgi = CGI->new();
9
10my $set = $cgi->param('set') || '';
11my $username = $cgi->param('username') || '';
12
13my ($cookie, %cookies, $cookieset);
14
15if (!$set) {
16        print "Content-Type: text/html; charset=utf-8\n\n";
17        print <<HTML;
18<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
19<html lang="en-gb">
20<head>
21        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22        <title>Username - set cookie</title>
23        <link rel="stylesheet" type="text/css" href="http://grault.net/grubstreet/grubstreet.css" title="stylesheet">
24</head>
25<body>
26<div id="content">
27<h1>Username</h1>
28<p>
29Use this form to set a cookie in your browser of how you wish to be
30identified in Recent Changes.
31</p>
32<form action="username.cgi" method="post">
33<input type="text" size="20" name="username"> 
34<input type="submit" value="Set it">
35<input type="hidden" name="set" value="yes">
36</form>
37</div>
38</body>
39</html>
40HTML
41
42}
43
44else {
45        &set_cookie;
46        print "Content-Type: text/html; charset=utf-8\n\n";
47
48        print <<HTML;
49<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
50<html lang="en-gb">
51<head>
52        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
53        <title>Username - cookie delivered</title>
54        <link rel="stylesheet" type="text/css" href="http://grault.net/grubstreet/grubstreet.css" title="stylesheet">
55</head>
56<body>
57<div id="content">
58<h1>Cookie set</h1>
59<p>
60You set
61HTML
62
63if ($cookieset eq "") {
64        print "\"$username\"";
65}
66else {
67        print '"' . &get_cookie . '"';
68}
69
70print <<HTML;
71 as your username.
72</p>
73<p>
74<a href="wiki.cgi">Return to the wiki</a>
75</p>
76</div>
77</body>
78</html>
79HTML
80
81}
82
83sub set_cookie {
84        $cookie = CGI::Cookie->new(     -name    =>  'username',
85                                        -value   =>  $username,
86                                        -expires =>  '+12M' );
87       
88        print "Set-Cookie: $cookie\n";
89}
90
91sub get_cookie {
92        %cookies = fetch CGI::Cookie;
93        $cookieset = $cookies{'username'}->value;
94        return $cookieset;
95}
Note: See TracBrowser for help on using the repository browser.