Código PHP:
function redirecciona($destino,$datos,$metodo){
/*
forma del array
$datos=(‘nombreparametro’=>valor,’nombreparametro2’=>valor2 ...,’nombreparametroN’=>valorN)
*/
if ($metodo=="get") {
if (!headers_sent()) {
$cadena="";
if (count($datos)>0) {
foreach ($datos as $key=>$value){
$cadena.="$key=$value&";
}
$cadena=substr($cadena,0,strlen($cadena)-1);
header("Location: $destino?$cadena");
}
else {
header("Location: $destino");
}
}
else {
?>
<form name="envia" method="GET" action="<?=$destino?>">
<?if (count($datos)>0) {
foreach ($datos as $key =>$value){?>
<input type="hidden" name="<?=$key?>" value="<?=$value?>">
<?}
}?>
</form>
<script>document.envia.submit();</script>
<?
}
}
else if($metodo=="post"){
?>
<form name="envia" method="POST" action="<?=$destino?>">
<?if (count($datos)>0) {
foreach ($datos as $key =>$value){?>
<input type="hidden" name="<?=$key?>" value="<?=$value?>">
<?}
}?>
</form>
<script>document.envia.submit();</script>
<?
}
}