Page 1 of 1

a big problem and a small problem with template system

Posted: Fri Jul 22, 2011 6:23 am
by JelvinJS7
so first off, I AM using the .htaccess code to make a vanity URL. 
basically, I followed the template system series, and it all works. however, I'm including ENITRE files with this page. there are a few problems here. but first the code:

index.php
<?php

if (empty($_GET['page']) || $_GET['page'] == "index"){
header("Location: login");
die();
}

$pages = scandir("core/inc_files");
unset($pages[0], $pages[1]);

foreach($pages as $page){
$page = substr($page, 0, strpos($page, '.'));
}

if (in_array($_GET['page'], $pages) === false){
$inc_file = "core//inc_files/login.php";
}

else{
$inc_file = "core/inc_files/{$_GET['page']}.php";
}

include ($inc_file);
?>
Part of template/header.inc.php
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>RSS - <?php echo ucwords($_GET['page']); ?></title>
and all the included files basically redirect to the read page if there's a set session, and include the header file. 

first off, before this would work. now, through edits and redoes, it will only display the login page. 

second, when it was working, if the user typed "isuvyo", then the title will be "RSS - Isuvyo". if the user types something random, then I want it to display the login page and have the title be the login page. 

can someone please help me with this?

Re: a big problem and a small problem with template system

Posted: Fri Jul 22, 2011 6:41 am
by JelvinJS7
alright edit. it's mostly working now. including files that exist works. here's part of my code. I don't fully understand it though…
if (in_array($_GET['page'], $pages)){
$inc_file = "core/inc_files/login.php";
}


else{
$inc_file = "core/inc_files/{$_GET['page']}.php";
}

include ($inc_file);
and when I enter a fake file, I get
error wrote: PHP Error Message

Warning: include(core/inc_files/fy.php) [function.include]: failed to open stream: No such file or directory in /home/*******/public_html/rss/index.php on line 24

Free Web Hosting

PHP Error Message

Warning: include() [function.include]: Failed opening 'core/inc_files/fy.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/*******/public_html/rss/index.php on line 24

Free Web Hosting
I can't figure out a way to redirect w/o an too many redirects.

Re: a big problem and a small problem with template system

Posted: Fri Jul 22, 2011 11:03 am
by jacek
If you want to redirect for all pages, just check for the session variable and ignore the page they requested.
if (isset($_SESSION['something']) === false){
    header ...
}

Re: a big problem and a small problem with template system

Posted: Fri Jul 22, 2011 9:27 pm
by JelvinJS7
I'm not sure that would work. if you're not logged in on most pages, you get redirected to login. of you're already logged in and you go to register or login then you redirect to read

Re: a big problem and a small problem with template system

Posted: Sat Jul 23, 2011 10:57 am
by jacek
Well to do that you could do
if (in_array($_GET['page'], array('login', 'register')) === false && isset($_SESSION['something']) === false){
    // login.
}else if (in_array($_GET['page'], array('login', 'register')) && isset($_SESSION['something'])){
    // read.
}
whcih can be simplified a bit, but you can do that ;)