Page 1 of 1

A good way to deisgn my site?

Posted: Sat Oct 17, 2009 6:50 am
by frozenarmageddon
Hello there :D
I got this site and its based on a template as I am not into making it beautiful at this point, but more into making it work...
So Its devided to 5 parts:
Header
Left|Middle|Right
Footer

For every page the Header, Left, Right and Footer parts don't change at all [in the code that is]
So I thought making it less time consuming to make new pages by leaving the Header Left Right and Footer parts alone, and just editing the Middle...
I made this thing for the Index.php's middle section:

Code: Select all

 
<div id="middle">
        <?php
            if(isset($_GET['page']) && $_GET['page'] != NULL)
            {
                if(isset($_GET['ext']) && $_GET['ext'] != NULL)             //Used for diffrent file types i.e: goodies.html, game.jpg, etc'.
                {
                    $page       = $_GET['page'].".".$_GET['ext'];
                }
                else
                {
                    $page       = $_GET['page'].".php";             //But defaults to a .php extension for convenience.
                }
                require $page;
            }
            else
            {
                //The actual index.php's middle code
            }
        ?>
        </div>
 
It worked perfect for some pages in my site... untill I reached the $_SESSION variabls in the login/register page... It just doesn't work, and I thought to myself, if I use the GET method... it would be hard to set SESSION data for the next page...
So I am asking if there is any good way to make what I am trying to do? The only "limit" is that the page has to be "bookmark-able"\"favorite-able".

I don't mind just adding the whole other sections of a page manually to every page on my site... I am just looking for an easier automatic way, which might also make the code more readable [Less code = Easier to find the problem].

Edit:
I also thought of stuff like separate includes for the start of the page [Header, Left, Right] and the end [Footer] so I can just include them... But I guessed its not gonna work... and also I might forget to include one of them and then go crazy at trying to understand why it give me an error...
My third idea was make a function, something like

Code: Select all

function page($page, $ext)
{
    require header.php;
    if(isset($ext) && $ext != NULL)
        {
        require $page.".".$ext;
    }
    else
    {
        require $page.".php";
    }
    require footer.php;
}
but then it seemed really hard to change pages, and still many stuff won't work :\

Re: A good way to deisgn my site?

Posted: Sat Oct 17, 2009 12:07 pm
by PHPHorizons
Hello frozenarmageddon,

I don't see any reason why session vars wouldn't work there. The only detail you provided about them not working was "It just doesn't work". There's not a whole lot to go on there.

Besides that, you have major security problems there. You've allowed anyone to load any script into your site. Hopefully remote file includes are disabled...

Regardless, you need to do some validation on those $_GET['page'] and $_GET['ext'] variables.

Re: A good way to deisgn my site?

Posted: Sat Oct 17, 2009 3:40 pm
by frozenarmageddon
PHPHorizons wrote:I don't see any reason why session vars wouldn't work there. The only detail you provided about them not working was "It just doesn't work". There's not a whole lot to go on there.
Yea I don't too... I have no clue why it doesn't work... it just doesn't...
I backed up my site before doing this kind of major change, so I restored it... and it works fine... but with the change, it just don't o_O
PHPHorizons wrote:Besides that, you have major security problems there. You've allowed anyone to load any script into your site. Hopefully remote file includes are disabled...

Regardless, you need to do some validation on those $_GET['page'] and $_GET['ext'] variables.
It was just the simple "version" you know, before "over-coding" stuff, I need to check if it works ^^



Anyway, I don't really need a solution, just an idea, or direction, or just a single command to look up for that might help me make the whole site thing "^^

Re: A good way to deisgn my site?

Posted: Thu Oct 22, 2009 7:43 am
by TheOnly92
An obvious one: session_start() ?

Re: A good way to deisgn my site?

Posted: Fri Oct 23, 2009 10:44 am
by frozenarmageddon
TheOnly92 wrote:An obvious one: session_start() ?
Yea, I know, as I said, it worked as whole, but didn't as separate, so its not the problem :o
Anyway, I found a different way to do this, thanks to no one ">_<

Making this thread useless, and should be deleted ^^

Re: A good way to deisgn my site?

Posted: Fri Oct 23, 2009 10:00 pm
by PHPHorizons
frozenarmageddon wrote:[SNIPPED] ...it worked as whole, but didn't as separate, so its not the problem :o
Anyway, I found a different way to do this, thanks to no one ">_<

Making this thread useless, and should be deleted ^^
(I added the bold)

That's only because you didn't share your solution...

Re: A good way to deisgn my site?

Posted: Mon Nov 02, 2009 7:45 am
by frozenarmageddon
Oh ummm yea sorry o_o
Didn't think about it for some reason XD
Well it's easy...
I made a site_header.php and a site_footer.php
and then just required them in every page that needs them...

site_header.php

Code: Select all

<html><head><link href="style.css" rel="stylesheet" type="text/css" /><title><?php $_SESSION['site_title'] ?></title></head><body><div id="container">    <div id="header">    </div>    <div id="content">        <div id="left">        </div>        <div id="right">        </div>        <div id="middle">        </div>
site_footer.php

Code: Select all

     </div>    <div id="footer">    </div></div></body></html>
any_page.php

Code: Select all

<?php
    #########################################################
    $_SESSION['site_title']          = "The Site's Title";  #
    require "site_header.php";                              #
    #########################################################
?>
~contents~
<?php require "site_footer.php"; ?>
I use a different title for every page, but the same .css style sheet... so I use it this way.
But for those of you who don't change a site title, you can just remove the site title part.
And those who use different style sheets for every page, you can add to any_page.php:

Code: Select all

$_SESSION['site_css']          = "css_file.css";
and then change in site_header.php:

Code: Select all

<link href="style.css" rel="stylesheet" type="text/css" /> 
to:

Code: Select all

<link href="<?php $_SESSION['site_css'] ?>" rel="stylesheet" type="text/css" />
I think it might not work, so can someone test it out?