+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
Web Development Thread, HTTP500 error in Coding and Web Development; Code: <?php $session_start(); echo "test" if ($_SESSION['status'] == 8) { echo "never gets this far Grrrr."; } else { echo ...
  1. #1

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328

    HTTP500 error

    Code:
      <?php
          $session_start();
          echo "test"
          if ($_SESSION['status'] == 8)
          {
               echo "never gets this far Grrrr.";
          }
          else
          {
              echo "<table>";
              echo "<form action=\"module/thispage.php\" method=\"post\"><tr>";
              echo "<td>form stuff</td><td>form stuff</td>";
              echo "<td><input type=\"submit\" value=\"ADD\" />";
              echo "</tr></form>";
              echo "<tr><td>non form stuff</td><td>non form stuff</td><td>&nbsp;</td></tr>";
              echo "</table>";
              $_SESSION['status'] = 8;
              echo $_SESSION['status'];
           }
    ?>
    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.

  2. #2

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,404
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    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?
    Last edited by CESIL; 27th February 2009 at 11:58 AM.

  3. Thanks to CESIL from:

    tmcd35 (27th February 2009)

  4. #3

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    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.

  5. #4

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,404
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    what browser are you using?

    Have you tried IE with friendly errors turned off?

  6. #5

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    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.

  7. #6

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    Okay

    Code:
    echo "test";
    changed to
    Code:
    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?

  8. #7

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,404
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    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.

  9. #8
    tsky's Avatar
    Join Date
    Jan 2009
    Location
    Billingham
    Posts
    200
    Thank Post
    10
    Thanked 27 Times in 16 Posts
    Rep Power
    20
    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

  10. Thanks to tsky from:

    tmcd35 (27th February 2009)

  11. #9

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    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?

  12. #10

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,404
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    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.

  13. #11

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    @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 !?!

  14. #12

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    Quote Originally Posted by cadjs View Post
    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.

  15. #13

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,404
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    try adding

    PHP Code:
    echo session_id(); 
    after the session_start()

  16. #14

    Join Date
    Jan 2007
    Location
    Lowestoft, Suffolk
    Posts
    84
    Thank Post
    6
    Thanked 4 Times in 4 Posts
    Rep Power
    16
    Quote Originally Posted by tmcd35 View Post
    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.

  17. #15

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    5,665
    Thank Post
    850
    Thanked 893 Times in 738 Posts
    Blog Entries
    9
    Rep Power
    328
    Thanks @cadjs, should have thought of that!

    The session id is the same value! Trying a

    Code:
    echo "<br>".$_SESSION['temp']." ";
    echo session_id();
    In the first half of the if statement to see what results I get there.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Best Site to learn php and mysql?
    By My220x in forum Coding
    Replies: 11
    Last Post: 23rd April 2008, 08:58 AM
  2. Can't get mysql and PHP to play together on IIS
    By dagza in forum Web Development
    Replies: 5
    Last Post: 20th January 2008, 03:38 PM
  3. Creating a new database in php and mysql
    By StewartKnight in forum Web Development
    Replies: 18
    Last Post: 21st February 2007, 08:53 AM
  4. PHP MYSQL Hit counter
    By Nij.UK in forum Web Development
    Replies: 9
    Last Post: 15th November 2006, 09:11 AM
  5. php MySql
    By iking in forum Books and Manuals
    Replies: 0
    Last Post: 11th July 2005, 03:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •