Skip to content

Commit

Permalink
Extend method hook validation for deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
jekkos committed Sep 28, 2021
1 parent 2b031e6 commit ea879fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions application/config/hooks.php
Expand Up @@ -28,8 +28,8 @@

$hook['pre_controller'][] = array(
'class' => '',
'function' => 'validate_save',
'filename' => 'save_hook.php',
'function' => 'validate_method',
'filename' => 'method_hook.php',
'filepath' => 'hooks'
);

Expand Down
16 changes: 16 additions & 0 deletions application/hooks/method_hook.php
@@ -0,0 +1,16 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function validate_method()
{

$url = $_SERVER['REQUEST_URI'];

$post_required = preg_match('/(save|delete|delete_item)\/\d*?/', $url);

if($post_required && $_SERVER["REQUEST_METHOD"] != "POST" && empty($_POST))
{
echo "Method not allowed";
die;
}

}
16 changes: 0 additions & 16 deletions application/hooks/save_hook.php

This file was deleted.

0 comments on commit ea879fc

Please sign in to comment.