根据GET或POST等请求环境调用错误

My php script self describe every thing what want to do with this script

Environment #1 Request comes through POST by form from previous page action to below script

Environment #2 Request comes through GET for my clients to share download link for one use

Now every thing is perfect in below script but I want to call the error according to request environment like if GET request is invalid then error Your download code is invalid or expires and if POST request is invalid then error header ('location: ../Download-token') please help

<?php

if(isset($_GET['dlCODE']) and ($_GET['Rfile'])){
    $reqfname   = $_GET['Rfile'];
    $dlKEY      = trim($_GET['dlCODE']);
    $kfile      = file('Download-Keys.php');
    foreach($kfile as &$one) {
        if(rtrim($one)==$dlKEY) {
            $slink  = true;
            $one    = '';
        }
    }
    file_put_contents('Download-Keys.php', $kfile);
}

if(isset($_POST['Rf'])){
    @session_start();
    if(!isset($_SESSION['download-token'])){
    header("location:../Downloads-Passing");
    }
    $reqfname       = $_POST['Rf'];
    $dlREQ          = true;
}




if(($slink == true) or ($dlREQ == true)){

//Below Variables for Defines value hereinafter use;
$explode        = explode('.',$reqfname);
$t              = time();
$Clintfname     = $explode[0]."_".$t.'.'.$explode[1];
$fPath          = "../qd_files/";


//Below code for force to browser display save as dialogue box options;
header('Content-type: application/zip');

//Below code for rename the source file name to escape hot-linking;
header('Content-Disposition: attachment; filename='.$Clintfname);

//Below code for Sending correct file size to be ready to Download;
header('Content-Length: '.filesize($fPath.$reqfname));

//Below code for read original file from the source;
readfile($fPath.$reqfname);

//Below code for Count Download hit on download button;
$dlfile     =   "dlcounter.php";
$dlcoun     =   file_get_contents($dlfile);
/*PUT ADD ONE*/ file_put_contents($dlfile, ++$dlcoun);

} else {
/*
**
**
**
**
**
        errors need here
**
**
**
**
**
*/
}

?>

you need define the error inside of each Environment, maybe:

<?php
$error = 0;

if(isset($_GET['dlCODE']) and ($_GET['Rfile'])){
    $reqfname   = $_GET['Rfile'];
    $dlKEY      = trim($_GET['dlCODE']);
    $kfile      = file('Download-Keys.php');
    foreach($kfile as &$one) {
        if(rtrim($one)==$dlKEY) {
            $slink  = true;
            $one    = '';
        }else {$error  = 1;}
    }
    file_put_contents('Download-Keys.php', $kfile);
}

if(isset($_POST['Rf'])){
    @session_start();
    if(!isset($_SESSION['download-token'])){$error = 2;}
    $reqfname       = $_POST['Rf'];
    $dlREQ          = true;

}

switch($error)
{
   case 1: echo 'Your download code is invalid or expires'; Break;
   case 2: header ('location: ../Download-token'); Break;
   default:

    //Below Variables for Defines value hereinafter use;
    $explode        = explode('.',$reqfname);
    $t              = time();
    $Clintfname     = $explode[0]."_".$t.'.'.$explode[1];
    $fPath          = "../qd_files/";


    //Below code for force to browser display save as dialogue box options;
    header('Content-type: application/zip');

    //Below code for rename the source file name to escape hot-linking;
    header('Content-Disposition: attachment; filename='.$Clintfname);

    //Below code for Sending correct file size to be ready to Download;
    header('Content-Length: '.filesize($fPath.$reqfname));

    //Below code for read original file from the source;
    readfile($fPath.$reqfname);

    //Below code for Count Download hit on download button;
    $dlfile     =   "dlcounter.php";
    $dlcoun     =   file_get_contents($dlfile);
    /*PUT ADD ONE*/ file_put_contents($dlfile, ++$dlcoun);

    Break;
}