Jump to content

Recommended Posts

Posted

       $session_start();
     echo "test"
     if ($_SESSION['status'] == 8)
     {
          echo "never gets this far Grrrr.";
     }
     else
     {
         echo "</pre><table>";
         echo "";
         echo "form stuffform stuff";
         echo "";
         echo "";
         echo "non form stuffnon form stuff ";
         echo "</table>";<br>         $_SESSION['status'] = 8;<br>         echo $_SESSION['status'];<br>      }<br>?&g

 

Okay, I'm trying to write a new asset management database for the school. I am using a WAMP environment on Windows 2003 R2 in a M$ Virtual Server VM.

 

Everything has been going swimmingly until I hit upon this problem I just can't see the answer to. The above is a heavily edited version of the script causing me problems.

 

On the first pass:

'test', the table and form contents, and '8' are displayed on the screen.

 

When you click on the 'ADD' button to initiate the second pass I get a:

HTTP 500 error.

 

Now, the address in the form action is correct. If I change it to another page in the same folder the 'ADD' button works. But when it is asked to reload this page, it doesn't!

 

I have used the same basic code on around half dozen pages without problem.

 

The only other thing of significance is that I am posting around 10 variables from the form this time. That said I have another script that can dynamically post 10's (100's) of variables from it's form and that works without error.

 

Anyone got any pointers, something I should be looking at/for to resolve this strange problem?

 

Cheers

 

Terry.

Posted (edited)

Just tried your code here and it works apart from needing a couple of fixes.

 

removed the $ from line 2

added ; to line 3

changed form action path to my test page

 

Have you looked at the apache logs to see if any info is in there?

Edited by CESIL
  • Thanks 1
Posted

Sorry, couple of simple typos dumbing down the page to the bit that is wrong.

 

I've used the same code loads of times without problems. Anyone got any ideas what might be causing a HTTP500 error? I've been staring at this for far too long. Grrr.

Posted

I am using IE8. Didn't know about friendly errors. Turned off and got an interesting result. the "test" before the if statement is displayed. But nothing is displayed from either clause in the if statement.

 

I'm going to check the session variable and see if I have a problem joining the session.

Posted

Okay

 

echo "test";

changed to

echo "test"." ".$_SESSION['status']

 

first pass result in "test 9" followed by the table/form followed by "8". correct :)

 

second pass results in "test 0".

 

so I'm loosing my connection to the session between iterations! Question is, how do I fix that? I thought 'session_start();' at the start of every page took care of that for me?

Posted
have a look in the folder where sessions are stored (defined by session.save_path in php.ini) and see if session files are being created. If not you may have a permissions problem.
Posted

Check your PHP.INI file - you could try turning on Register Globals, often the cause of a problem with a lot of scripts where you're expecting passed variables and suddenly it doesn't work.

 

remember to do a strip slashes strip tags on your input for a bit of security on your code!

 

you could try a reassign of your session variables if you've got an include for starting sessions... $_SESSION['myvar'] = $myvar;

 

one I usually use also is a cache control:

 

session_start();

header("Cache-Control: ");

header("pragma: ");

 

this helps retain information page to page if input by users is buggered ;)

  • Thanks 1
Posted

Here's the thing. I've got half a dozen pages with the same code. The rest work fine!?! The session is being created and variables successfully passed among all the other pages. When the it comes to this page. The first iteration and the session and variables are fine. The second and (same code) it's not !?!

 

If this was the first page of a new project I'd agree - session not being created - but when you're this far through the coding process. I have almost 30 php scripts so far making up this project. Almost all of them use session_start(); and no other page - regardless of which folder it is stored in or how meny times it is called - is causing any problems with session variable passing.

 

What could make WAMP/IE lose the session between pushing the 'ADD' button and reloading the php script?

Posted

have you looked at the session id to check it is the same when the page reloads?

 

if you are getting a different id on reload then the session vars will be lost

 

this can happen if cookies are blocked for some reason.

Posted
@tsky: no joy on the register globals (which was turned off - now on), also adding cache control to that page is not effective. Re-assigning session variable is a non starter. At this point they contain data I need to extract. I also can't understand why the session variables are correct during the first run of the script - when the else block is run - but not during the second run of the script. It's the same script !?!
Posted
have you looked at the session id to check it is the same when the page reloads?

 

