/    Sign up×
Community /Pin to ProfileBookmark

How to do (/index.php?page=something.php)?

Anyone know where a quick tutorial is on how to setup my pages like this? I don’t want to have “include header.php” and “include menu.php” and etc on all of my pages.

I just want the header, and the menu to be a part of the index, and then the blank space left next to the menu to be where my pages go.

I’ve used it in the past, a long time ago, but I don’t remember how exactly it went because I don’t have an examples laying around ?

Thanks in advance!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 30.2006 — I'm not sure that i've ever really seen a page setup like that... i'd assume you'd want to do something like this though

[code=php]
if(isset($_GET['page']))
$page = $_GET['page'];
else
$page = "default.php";

printHeader();//just some function that prints the header
include($page);
printFooter();//just some function that prints the footer[/code]
Copy linkTweet thisAlerts:
@blade52xauthorDec 31.2006 — I'm not sure that i've ever really seen a page setup like that... i'd assume you'd want to do something like this though

[code=php]
if(isset($_GET['page']))
$page = $_GET['page'];
else
$page = "default.php";

printHeader();//just some function that prints the header
include($page);
printFooter();//just some function that prints the footer[/code]
[/QUOTE]


I don't think that's what I was looking for. Thanks for the code anyway.

If I could maybe phrase this is a little easier: The site I once helped out with a few years ago, it was setup in a way that when you made a new page, all you had to do was put your information down... like:

<!-- Begin page-->

<p>hello</p>

<!-- End page-->

and when you saved that page and loaded it, it included everything - the header, menus, the whole entire layout was present.

Right now, the way my pages are setup, is every page has to call every part separatly... like:

<?php include('header.php') ?>

<table>

<tr>

<td class="someclass">

<?php include('lmenu.php')?></td>

<td width=100%>

<!-- Begin page-->

<p>Hello</p>

<!--End page-->

</td></tr></table>

The result ends up being the same, but it's just a little annoying having to include all that extra stuff ?
Copy linkTweet thisAlerts:
@NightShift58Dec 31.2006 — What chazzy gave you will do it for you - only with a bit more flexibility...

Take a look at your code:[code=php]<?php include('header.php') ?>
<table>
<tr>
<td class="someclass">
<?php include('lmenu.php')?>
</td>
<td width=100%>
<!-- Begin page-->
<p>Hello</p>
<!--End page-->
</td>
</tr>
</table>[/code]
And now chazzy's:[code=php]if(isset($_GET['page']))
$page = $_GET['page'];
else
$page = "default.php";

printHeader();//just some function that prints the header
include($page);
printFooter();//just some function that prints the footer[/code]
Aside from the table, both solutions lead to very similar results. Chazzy's way, though, is more flexible, as you wouldn't have to make any modifications to the user's input/content. You could "merge/modify" your code with chazzy's and you get:[code=php]<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = "default.php";
}

include('header.php'); // or better: chazzy's printHeader()

print "<table>";
print "<tr>";
print "<td class='someclass'>";
include('lmenu.php');
print "</td>";
print "<td width=100%>";
include($page);
print "</td>";
print "</tr>";
print "</table>";
include("footer.php"); //or better: chazzy's printFooter()
?>
[/code]
If you ever need to change layouts, you would only need to modify "index.php" instead of - as your code would require - modifying tens or hundreds of individual pages. In fact, using chazzy's basic framework, you could easily store the user-generated content in a MySQL table because he doesnt mix content and layout ('abstraction').
Copy linkTweet thisAlerts:
@blade52xauthorDec 31.2006 — Thank you both [b]so much[/b].

This works perfectly, and makes making new pages so much simpler.

(I didn't realize how that code earlier worked, I thought it was a script that would have simply redirected someone to default.php all the time, I didn't know the part above it did all the magic - now I know)

  • - Thanks again!
  • ×

    Success!

    Help @blade52x spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...