Forum Moderators: coopster

Message Too Old, No Replies

What's the cleanest way to set session vars from HTML

session html vars

         

jezzer300

1:02 pm on Oct 20, 2004 (gmt 0)

10+ Year Member



I have a page that displays pictures, large or small.

I want to detect the current size using session vars and avoid any additional text on the end of my web address (ie.?action=new&large)

Currently to set large pictures the user clicks a button which redirects the user back to the current page with "&large" on the end of the web address.

My PHP then sets the session varaible when it detects this, next time the page is loaded it remembers.

if (isset($_REQUEST['large']) $_SESSION['large'] = 1;

$picSize=150;
if (isset($_SESSION['large']))
if ($_SESSION['large'] == 1) $picSize=250;

Advice.

---

Also, how do those websites keep just the main web address www.#*$!.com at the top and stop showing the full address. /products/list.php. Other than using frames I can't see how it's done.

Perhaps some clever .htaccess mod?

mincklerstraat

1:14 pm on Oct 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the main page on sessions in the php manual, you'll find a configuration value that you can set with ini_set() which makes sessions use cookies only, which will prevent you from getting the session ID in the url.

As for your second question, this 'could' be done some other way than frames but it would be very goofy indeed. I'd see the display of the real, full url in the address bar as an advantage rather than a disadvantage.

jezzer300

1:20 pm on Oct 20, 2004 (gmt 0)

10+ Year Member



Hi,

Thanks.
I don't quite mean that.

I can hide the session variables. I already use session cookies if available. However, when the user first clicks a button and I want that action to change a session var, is this the only way to do it, post a variable to the script, detect this and set the session varaible.

coopster

10:40 pm on Oct 20, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You can use the GET method (appending it to the url query string) or you could use a form using the method="post" as well.

jezzer300

8:44 am on Oct 21, 2004 (gmt 0)

10+ Year Member



Okay, Thanks.

So what ever I do the user will always see something on the end of the URL.

I did hear about using javascript to update the session cookie, that's transparent, but obviously you need to have cookies enabled, which isn't always the case for my users.

Regards,

Jez.

coopster

11:48 am on Oct 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No, the form method="post" will not append anything to the url -- you are referring to the "get" method. "post" has the value in an <input> form element.

jezzer300

12:12 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Is there a clean way to post variables with out creating a form within the HTML script.

Currently I append?variable=#*$!x to the URL.

Can I easily setup variables and post them to the next PHP script?

I'm running PHP verion 4.3.8

Thanks.

timster

4:19 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a clean way to post variables with out creating a form within the HTML script.

The data you send is either going to be in the URL or a form. If you are trying to create a pretty URL to set variables, that's possible with mod_rewrite (assuming you're using Apache).

So with a little work your link could send the user to

/dir/new_large

.. instead of: /dir/picture.php?new&large

[httpd.apache.org ]

jezzer300

4:41 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Thanks very much for the replies.

That answers all my questions.