I have been working is a website for offering stuff.
I have been dealing with a problem from a while, and now I know why it is happening, but not how to solve it. Please help!!
In the first page, some items are selected from a list using checkboxs. The result of this selection is stored in a variable called "check" (all checkboxs are within a form).
echo '<td><input type="checkbox" name="check" value='.$fila.'></td>';
"check" is passed to the next page using a input type="submit", and recovered using POST:
$check = $_POST['check'];
In this same page, a session variable is created, in order to use this values in the next pages:
This works perfectly most of the times, but in a few cases the session variable is empty in the next page, even when <?php session_start(); is used in both pages.
This makes the website stops running.
Could anyone help? Any idea about why the session variable is empty?
Thanks a lot!!
This makes the website stops running.
Sounds to me like session_start() is sometimes being called after output (anything echo'd out or not inside php tags).
According to the PHP manual, there is a <?php before ...
You're aware you're creating an array there, not a singular value?
Have you run the script with error displays on (See Common PHP Problems thread at top of forum)?
Thanks for helping.
About your first question, yes, it is an array.
According to the info I found, I can assing the session as I am doing:
If it is not the proper way, or if I a missing something, please let me know.
I have reviewed your post of most common errors. I will be adding the script and post the results.
Thansk a lot!!
Without seeing your code, I cant offer any further opinion.
Thanks a lot. I have run your script in pages presenting this behavior:
And a very importing result appeared:
Notice: Use of undefined constant session_check - assumed 'session_check'
Looking at the code, it was like this:
And I guess it has to be like this:
session_check is a session variable storing a selection of items made in the previous page.
Is it possible this syntax missing has been causing this issue? As stated earlier in this post, in most of the cases all works fine, nothing happens and the program runs perfectly. But in a few cases program stops, print_r(session_check) shows nothing and IF sentence does not work.
An adittional question please.
Anothe simitar error message was generated:
Notice: Use of undefined constant CreditCard - assumed 'CreditCard'
Pointing to this line:
It has always workking fine. Has it also a syntaxis problem?
Thanks a lot once again!!!
The undefined constant is a NOTICE level warning - it doesnt stop operation. PHP has recognized you typed something that looks like a string, or it was expecting a string, but you forgot to put quotes around it, so puts quotes around it for you.
Strings should be encapsulated in quotes - either single or double. Double quoted strings will interpret special characters in it -
echo 'This is a $single quote' will output This is a $single quote
echo "This is a $double quote' will output This is a <whatever the value of $double is> quote
This shouldnt have caused the issue you're seeing.... the only reason a session should empty itself is if you wait too long (usually 15 minutes) or closed your browser between page loads.
I see, thanks for your answer.
Just to make my issue clear, a session variable is created in one page, and when in another page, this variable is empty. It happens in a very few cases, normally all works well.
I have a print_r($SESSION['sessioncheck']); (now with single quotes). When the problem happens, print_r shows nothing, i.e., the session variable is empty, and this makes the program stops running because it needs this variable.
I have made tons of tests, but I have been unable to reproduce the issue, it has always happened in another people's computers. It happens with both MAC and PC.
Being unable to reproduce it makes it rather frustrating to try and find;
Did the people reporting the issue leave the page? Close their browser? Not move from page A to page B within 15 minutes? Have they got the site open multiple times?
According to their answers, they did it normally.
Making further research, I've found some posts with similar behaviors, pointing to some directory permissions related to session variables:
Are you related with this?
If that were your issue, the session would -never- be created. You're seeing it being created, which means PHP has all the necessary information/permissions to do so. If you've managed to bombard your site with a supremely large number (Trillions+) of sessions in the span of a short time (< 15 minutes), you might see session collisions, but if that were the case you'd be able to reproduce the error....
honestly, I'm at a loss.
This topic is now closed. New replies are no longer allowed.