Forum OpenACS Q&A: Passing parameters between pages

Posted by Ayman M on
I know of 2 ways to pass parameters between pages at the moment:
- using ad_page_contract to get the variables after a form post
- using additional URL information such as blah?number=2

Im not too keen on the 2nd option unless its just simple information 
as I dont want to send sensitive information in the URL line. Other 
than this method, is it possible to pass a variable to the next page 
without using a form?

The variable im trying to pass is an ID which is open for the user's 
session so I want to access this on every page.

Any ideas?

Posted by Kevin Crosbie on
If the id is to live throughout the session, then you could write it into the session cookie.

Do this using:
ad_set_client_property mymodule idname value

Then you could do something like alter the request processor such that it will put your id into the ad_conn array.
Then you would read it like:
set my_id [ad_conn idname]

Alternatively you could just read from the cookie every time.
set my_id [ad_get_client_property mymodule idname]

Hope this helps

Posted by Dave Bauer on

If it is something that identifies the user, you can store it in a cookie and query that on page loads. OpenACS does that for user_id. The other option is to store it in the database, and query based on user_id.

Other than that I can't think of any way to pass information between pages. That is the way HTTP is designed. There are two operation that are mostly used GET and POST. GET passes the parameters in the URL and is used to retrieve information. POST uses form variables and is used to trigger a change, for example, inserting, deleting or updating a row in the database.

Posted by Kevin Crosbie on
Albeit, ad_set_client_property does not write to the cookie.  ;o)  I was thinking of ad_set_cookie and ad_get_cookie.

ad_set_client_property writes to the sec_session_properties table, mapped against someones session_id, which I think in your case is perfect.

Posted by David Siktberg on
Both GET and POST can be used to launch queries and launch changes.  The key thing is that they both send variable values from the browser to the server, which can use them as it pleases.  In my experience, AOL Server does not differentiate between variables passed in the URL and parameters passed within the HTML headers by a POST.  They both are accessible via ns_getform.  You can even have some of each on a given page:

<form method="POST" action="foo.tcl?var1=blah">
<input type=text name=var2>

will deliver values for both var1 and var2 to the server.

If you examine the HTML headers for your HTTP traffic (I highly recommend that if you want to learn how HTTP requests work - one method for Windows clients is the PC Magazine utility Cookie Cop 2, which has an HTTP viewer), you'll see the embedded variable info from a POST.

Posted by Michael A. Cleverly on
Beneath the hood AOLserver has to read/parse the form variables differently for GET vs POST. But it's up to the programmer to check the value of [ns_conn method] (if need be) to change behaviors depending on which method was used.