View Source

[examples]
context.wtcl
cookies.wtcl
cookiesIntro.wtcl
errors.wtcl
errorsIntro.wtcl
expr.wtcl
fish.jpg
fish.wtcl
flush.wtcl
flushIntro.wtcl
form.wtcl
formIntro.wtcl
index.wtcl
ready.wtcl
scripting.wtcl
scripting.wtcl~
scriptingIntro.wtcl
session.wtcl
sessionIntro.wtcl
uploads/
uploads.wtcl
uploadsIntro.wtcl
virtual.wtcl
virtualIntro.wtcl
File: / examples / cookies.wtcl

Lines Size Modified Created Owner MIME Types
317 7,312 2010/05/18 23:04:06 2011/06/13 15:35:16 BUILTIN\Administrators application/x-wtcl, text/x-wtcl

0001
<?
0002
0003
include ../lib/examplePage.wtcl
0004
0005
::wt::examples::setTitle "Cookies"
0006
0007
set vals [params getAll val {}]
0008
0009
# To create a cookie, set the properties, then call
0010
# responseCookies add
0011
0012
if {[params get action ""] == "set"} {
0013
  set cookie [cookie create]
0014
  cookie name cookie [params get name]
0015
0016
  set newValues [list]
0017
  foreach val $vals {
0018
    if {$val != ""} {
0019
      lappend newValues $val
0020
    }
0021
  }
0022
  cookie allValues cookie $newValues
0023
0024
  cookie expires cookie [params get expires]
0025
  cookie path cookie [params get path]
0026
  cookie domain cookie [params get domain]
0027
  cookie secure cookie [params get secure 0]
0028
0029
  responseCookies add $cookie
0030
}
0031
0032
# To delete a cookie, send a cookie with the same
0033
# parameters and no value
0034
0035
if {[params get action ""] == "delete"} {
0036
  set cookie [cookie create]
0037
  cookie name cookie [params get delName]
0038
  cookie markExpired cookie
0039
  cookie path cookie [params get delPath]
0040
  cookie domain cookie [params get delDomain]
0041
  cookie secure cookie [params get delSecure 0]
0042
  responseCookies add $cookie
0043
}
0044
0045
set refreshUrl [serverVars get SCRIPT_NAME]
0046
0047
include ../lib/header.wtcl
0048
0049
?>
0050
0051
<?
0052
  if {[params get action ""] == "set"} {
0053
?>
0054
0055
  <h3>Sent New Cookie</h3>
0056
0057
  <p>
0058
  <table cellpadding=0 cellspacing=0 border=0>
0059
    <tr>
0060
      <td width=200><b>Name </b></td>
0061
      <td>[htmlEncode [cookie name $cookie]]</td>
0062
    </tr>
0063
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0064
    <tr valign=top>
0065
      <td><b>Values </b></td>
0066
      <td>
0067
0068
        <? foreach value [cookie allValues $cookie] { ?>
0069
0070
          [htmlEncode $value]<br>
0071
0072
        <? } ?>
0073
0074
      </td>
0075
    </tr>
0076
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0077
    <tr>
0078
      <td><b>Expires </b></td>
0079
      <td>[htmlEncode [cookie expires $cookie]]</td>
0080
    </tr>
0081
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0082
    <tr>
0083
      <td><b>Path </b></td>
0084
      <td>[htmlEncode [cookie path $cookie]]</td>
0085
    </tr>
0086
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0087
    <tr>
0088
      <td><b>Domain </b></td>
0089
      <td>[htmlEncode [cookie domain $cookie]]</td>
0090
    </tr>
0091
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0092
    <tr>
0093
      <td><b>Secure </b></td>
0094
      <td>[htmlEncode [cookie secure $cookie]]</td>
0095
    </tr>
0096
  </table>
0097
  </p>
0098
0099
<? } ?>
0100
0101
<? if {[params get action ""] == "delete"} { ?>
0102
0103
  <h3>Deleted Cookie</h3>
0104
0105
  <p>
0106
  <table cellpadding=0 cellspacing=0 border=0>
0107
    <tr>
0108
      <td width=200><b>Name </b></td>
0109
      <td>[htmlEncode [params get delName]]</td>
0110
    </tr>
0111
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0112
    <tr>
0113
      <td><b>Expires </b></td>
0114
      <td>[htmlEncode [cookie expires $cookie]]</td>
0115
    </tr>
0116
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0117
    <tr>
0118
      <td><b>Path </b></td>
0119
      <td>[htmlEncode [params get delPath]]</td>
0120
    </tr>
0121
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0122
    <tr>
0123
      <td><b>Domain </b></td>
0124
      <td>[htmlEncode [params get delDomain]]</td>
0125
    </tr>
0126
    <tr><td colspan=2><br style="line-height: 3px;"></td></tr>
0127
    <tr>
0128
      <td><b>Secure </b></td>
0129
      <td>[htmlEncode [params get delSecure ""]]</td>
0130
    </tr>
0131
  </table>
0132
  </p>
0133
0134
<? } ?>
0135
0136
<h3>Client Cookies</h3>
0137
0138
<p><a href="[htmlEncode $refreshUrl]">Refresh Page</a></p>
0139
0140
<p>
0141
<table cellpadding=0 cellspacing=0 border=0>
0142
  <tr>
0143
    <td width=200><b>Items: </b></td>
0144
    <td>[cookies count]</td>
0145
  </tr>
0146
  <tr valign=top>
0147
    <td width=200><b>Request header: </b></td>
