views:

418

answers:

2

Hoi!

I have a form I wish to submit, but I need to add the PHPSESSID, because some clients allow no cookies.

There are several javascript functions on my page which displays a list of users (search, sort, open details), the page is generated by PHP.

Now I am looking for an elegant way to have the PHPSESSID included in every submit of my form - this needs to be done on several pages, so I hope for an easy solution. Adding the PHPSESSID to the action or into a hidden field does not work properly.

Or is this problem located elsewhere? It could be the client is behind a too restrictive firewall or something. Any ideas (especially with solutions ;-) ) in that direction are also welcome!

Example code (extremely simplified):

<form name="userlist" method="POST" action="./myuserlist.php">
[...some formfields and stuff..]
</form>

<script>
//one example function, there are several on my page
function next_page()
{
  //set some hidden field to get the next page
  document.forms[0].submit();
}
</script>

Thanks in advance!

Bye, Basty

[EDIT] session.use_trans_sid is set to true

+2  A: 

Using a hidden field should work - if it doesn't then session.use_trans_sid is probably off in your php.ini

You could add it to a hidden field then say

if (!empty($_POST['PHPSESSID']))
   session_start($_POST['PHPSESSID']);
else
    session_start();
Greg
Hoi! "hidden field should work" - the key here is "should" ;) Sadly it doesn't. But I'll try to start the session with the POST-parameter.
bastianhuebner
+2  A: 

When you say putting it into a hidden field doesn't work, can you elaborate on what doesn't work about it?

When faced with a situation where every (or a lot) of form submits need some state information to be passed, an input type=hidden field is the canonical way to do it.

Just guessing in the dark here. Are you doing something like an input with style="display:none" or something like that? If so, change it to a bona fide <input type="hidden"> tag. A lot of browsers will not submit form fields which are hidden via display:none.

Another stab in the dark: Are you adding the hidden form to the page via javascript? Like a foo.innerHTML call? Again, some browsers won't properly handle form fields added to a page that way. You either need to have the sessionid in there from the start, or rewrite your ajax method which handles the data returned from the server to insert the input field via dom manipulation rather than innerHTML.

Keith Twombley