This is getting stranger. May try with a different web browser, Safari on me Mac, in a moment. But, I can't find the cookie that stores the SID for the session? I can find other cookies but not this one! Which is strange as all other pages are working and would be relying on this information.

Posted
first pass result in "test 9" followed by the table/form followed by "8". correct :)

 

second pass results in "test 0".

 

so I'm loosing my connection to the session between iterations! Question is, how do I fix that? I thought 'session_start();' at the start of every page took care of that for me?

 

Is it losing connection? Surely if the connection was lost $_SERVER['status'] wouldn't be initialised? It seems the value is there but set to 0.

 

What about looking at the web server logs. Your earlier 500 errors should be there.

Posted

Thanks @cadjs, should have thought of that!

 

The session id is the same value! Trying a

 

echo "
".$_SESSION['temp']." ";
echo session_id();

 

In the first half of the if statement to see what results I get there.:confused:

Posted

Okay, earlier I changed the

 

if ($_SESSION['status'] == 8)

 

to

 

if($_POST['tag'] != null)

 

it worked! But any reference to session variable within the IF statement didn't :(

 

Now I've added those two echo statements into the IF block and low and behold the if block is NOT being processed.

 

If POST['tag'] was null it'd display the form? but since it's not null (form submitted), it doesn't appear to be processing the IF statement!

Posted
have you tried with a different computer/browser yet?

 

maybe IE8 has stricter/different security that is affecting cookies?

 

Firefox gives exactly the same results! I think it's a backend php problem. Not sure what though...

Posted

are you sure the form action path is correct?

 

it seems to be pointing to a file in another folder...if you leave the action blank then it will reload the form by default anyway

 

edit: actually even if that was the case the session vars would still be visible assuming the next file also has a session_start

Posted

form action path is correct and the file is being loaded. The echo session_id(); after the session_start(); proves this. I think I may have to re-write the file from scratch and see if the problem gets re-created on a re-write.

 

The problem is, the code for displaying the data entry form and the table beneath that is quite complex and I don't fancy giving it a complete re-write - once was hard enough.

 

There appears to be a problem with the PHP passing but I can't see anything obvious. The passing of $_SESSIONS and $_POST variables seem to be a bit hit and miss.

 

It does appear that the session id is following and some session variables are to. $_SESSION['status'] appears to be being reset to 0 for some reason.

Posted

When things start erroring in PHP, the best things to are the following.

 

At the top of your PHP script add

 

error_reporting(E_ALL);

 

From PHP: error_reporting - Manual

 

Next look in you webserver logs.

 

HTTP Error 500 Internal server for php pages and solution

 

Next if the program is really complicated start a testing framework.

 

SimpleTest - Unit Testing for PHP

 

Then you can get into performance tuning with tools such as cachegrind

 

KCachegrind

SourceForge.net: WinCacheGrind

 

This can be usefull if you are doing database calls and experiencing slowdowns. You'll usually find your making a lot of calls in a loop somewhere.

Posted

There appears to be a problem with the PHP passing but I can't see anything obvious. The passing of $_SESSIONS and $_POST variables seem to be a bit hit and miss.

 

Try adding to your code:

 

print_r($_POST);

print_r($_SESSIONS);

 

This will dump out all the post and session variables.

 

It could also be to do with sending a post variable with out a value.

  • Thanks 1
Posted

         echo "</pre><form action="%5C%22module/thispage.php%5C%22" method='\"post\"'>";

<

 

Do you need to escape the "/" e.g.

         echo "</pre><form action="%5C%22module%5C/thispage.php%5C%22" method='\"post\"'>";
<

 

or you could use single quotes to around the whole statement and then not have to escape the double quotes.

 

         echo '</pre><form action="module/thispage.php" method="post">';
<

 

You also have to be carefull on the directory seperator.

 

"/" is usually a unix directory seperator

 

"\" is a windows directory seperator

 

Plenty of options that could be causing you fun.

Posted

Thanks to everyone who replied. As you'd have probably guessed it was down to user error :o

 

both $_SESSION and $_POST variables where transferring fine. I just needed to keep better track as to what was being contained in each and when.

 

The $_SESSION['status'] variable is still containing the wrong value = '0' instead of '8', but I worked around it (not used that variable at this point) and everything is fine.

 

Thanks again for the help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...