I am testing a script for one of my websites. I am looking for a certain condition to be met. If it is true, I am currently echoing text to a page. Otherwise (else) I am displaying a different message. Now I need to change this, but are not sure with the right command. Here is the existing code if (code removed as not needed for this question()) { echo "The result is true"; } else { echo "The result is not true. Go somewhere else"; } PHP: The "If" echo should pretty much be replaced with "do nothing" = meaning - just finish displaying the page the code is embedded in. The "else" echo should be replaced with a redirect to another page. How would I do that? Thanks. Christoph
Not sure if I understand you correctly, but you can use the ! operator. if (! condition) { // Do something } PHP: ! means "if not". It's what the else would do basically.
Well, if there is no code html outputted before the if condition you can use the 'header' redirect. For example: if ( this == that ) { // do nothing } else { header("Location: http://www.google.com/"); exit; } PHP:
Instead of the header... you can also use... echo "<script>window.open("--link--","_self")</script>"; This is a better approach using javascript
You probably have some html outputted to the page already or something. Placing it before any html is outputted may fix it.