Ошибка вызова в соответствии со средой запроса, такой как GET или POST

Мой скрипт php сам описывает все, что хочет сделать с этим скриптом

Окружающая среда № 1
Запрос приходит через POST по форме от предыдущего действия страницы до сценария ниже

Окружающая среда № 2
Через GET приходит запрос для моих клиентов поделиться ссылкой на скачивание для одного использования

Теперь все отлично в приведенном ниже сценарии, но я хочу вызвать ошибку в соответствии со средой запроса, например, если запрос GET недействителен, то ошибка Your download code is invalid or expires и если запрос POST недействителен, то ошибка header ('location: ../Download-token')
пожалуйста помоги

<?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
**
**
**
**
**
*/
}

?>

1

Решение

вам нужно определить ошибку внутри каждой среды, может быть:

<?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;
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector