Monday, February 3, 2014

Sample Redirection function

Very Useful function After Added or updated data "redirection given url". Easy to use below code.


<?php

//define Function
 function redirectPost($url, $restrict_hidden=array(), $add_hidden=array())
{
$text = '';
$text .= '<form name="frmRed" method="post" action="'.$url.'">';
$text .= "\n".'<input type=submit name="sb_hid" value="" />';
$text .= "\n".'</form>';
$text .= "\n".'<script type="text/javascript">';
$text .= "\n".'x=5+5;';
$text .= "\n".'document.write(x);';
$text .= "\n".'document.frmRed.submit();';
$text .= "\n".'</script>';
echo $text;
}


//call function
if(isset($_POST['submit']) &&  $editid>0)
{
        $url= "givenpageurl.php?id=".$editid;   
        //updated php and mysql code
        redirectPost($url, $restrict_hidden, $add_hidden);
        exit;   
}

else
{

             $url= "givenpageurl.php";   
        //Added php and mysql code
        redirectPost($url, $restrict_hidden, $add_hidden);
        exit;   

}

?>

No comments:

Post a Comment