Trouble with Cookies

Chris Kelleher

Administrator
Staff member
I have written the following code to set cookies for session ID and user ID:

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
<script language="Speedscript">
run set-sid(input v-user-id,
input "Logged In",
output v-sic,
output v-uic,
output v-sid,
output v-uid).
</script>

<script language="Speedscript">
Procedure output-headers:
set-cookie("Jooky","Jooky",?,?,?,?,?).
set-cookie(v-sic,v-sid,?,?,?,?,?).
set-cookie(v-uic,v-uid,?,?,?,?,?).
end procedure.
</script>
[/code]

Currently, the only cookie that gets set is "jooky". The other 4 variables
are all being set proparly by the earlier procedure call. I'm wondering of
you can use variables like this to set a cookie, or does it always have to
be a literal. It wouldn't seem practical to only allow literal cookies, but
all the Webspeed examples I have found so far are always setting literal
cookies. I'm thinking my variables may not be set when the procedure is
called.

Any help would be appreciated.

Roland Schaer
Senior Programmer/Analyst
RAM Software Systems, Inc.
Roland.Schaer@ramsys.com
972-669-0763
 

Chris Kelleher

Administrator
Staff member
Place your run set-sid() statement inside the output-headers procedure.
Then it will work. Output headers gets run before anything else.

You'll probably catch some flak about setting a UserID in the cookie.
You should only set the session id, and use it to lookup the userid.
Remember that people can set their own cookies, so your code shouldn't
trust the cookie values coming in to have the correct user ID.

There's more about this in the WebSpeed FAQ: http://www.whosplayin.com/ws

Hope that helps,

-Steve
 

Chris Kelleher

Administrator
Staff member
I think you are right, your varibles are not set yet. You may wish to set them
in the output-headers procedure. This is the first code that is run before any
of you "regular" code is executed. If your varible's values are dependent on
the regular code, they wont be set yet. To get around this, you would need to
set them in output headers, or in the e4gl.i include file found at the top
(which makes the call to output headers).
 

Chris Kelleher

Administrator
Staff member
Thanks for the help...

moving the code fixed a majority of the problems. I made some other tweaks,
including getting rid of the User ID stuff. The session file contains the
user ID so I really didn't need to set a cookie.

RTS
 

Chris Kelleher

Administrator
Staff member
The problem is that the output-headers (internal) procedure is being
run first, before the first line of embedded speedscript that does the
"run set-sid(...)".

You want to add the "run set-sid(..)" to the output-headers procedure
itself so that it will get executed in the correct order.
 
Top