Redirect from custom file

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Satrapo
User
Posts: 39

Redirect from custom file

Post by Satrapo »

Hi,

I need to redirect from a custom file (v2024) back to a specific list page, I'm using this code and It works:

if ($mycondition) {
$myurl = $_SERVER['CWD']."mynewurl";
header("location: " . $myurl );
die();
}

Just to know: how can I do this in custom files using phpmaker function (terminate(), Redirect() etc etc) ?


arbei
User
Posts: 9384

Post by arbei »

You should redirect in server event such as Page_Load, not in the page content.


Satrapo
User
Posts: 39

Post by Satrapo »

Ok, my condition for redirecting is:

        if (isset($_POST['posted'])) {
            $session = Session();
            $SchedaWork = $session["SchedaWork"]; // Get session variable
            //var_dump($_POST);
            $utime = time();    
            $ToSave = json_encode(array_diff_key($_POST,['csrf_name'=>0,'csrf_value'=>0,'posted'=>0]));
            $sql = "UPDATE `schede` SET
            `salvataggio` = '$ToSave',
            `unixtime` = '$utime'
            WHERE `id_scheda` = {$SchedaWork['id_scheda']}";
            $rowAffected = ExecuteStatement($sql);
            //echo "<br>ROW_AFFECTED:".$rowAffected;
            if($rowAffected == 1){
            $this->setSuccessMessage("UPDATE OK");
            }else{
            $this->setFailureMessage("UPDATE ERROR");    
            }
            $YourUrlGoesHere = $_SERVER['CWD']."SchedeList?showmaster=dispositivi&fk_id_dispositivo=".$SchedaWork['dispositivo'];
            $this->terminate($YourUrlGoesHere);            
            }

I've tried it in Page_Load and it works but it's ok to use all this code in Page_Load server event?
I cannot use termintate() in custom file content?

Thanks a lot!


arbei
User
Posts: 9384

Post by arbei »

Satrapo wrote:

I've tried it in Page_Load and it works but it's ok to use all this code in Page_Load server event?

Yes.

I cannot use termintate() in custom file content?

If you want to redirect, no, you cannot.


Satrapo
User
Posts: 39

Post by Satrapo »

Ok, I'll go with Page_Load server event.

Thanks a lot!


Post Reply