I am trying to get variables from a query string with the _GET superglobal. The way I have my project setup now is by using a driver file to access files within my website. Each included file as a security check that is set by the main index file therefore you cannot directly access nested files. As an example of my setup, here is how I've configured it.
localhost/index.php
define(‘SECURE_CHECK’, true);
include(admin/site.php);
and the included file would only work by being included
admin/site.php
defined('CHECK_SECURE_ENVOI') or die("Please return to the main page.");
In one of my admin files, I tried creating a clean way to retrieve pages based on URI requests and reinforce this with my .htaccess.
if (fnmatch("*dashboard/", $_SERVER['REQUEST_URI'])) {
include(DIR_ADMIN_VIEWS . 'dashboard.php');
} else if (fnmatch("*add-post/", $_SERVER['REQUEST_URI'])) {
include(DIR_ADMIN_VIEWS . 'add-posts.php');
} else if (fnmatch("*edit-post/", $_SERVER['REQUEST_URI'])) {
include(DIR_ADMIN_VIEWS . 'edit-post.php');
} else if (fnmatch("*view-posts/", $_SERVER['REQUEST_URI'])) {
include(DIR_ADMIN_VIEWS . 'view-posts.php');
} else {
include(DIR_ADMIN_VIEWS . 'dashboard.php');
}
Any my .htaccess looks like:
<IfModule mod_rewrite.c>
Options -MultiViews
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/?(resources)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*) index.php [PT,L] <--- was my original before this issue
RewriteRule ^(.*)$ index.php?edit=$1 [NC,QSA]
</IfModule>
The above code makes so that I can use the url of localhost/admin/add-post/
instead of localhost/core/admin/views/add-posts.php
. It also helps reinforce the security in a way that you can’t access a page without properly navigating to it. The problem is now I can’t seem to get values through a query string.
I tried following a few guides like this one, but I haven’t had success; Here
My goal is to be able to use a link like localhost/admin/edit-post/?edit=value
Or localhost/admin/edit-post/edit/value
and get the value with something like an isset check below:
if(isset(_GET[‘edit’])) {
$value = isset(_GET[‘edit’];
//do something
}
I think the problem I have might be related to my admin redirect pages through my if/else, but I am not sure. Any help would be greatly appreciated. Thanks.