PDA

View Full Version : setting cookies


Peter_Chea
06-09-2003, 08:53 AM
It there a way to set cookies in laszlo?

antun
06-09-2003, 11:09 AM
Yes - you can set the cookie using client side JavaScript, for example:


<canvas>
<simplelayout spacing="5"/>
<windowtext name="fooVal">bar</windowtext>
<button>Set Cookie
<method event="onclick">
// Build up a string like:
// javascript: document.cookie = "foo=bar"; void(0);
var s ='javascript:';
s += 'document.cookie="foo='+ fooVal.getText();
s += '"; void(0);';
LzBrowser.loadURL( s );
</method>
</button>
<button>get Cookie
<method event="onclick">
LzBrowser.loadURL('javascript:alert(document.cooki e)');
</method>
</button>
</canvas>


The void(0) prevents the browser from trying to access the javascript.... URL.

-Antun

Peter_Chea
06-09-2003, 02:14 PM
Thanks, since laszlo have access to the browser, is it wrong to assume everything you can do in the browser with javascript, you can do it on a laszlo app?

antun
06-09-2003, 02:22 PM
No you can't do everything for security reasons. For example you can't submit an HTML form using the method I described in all browsers. Also, you can't call a method in browser-javascript from a Laszlo app and capture its return value for use in the Laszlo app, although there are probably crafty workarounds.

-Antun

Pedro
10-09-2005, 02:54 AM
Hello antun,

Your example is very useful to me. I have to prepare an application that must validate user/password against a MySql database. I will program the authentication in PHP.

I set the cookie correctly using your code, but... How can I get the cookie value to use it in my Laszlo app.? Other question, How can I drop the cookie? maybe setting the cookie string to NULL?

I've tried many ways but I can't do it.

Thanks very much in advance!!

Pedro
11-17-2005, 09:08 AM
I've solved the problem using PHP cookie management libraries. You can make requests to PHP urls where you can set or get cookie values with a minimun effort.

arunarao
07-21-2006, 01:10 AM
I want to set a cookie in my laszlo. You have written you got the solution using PHP. I dont know PHP.
Can you please tell how to set a cookie in my laszlo login page with username and password stored in it and next time when i load the login page, how can i retrieve the two values stored in cookies and display in respective username and password fields.

Thanks
Aruna