Search code examples
phprequest-uri

Php url request


I downloaded this template off the web, very easy to understand. It is used to detect what device you're using and all. Well, just one issue I am having with it is how the index.php page is setup and it uses REQUEST_URI to figure out what file it needs to pull just one issue when you click it link it moves files so instead of it being on index.php it is now on foobar.php resulting the REQUEST_URI to be useless. I feel like it was attempting to stay on the index.php page when you clicked a link, but it still showed the dir it was suppose to follow. I am unsure but here the two files. Sorry for my poor explanation... Grammar and such was/is never my strong suit.

Oh yeah. I did however took out their detect and replaced it with mobile detect (Which I find much better and updated), but it will still giving me this issue when I was using theirs.

Config.php

<?php
/*
 * A Design by W3layouts
Author: W3layouts
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
 *
 */
$current_page_uri = $_SERVER['REQUEST_URI'];
$part_url = explode("/", $current_page_uri);
$page_name = end($part_url);
echo $current_page_uri;
echo $page_name;
$email_id = "w3layouts@gmail.com";
?>

Index.php

<?php 
/*
 * A Design by W3layouts
Author: W3layouts
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
 *
 */
 /*
include "app/config.php";
include "app/detect.php";*/
include "app/config.php";
require_once 'app/Mobile_Detect.php';
$detect = new Mobile_Detect;

$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();
if ($deviceType == "tablet" || $deviceType == "phone") {
    $browser_t = "smartphone";
}
elseif ($deviceType == "computer") {
    $browser_t = "web";
}

if ($page_name=='') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='index.html') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='technology.html') {
    include $browser_t.'/technology.html';
    }
elseif ($page_name=='blog.html') {
    include $browser_t.'/blog.html';
    }
elseif ($page_name=='about.html') {
    include $browser_t.'/about.html';
    }
elseif ($page_name=='contact.html') {
    include $browser_t.'/contact.html';
    }
elseif ($page_name=='single-page.html') {
    include $browser_t.'/single-page.html';
    }
elseif ($page_name=='404.html') {
    include $browser_t.'/404.html';
    }
elseif ($page_name=='contact-post.html') {
    include 'app/contact.php';
    }
else
    {
        include $browser_t.'/404.html';
    }

?>

Solution

  • I forgot to enable mod_rewrite on my server therefore it wasn't working correctly.