This is a dodgy question...
When requesting a page, the output of the page depends on the parameters passed. Soo:
http://localhost/test/php?key=value
AND
http://localhost/test/php?key=other_value
will produce different outputs.
There are a lot of these parameters and sometimes they are set, sometimes they are not.
I have this code block, that I keep copying over and over:
if ( !isset( $PARAMS["type"] ) ){
$message = urlencode("No Type Parameter Defined In File {$_SERVER["PHP_SELF"]}");
header( "Location: /admin/pages/{$PARAMS["page"]}?m=$message" );
exit;
}
Now this code block is repeated in some cases about 6 times!
So I thought I could write a function:
function redirect_on_fail( $var ){
if ( !isset( $var ) ){
$message = urlencode("No Type Parameter Defined In File {$_SERVER["PHP_SELF"]}");
header( "Location: /admin/pages/index?m=$message" );
exit;
}
}
OBVIOUSLY this will not work
Because I will have to call redirect_on_fail( $PARAMS["type"] );
and if it is not set, it wont be passed to the function...
Because I need to test whether the variable exists in the Pages Scope...
So I could just do this, I suppose:
function redirect_on_fail( $message, $redirect_to ){
header( "Location: /admin/pages/$redirect_to?m=".urlencode($message) );
exit;
}
But then in the page I'm doing:
if ( !isset( $PARAMS["type"] ) ){
redirect_on_fail( "No Type Parameter", $redirect_to );
}
and that defeats the point...
So is there a way around this?