Page 1 of 1
session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 7:42 am
by phphelpme
Hi Jason here,
I am trying to get my form to work with my session id but it keeps taking me to the login screen because it wont recognise that the session id is there. I have a sessionidcheck.php which basically checks to see if a session exists and if not redirects them to the login page.
The form below is used to get an id which is saved in a string called $id and then I use this string to perform other actions. When I click the update button it takes me to the login screen every time. Not sure what I am doing wrong here.
Code: Select all
<form method="GET" action="<?php echo $PHP_SELF;?>?sessionid=<?php echo $sessionid; ?>">
<input type='hidden' size="12" maxlength="12" name="id" class="text" disabled="true" value="<?php echo $id; ?>"><p>
<input type="submit" value="Update" name="submit" class="grab">
</form>
Any help would be greatly welcomed.
Jason.
Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 7:54 am
by adil
<form method="GET"
change to
<form method="POST"

Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 8:29 am
by phphelpme
Hi,
I have tried changing GET to POST and now it just reloads the form and will not execute what it is supposed to do. If I change it back everything works fine but still takes me to the login screen cos it does not recognise the session id as being there.
This is the way the form looks when it is fully working, but redirects me to the login page as session id is not present:
Code: Select all
<form method="GET" action="<?php echo $PHP_SELF;?>">
<input type="text" size="12" maxlength="12" name="value" class="text"><p>
<input type="submit" value="submit" name="submit" class="grab">
</form>
The form gets a number from the user, then that number is saved as a string value, that string value is used to perform an action then the action is saved into a .php file.
This is the first way I tried by adding the session id:
Code: Select all
<form method="GET" action="<?php echo $PHP_SELF;?>?sessionid=<?php echo $sessionid; ?>">
<input type="text" size="12" maxlength="12" name="value" class="text"><p>
<input type="submit" value="submit" name="submit" class="grab">
</form>
This does perform the php script that I need it to do, but then redirects me to the login page as it is not recognising the session id in the action of the form.
Then I tried to change GET to POST:
Code: Select all
<form method="POST" action="<?php echo $PHP_SELF;?>?sessionid=<?php echo $sessionid; ?>">
<input type="text" size="12" maxlength="12" name="value" class="text"><p>
<input type="submit" value="submit" name="submit" class="grab">
</form>
Now the form just reloads itself and stops the page from acting on the string value saved and stops the file save action.
The top one displays in the address bar when I click submit: /updatemembers.php?value=45605&submit=Update
I think it has something to do with that because I am trying to add a session id to this but when I arrive at the page the link looks like this:
/updatemembers.php?sessionid=486er5f8456er8e5f8ef etc
So by saying $PHP_SELF it uses this link then adds the additional string values to the end so I am adding another session id to the end surely?
Not sure what to do from here...

Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 8:54 am
by adil
plz paste here your get form request code
Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 9:01 am
by phphelpme
Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 2:32 pm
by Christopher
Typically when you pass the session ID you need to use the name that PHP uses, so: <?php echo $PHP_SELF . '?' . session_name() . '=' . session_id(); ?>. If you are having problems with the session working then you should narrow down your code to just test that. There are many possible problems. It is possible that sessions are not working on your server.
Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 3:09 pm
by phphelpme
Hi Christopher,
Thank you very much for your very swift reply. Great forum by the way. Only just registered. I never knew it existed and now I think its great.
I have however been messing like crazy with my coding and I can confirm that sessions are working ok on my server as I use them to login to my system to get access to this particular page.
Anyway, just to keep all informed, I have been playing around and found out that I do indeed need to use POST method but also include the $_SERVER within the action script and this allows me to follow on with the session id still being used.
Code: Select all
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']?>?sessionid=<?php echo $sessionid; ?>">
Thank you for your great help and I do agree it could be a number of possibilities and that is why I seeked help online due to trying so many different things.
Thanks Christopher.
Best wishes,
Jason
Re: session id on form submit - HELP PLEASE
Posted: Mon Nov 22, 2010 8:51 pm
by Christopher
I am a little confused because the code you shows has no session code. I don't see a session_start() anywhere. You are using 'sessionid' but the name of the PHP session is usually something like 'PHPSESSID'.
Re: session id on form submit - HELP PLEASE
Posted: Tue Nov 23, 2010 7:16 am
by phphelpme
Sorry, I call a file called checkcookiesession.php right at the top, but I did not include this at the top of the coding. This file checks to see if a session exists then directs them accordingly. lol Sorry for leaving that one out... lol Thanks Christopher.