FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP] exit;





n0obie4life
Code:
<?php

$get = $_REQUEST['mode'];

$var = 'var<br />';
$echo1 = 'echoooo<br />';

echo $var;
switch ( $get )
{
case "1":
echo 'die<br />';
exit;
case "2":
echo 'baha<br />';
exit;
default:
echo 'h4x<br />';
exit;
}

echo $echo1;

?>


that script returned

Code:
var
die


Obviously, the link was

script.php?mode=1 Smile

So, is it just a bug/fault in the code, or a bug in the php application?
sonam
Script is working properly. Only what I see script didn't echo "echoooooo" on the end. Reason for this is exit; function. If you would like to see "echoooooo", change exit with break function. Very Happy

Sonam
BlackSkad
I don't realy get your point n00bie. But if the fact that it doesn't echo the "echoooo" is your problem, you indeed need to change the "exit" into "break".
The exit-statement completely stops executing the rest of the script (something like die(), but without output). Break, at the otherhand, jumps out of the loop/switch and continues with the script below. So your "echooooo" will be outputted using "break"...

BlackSkad
n0obie4life
My bad. It was supposed to be

exit;
break;

Lettme try.
simplyw00x
exit stops the execution of the PHP script; break simply ends the switch statement.
n0obie4life
I wanted it to do this.

Taking an example that the error code is 404.

Code:
$error = '404';
echo 'An error has occured\n';

switch ( $error )
{
case '404':
echo 'Failed to connect\n';
exit;
break;
default:
echo 'Unknown Error\n';
exit;
break;
}


I need it to stop processing the script right after it echos the error meaning.
polarBear
Code:
$error = '404';
echo 'An error has occured\n';

switch ( $error )
{
case '404':
echo 'Failed to connect\n';
exit;
break;
default:
echo 'Unknown Error\n';
exit;
break;
}

Try this scheme instead:

Code:

$error = '404';
echo 'An error has occured\n';

switch ( $error )
{
case '404':
$error='Failed to connect\n';
break;
default:
$error='Unknown Error';
break;

echo $error;
exit;
}


That way you only exit after the echoing, and the switch chooses the right string to echo.
virtualpointer
n0obie4life wrote:
I wanted it to do this.

Taking an example that the error code is 404.

Code:
$error = '404';
echo 'An error has occured\n';

switch ( $error )
{
case '404':
echo 'Failed to connect\n';
exit;
break;
default:
echo 'Unknown Error\n';
exit;
break;
}


I need it to stop processing the script right after it echos the error meaning.



=====================================

I think you might want to do this thing:

Code:
$error = '404';
echo 'An error has occured\n';

switch ( $error )
{
case '404':
echo 'Failed to connect\n';
echo $error;
exit;

default:
break;
}


If you exit the program on all cases, what will your program do?
Unless you are sure there must be wrong somewhere.
n0obie4life
@virtualpointer

Abusing bbcodes result in an instant ban.

Problem solved anyway.

-close-
Related topics
HTTP AUTH with PHP and mySQL
How To : Improve Your PHP Programming
How To : Secure Your PHP Website
php runescape highscorez
PHP OOP Tutorial
PHP Question
PHP Login Problem
ODBC and PHP connections
php script help!
Need help with PHP script[RESOLVED]
need IP blocker on my site
Authentication Module
Strange Problem in PHP-MYSQL
Offering the full site to mobile users
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.