AM: You're actually just approximating when the page loads. According to your script, you're trying to make a page automatically submit a form as soon as the page is loaded. Since page load times vary from user to user (a dialup user, for example, will take longer than an high speed user to load the same page), your script will work sometimes and not others.
Since you're really just redirecting the user based on an error, I'd suggest modifying your code to something like this
PHP Code:
if ($Success != 1) { header("Location:index.php?error=yes"); exit(); }
(NOTE: That changes the value to a $_GET value instead of a $_POST value.)
Now, if that doesn't work, it's most likely because you've already returned some text to the browser, so then you'd have to use something like this for the same effect:
PHP Code:
if ($Success != 1) { echo '<script type="text/javascript"> location.replace("index.php?error=yes"); </script>'; }
All that said, I'd suggest that you've got the logic of your routine wrong -- how likely is it that when an error occurs you need to redirect the user to an error page? I suggest that it really should show the user the error and provide them with the ability to correct it on that page itself -- no redirection involved. That skips the time required to redirect and load the new page and makes the process a bit smoother for your website visitors AND it doesn't require javascript to be enabled.
|