Im trying to get some values that I pass in my url but Im having one problem.
Im using this code and function to get my url:
$page = $url[1];
$page = ($page ? $page : 1);
echo '<h1>'.$page.'</h1>';
And my function getHome():
function getHome()
{
$url = $_GET['url'];
$url = explode('/', $url);
$url[0] = ($url[0] == NULL ? 'index' : $url[0]);
if(file_exists('tpl/'.$url[0].'.php'))
{
require_once('tpl/'.$url[0].'.php'); (tpl is my folder, where I have my php files)
}
else
{
require_once('tpl/404.php');
}
}
With this, I can get value that I pass in url in my “categories.php” file, using this url: htttp://localhost/project/categories/2 -> I´m getting echo of my “2” and also I have my categories.php page included.
But in my “index.php” file, using this url: htttp://localhost/project/2 -> Im not getting value that I pass in url, and its included my page “404 not found”, that I include in my function getHome like this: “tpl/404.php”.
If I use index in my URL, like this: htttp://localhost/project/index/2, it works, I can get my url value of “2”. But I´m trying to have just my htttp://localhost/project/2, without index, and get the value I pass, in this case “2”.
So, Im trying to find a way to change my function geHome(), to get values that I pass in url also in my index.php file, using: localhost/project/2 , where I want to get my value “2” in this case, and not include my ‘tpl/404.php’.
But Im not having sucess doing this change, do you see some way to do it?
Im also using my .htaccess with my rule, saying that my index.php is my default, where I acess all, where I do my navigation:
RewriteEngine OnRewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
My project organization is:
- 1 folder project, inside it I have:
- 1 .htaccess file
- 1 index.php file where I call my function getHome()
- 1 folder “tpl” where I have my index.php, that´s my home page, and I also have my other php files