Hi,
I get an error 500 when I try to open my web page with IE, but not with other Programs as Firefox or Safari. The problem I think is with the redirect in the index.php file, but I don't see the problem.
Here is the code:

<?
fcnX('home.php');

And the function is a Java script:

}
function fcnX($prUrl){
  echo '<script language="javascript">' . "\n";
  echo '<!--' . "\n";
  echo 'document.location = \'' . $prUrl . '\';' . "\n";
  echo '-->' . "\n";
  echo '</script>' . "\n";
  break;
  exit;
}

Any ideas?
Thks!

Dani AI

Generated

A terse diagnosis and a short debugging checklist based on the thread (so the answer from and the hints from and are tied together).

The 500 is a server-side PHP failure (not a browser rendering bug). In this case the posted function contained a stray break and mismatched braces; break is only valid inside loops/switches and will raise a fatal error if used elsewhere, which commonly yields an HTTP 500 when error display is off. (php.net)

Fast checks to run before changing logic:

  • Lint the file on the server/locally to find parse errors:

    php -l /path/to/index.php

    The CLI linter reports unexpected tokens and line numbers so syntax mistakes show up immediately. (php.net)

  • Turn on temporary error reporting (never leave this on in production) or inspect the web server/PHP error log. Example debug snippet (place at top of a test file only):

    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);

    Note that some fatal compile-time errors still appear only in the server log rather than the browser. (php.net)

Why it could vary between servers/browsers: if a file starts with a short PHP open tag (<?) and the remote PHP has short_open_tag disabled, that file won’t be parsed as PHP. Also, server rules (rewrite/mod_security) or different PHP versions/configs can make behavior differ between hosts — compare phpinfo() and php.ini settings. (php.net)

When redirecting, server-side Location headers are the reliable choice and must be sent before output; building an absolute URL and using a simple redirect helper is a robust pattern. Check logs, remove the stray break and any unmatched braces, lint before upload, and prefer long PHP tags (<?php) for portability. (php.net)

Recommended Answers

All 9 Replies

Hi there,
The problem is that you are calling javascript from inside your php which is outside of it's name space. What you gotta do is in your php file : echo "<script>fcnX('home.php')</script>"; in the middle of your head section and the function will automatically be called when the page loads.

Thanks, but I dosen't seem to work either.
The strange thing is that the function as originally posted works fine in FF and Safari but not in IE. It is also strange that it works fine with IE in my local server but not in the remote server, can it be something to do with the server config??

Why are you using javascript to redirect?

Just use header('Location: http://somesite.com/page.html'); . You can use a relative url as well. Make sure you have nothing being echoed to the browser before calling that.

If you are still getting an internal server error, post more code because that function will not cause that.

Thanks, that works but I don't want to change the function because it is used several times, it works fine using a "direct" redirect. It can be Plan "B".
But I want to know why is this happening because it might be something with the config of the server I am using because it works fine in other servers. I am concern that the config of the server might be affecting other functions as well.

Why do you have break; in the function? You don't have a control structure that accepts that.

Hi,
When you use a cable modem or a DSL connection to try to connect to a Microsoft Internet Information Services (IIS) site that is running on a Microsoft Windows 2000 Professional-based computer, you may receive the following error message in Microsoft Internet Explorer:

Error 500

If you click to clear the Show friendly HTTP error messages in the Internet Options dialog box in Internet Explorer, and then you try to connect to the same site over the same connection, you may receive one of the following messages in Internet Explorer:

  • Bad Url
  • Bad Gateway

Note To locate the Show friendly HTTP error messages check box, click Tools, click Internet Options, and then click the Advanced tab.

Hi,
I get an error 500 when I try to open my web page with IE, but not with other Programs as Firefox or Safari. The problem I think is with the redirect in the index.php file, but I don't see the problem.
Here is the code:

<?
fcnX('home.php');

And the function is a Java script:

}
function fcnX($prUrl){
  echo '<script language="javascript">' . "\n";
  echo '<!--' . "\n";
  echo 'document.location = \'' . $prUrl . '\';' . "\n";
  echo '-->' . "\n";
  echo '</script>' . "\n";
  break;
  exit;
}

Any ideas?
Thks!

Well perhaps you may need to specify the full url in the function instead of just a page name. Below is an example of how you should use your function:

<?
fcnX('');

You may find that IE is just getting confused without the full address.

Thank you all,
Problem solved, what I did was to change the function, eliminate the javascript and make a more direct:

function fcnX($prUrl)
{
   header('Location: '.$prUrl);
  exit();
}

I was so frustrated trying to understand why it wasn't working in IE that I didn't paid attention to more simple solutions.

Thanks again

Hi, i am KEN74 from <URL SNIPPED>.

The problem is in the break, it may work in some browsers, but ie have a problem with the break, if you use it outside a loop.

Remove the break , and your code will work right

Feel free to contact me if you need Non-Object PHP help.


POSTDATA : I know this post is old, but maybe this helps someone, that has this break problem.

Good luck ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.