Alright I think I may finally be getting the hang of sessions.
Just a couple quick questions.
Heres how it all works:
form.php POSTS everything to Validation.php for you to see if you missed anything or need to make changes.
Click Back on browser or "make changes button" and all info is still in the form just as you typed it. Good.
If everything is right click "Create Account" and you are sent to a third "terns/conditions" page.
Accept terms everything is posted to a DB yada, yada, yada.
session_destroy() is the very last peice of PHP code on this page.
Right now im using a foreach loop to set every $_SESSION variable equal to the $_POST variables. Dont know why but this is the only way i could get my form to send any info and be able to retreive it later.
This all works just fine. But if you close the form window and re-open it all your form data is still there. And it will never leave. I have to clear my browser cache to make it go away.
So i changed in my php.ini the session.cookie-lifetime to 180. So now after 3 minutes the session finally ends and all data is cleared.
The problem is i dont want all the sessions on my set ending after 3 minutes.
Am i using session_destroy() wrong?
If my first page is a form that posts everything to a validation page do i need to use session_write_close()?
Ive seen a lot of people have trouble with redirects loosing session data and i wasnt sure what exactly qualified as a redirect.
Or do i need to set the session.cache-limiter or session.cookie-lifetime in the PHP script for my forms?
and if so how do you go about doing this?
session.cache and session.cookie question
Moderator: General Moderators
Read this entire page:
http://fr3.php.net/manual/en/function.s ... estroy.php
http://fr3.php.net/manual/en/function.s ... estroy.php
i didnt know i had to delete the session cookie as well. I thought i could just set it to timeout after so long.
Still get some sparatic problems now and then though.
Like right after i used a modified version of the script form that link you gave me i could no longer post to a database. No errors no nothing. Acted like it sent the info but nothing was there. Not even the fields like time and date that arent even session variables. Odd
Still get some sparatic problems now and then though.
Like right after i used a modified version of the script form that link you gave me i could no longer post to a database. No errors no nothing. Acted like it sent the info but nothing was there. Not even the fields like time and date that arent even session variables. Odd
here is the code that deals with sessions in each of the three pages being used:
form_example.php
validation.php
term_conditions.php
i set the session.cookie-lifetime to 60. And the sessions stop exactly after 60 seconds otherwise i cant get them to die
form_example.php
Code: Select all
session_start();
$_SESSION['....']; //each form value is called back this way.Code: Select all
session_start();
foreach($_POST as $key => $val) {
session_register($key);
$_SESSION[$key] = $val; }
var_dump($_SESSION); // for testing purposesCode: Select all
//Sets which type of payment method used
session_start()
if (!empty($_SESSION['CardPay'])) {
$acctype = $_SESSION['CardPay'];
$accname = $_SESSION['CardName'];
$compname = $_SESSION['CompName'];
$accnum = $_SESSION['CardNum'];
}elseif (!empty($_SESSION['AccPay'])) {
$acctype = $_SESSION['AccPay'];
$accname = $_SESSION['AccName'];
$compname = $_SESSION['AccComp'];
$accnum = $_SESSION['AccNum'];
}
mysql_connect("localhost", "xxxx", "xxxx") or die (mysql_error());
mysql_select_db("xxxx") or die (mysql_error());
mysql_query("INSERT INTO xxxxx (id, reg_time, ip_add, username, password, first, last, DOB, position, emp_ID, email, verify, biz_name, add1, add2, city, state, zip, phone, fax, tax_SSN, structure, bill_name, bill_dob, bill_add1, bill_add2, bill_city, bill_state, bill_zip, accType, accName, comp_name, Rout_Num, Acc_card_num, cardType, expiry, ccv) VALUES ('$id', '$time', '$ip', '$username', '$pass', '$first', '$last', '$DOB', '$position', '$empID', '$email', '$ver', '$bizname', '$add1', '$add2', '$city', '$state', '$zip', '$phone', '$fax', '$taxSSN', '$strctr', '$billname', '$billDOB', '$billadd1', '$billadd2', '$billcity', '$billstate', '$billzip', '$acctype', '$accname', '$compname', '$routnum', '$accnum', '$cardtype', '$exp', '$ccv')") or die (mysql_error());
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', 0, '/');
}
session_destroy();why are you using session_register? Take a look here:
http://us3.php.net/session_register
http://us3.php.net/session_register
I used session_register cuz i was searching for answers on google and some site said i had to use that to register my variables. And ot worked and all was right in the world until i remembered i had register_globals = On. Then when i turned that off all hell broke loose and i ended up just making crap up trying to get it to work.
I dont know if the session_register was causing the problem or not but the script is running fine now.
is the "foreach" loop i used ok?
Or should i have just set $_SESSION = array(blah blah blah...)?
Truthfully i havent a clue what im doing. Im so new at this im surprised any of this is actually working
I dont know if the session_register was causing the problem or not but the script is running fine now.
is the "foreach" loop i used ok?
Or should i have just set $_SESSION = array(blah blah blah...)?
Truthfully i havent a clue what im doing. Im so new at this im surprised any of this is actually working