0

I have a PHP file consisting of the following structure:

<html>... headers, scripts & styling
... some html here
<?php
  if($_GET['v'] == 1)
  {
?>
    ... html code here ...
<?php
  }
  else
  {
?>
    ... html code here ...
<?php
  }
?>
</html>

Sometimes the file just loads half, for example if v=1 what would load onto the screen (if I check with View Source also) is something like this: (relative to what I exampled above)

<html>... headers, scripts & styling
... some html here
    ... html cod

As you can see, the code just cuts off randomly. The is nothing obvious casing this such as a loop or anything. It happens in the middle of HTML code and not inside the <?php ?> tags.

It looks as if the server just decides to stop communicating right there-and-then for no reason. It also happens at a different and random place each time and sometimes loads perfectly fine.

It also only happens on my shared hosting account and not on my localhost.

Is there anything simples that might be causing this? Did anyone experience this before?

3
  • Can you share a link so that we can test it with our own browsers and run packet capturing tools? Commented Sep 19, 2011 at 16:33
  • No, sorry - it's inside an control panel of a web app. Commented Sep 19, 2011 at 16:44
  • Then can you create a pcap dump (for example with wireshark) and upload it? Commented Sep 19, 2011 at 17:02

2 Answers 2

2

Your code produces a warning (apparently silent) and fails here:

if($_GET['v'] == 1)

if no v parameter was given in the query string.

Do it like this:

if(isset($_GET['v']) && $_GET['v'] == 1)

If you're running an old version of PHP you'll have to make two separate if statements for each of the two conditions.

Sign up to request clarification or add additional context in comments.

4 Comments

I think that depends on the error reporting configuration though.
no. When error is supressed, it's supressed but still works. It's just a notice/warning, and script doesn't stop
It's not that, I do use isset and actually not an else but another if for when v = 2. It also happens only at about halfway inside the if's {} tags
I used ini_set('display_errors',1); and then it gave errors which got solved when using your solution. thank you
2

Make sure you have display_errors turned on.

ini_set('display_errors',1);

Just to make sure there's nothing going horribly wrong.

3 Comments

Ag man. Now it does not give that problem anymore - scared of it happening when a client uses it.
It's normal. If you have display_errors inactive if there's an error code execution will cease. You should also check code source instead of just looking at the produced visual output. Sometimes and depending on the browser it might not show the error.
Thanks. This seemed to have unknowingly solve my problem - like you said just now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.