0148
    <td>[htmlEncode [requestHeaders get cookie ""]]</td>
0149
  </tr>
0150
</table>
0151
</p>
0152
0153
<? if {[cookies count]} { ?>
0154
0155
  <p>
0156
  <table cellpadding=3 cellspacing=1 bgcolor=#aaaaaa border=0 width=500>
0157
    <tr bgcolor=#eeeeee>
0158
      <td align=center style="padding: 3px;"><b>Name</b></td>
0159
      <td align=center style="padding: 3px;"><b>Values</b></td>
0160
    </tr>
0161
0162
    <? foreach {name values} [cookies items] { ?>
0163
0164
      <tr valign=top>
0165
        <td bgcolor=white style="padding: 3px;"><?= [htmlEncode $name] ?></td>
0166
0167
        <td bgcolor=white style="padding: 3px;">
0168
0169
          <?
0170
            for {set i 0} {$i < [llength $values]} {incr i} {
0171
              set value [lindex $values $i]
0172
              puts [wt::util::previewString $value 200 1]
0173
              if {$i < [expr [llength $values] - 1]} {
0174
                puts <br>
0175
              }
0176
            }
0177
          ?>
0178
0179
        </td>
0180
0181
      </tr>
0182
0183
    <? } ?>
0184
0185
  </table>
0186
  </p>
0187
0188
<? } else { ?>
0189
0190
<p>No items.</p>
0191
0192
<? } ?>
0193
0194
<h3>Set Cookie</h3>
0195
0196
<p>
0197
<form action="[selfUrl -html]" method=post>
0198
  <p>
0199
  <table cellpadding=0 cellspacing=0 border=0 width=500>
0200
0201
    <tr>
0202
      <td style="padding-bottom: 6px;">
0203
        Name<br>
0204
        <input type=text name=name
0205
          value="[htmlEncode [params get name ""]]">
0206
      </td>
0207
    </tr>
0208
0209
    <tr>
0210
      <td style="padding-bottom: 6px;">
0211
        Values<br>
0212
        <input type=text name=val[]
0213
          value="[htmlEncode [lindex $vals 0]]"><br>
0214
        <input type=text name=val[]
0215
          value="[htmlEncode [lindex $vals 1]]"><br>
0216
        <input type=text name=val[]
0217
          value="[htmlEncode [lindex $vals 2]]"><br>
0218
      </td>
0219
    </tr>
0220
0221
    <tr>
0222
      <td style="padding-bottom: 6px;">
0223
        Expiration date<br>
0224
        <input type=text name=expires value="[htmlEncode [params get expires ""]]"><br>
0225
        <span style="font-size: .9em; font-style: italic;">The expiration date is a GMT string such as
0226
        <code>Thu, 01-Jan-70 00:00:01 GMT</code>
0227
        or a relative time
0228
        such as <code>+1d</code>
0229
        (<code>\[+-\]<i>num</i>\[smhdMy\]</code>).</span>
0230
      </td>
0231
    </tr>
0232
0233
    <tr>
0234
      <td style="padding-bottom: 6px;">
0235
        Path<br>
0236
        <input type=text name=path
0237
          value="[htmlEncode [params get path ""]]">
0238
      </td>
0239
    </tr>
0240
0241
    <tr>
0242
      <td style="padding-bottom: 6px;">
0243
        Domain<br>
0244
        <input type=text name=domain
0245
          value="[htmlEncode [params get domain ""]]">
0246
      </td>
0247
    </tr>
0248
0249
    <tr>
0250
      <td style="padding-bottom: 6px;">
0251
        <input type=checkbox<? if {[params get secure 0]} { ?> checked<? } ?> name=secure> Secure
0252
      </td>
0253
    </tr>
0254
0255
    <tr>
0256
      <td>
0257
        <br>
0258
        <input type=submit value=" OK ">
0259
      </td>
0260
    </tr>
0261
0262
  </table>
0263
  </p>
0264
  <input type=hidden name=action value=set>
0265
</form>
0266
</p>
0267
0268
<h3>Delete Cookie</h3>
0269
0270
<p>
0271
<form action="[selfUrl -html]" method=post>
0272
  <p>
0273
  <table cellpadding=0 cellspacing=0 border=0 width=500>
0274
0275
    <tr>
0276
      <td style="padding-bottom: 6px;">
0277
        Name<br>
0278
        <input type=text name=delName value="[htmlEncode [params get delName ""]]">
0279
      </td>
0280
    </tr>
0281
0282
    <tr>
0283
      <td style="padding-bottom: 6px;">
0284
        Path<br>
0285
        <input type=text name=delPath value="[htmlEncode [params get delPath ""]]">
0286
      </td>
0287
    </tr>
0288
0289
    <tr>
0290
      <td style="padding-bottom: 6px;">
0291
        Domain<br>
0292
        <input type=text name=delDomain value="[htmlEncode [params get delDomain ""]]">
0293
      </td>
0294
    </tr>
0295
0296
    <tr>
0297
      <td style="padding-bottom: 6px;">
0298
        <input type=checkbox<? if {[params get delSecure 0]} { ?> checked<? } ?> name=delSecure> Secure
0299
      </td>
0300
    </tr>
0301
0302
    <tr>
0303
      <td>
0304
        <br>
0305
        <input type=submit value=" OK ">
0306
      </td>
0307
    </tr>
0308
0309
  </table>
0310
  </p>
0311
0312
  <input type=hidden name=action value=delete>
0313
0314
</form>
0315
</p>
0316
0317
<? include ../lib/footer.wtcl ?>