/    Sign up×
Community /Pin to ProfileBookmark

Calling the theme & files.

Hi there. I’m now on a new mission!

My Server supports PHP, and I have created a theme (which I haven’t made “active yet”) – and I have created all my content files, with the html content (no <html> etc tags…we’ll get to that ?) and put them as .php files.
How “easy” would it be to call them from index.php, and it gets it’s “theme” from there? i.e. index.php?p=forum would load forum.php.
In the .php content files, I realise I have to “open” the theme, so the content gets placed within, but how easy is it to achieve this type of thing?

Many thanks!

to post a comment
PHP

24 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 22.2003 — [font=arial][color=maroon]For what you said about index.php, use this...[/color][/font]

[code=php]
<?php
if(isset($_GET["p"])){
$p = $_GET["p"];
header("Location: $p");
}
?>
[/code]


[font=arial][color=maroon](Make sure you put that before anything else in the document.)



If you want to have a basic "theme" for every page, make a header.php file, like this for example:[/color]
[/font]

[font=monospace]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

&nbsp; "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en-US">

<head><title>Title of the page - you can use $_GET["title"] on each page if you like</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css"><!--

@import url("your_stylesheet.css");

--></style>

</head>

<body>

<div>

[/font]

[font=arial][color=maroon]And then use this at the beginning of every file:[/color][/font]

[code=php]
<?php
include("headers.php");
?>
[/code]


[font=arial][color=maroon]Then, use this as your footer:[/color][/font]

[font=monospace]

</div>

</body></html>

[/font]

[font=arial][color=maroon]And assuming it's named footers.php, this at the bottom of every page.[/color][/font]

[code=php]
<?php
include("footers.php");
?>
[/code]


[font=arial][color=maroon]So a simple page with simple text on it would look like this:[/color][/font]

[code=php]
<?php
include("headers.php");
?>
This is the text. It is inside of a DIV.
<?php
include("footers.php");
?>
[/code]


[font=arial][color=maroon]Of course, there are many other things you can do with this, such as making connecting to a database in headers.php, and closing the database in footers.php, which saves you a lot of extra coding.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorOct 22.2003 — Brilliant thanks!!!

Exactly the info I needed, wonderful!

Just one last question, say for a staff-listing, where I would create a new dir "staff" and have index.php there with a staff listing, and then other .php files with the staff name, how do I call them?

would it be www.domain.tld/page.php?p=/contact/index.php&file=staffname

?

Thanks!

Just did a bit of reserach too, and I'll add the following so the pages CANNOT be loaded directly:

[code=php]
<?php
if (!eregi("page.php", $_SERVER['PHP_SELF'])) {
die ("You can't access this file directly...");
}
if (!isset($mainfile)) { include("page.php"); }
$index = 0;
include("header.php");
?>

<div align="justify">
All the rest of the HTML content.
</div>

<?php
include("footer.php");

?>
[/code]


Is that ok ? I..e I don't need opentable(); etc?

Furthermore, instead of using index.php?p=... I think i'll use "page.php" - as I want index.php just to have data, and for it not to be loaded directly, so, for page.php:

[code=php]
<?php
if(isset($_GET["p"])){
$p = $_GET["p"];
header("Location: $p");
}
else {
die ("Sorry, you can't access this file directly...");
}
?>
[/code]


Is that ok with the die message, etc?

Thanks! I'm now looking for "Sorry that file doens't exist" message ?
Copy linkTweet thisAlerts:
@DanUKauthorOct 22.2003 — Ok, just about to begin with re-doing all my site.

Can someone say I've got the above, in my other post correct?

Is that "page.php" quite secure, etc?

I just need to find out now how to add the errors such as file doesn't exist, and suchlike.

Many thanks if you can help me with this - looking forward to getting this done!!! hehehe.

Thanks again.

Dan.
Copy linkTweet thisAlerts:
@JonaOct 22.2003 — [code=php]
if(file_exists("dir/file.ext")){
echo("File exists.");
} else {
echo("File does not exist.");
}
[/code]


[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorOct 23.2003 — Hey there.

Did some more research, and after LOTS of reviewing, finally found what I was looking for - the original one we came up with only directed the page, not loaded it.

This works perfect, but if you think i should add / do anything please let me know.

If you think it's ok - please post and say so - i'll feel a lot better. I really appreciate all your kind help.

page.php:

test
Copy linkTweet thisAlerts:
@JonaOct 23.2003 — [font=arial][color=maroon]Not bad, well thought out.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorOct 23.2003 — Yay - that manual is good!
Copy linkTweet thisAlerts:
@JonaOct 24.2003 — [i]Originally posted by skydan [/i]

[B]Yay - that manual is good! [/B][/QUOTE]


[font=arial][color=green]And why shouldn't it be? They wrote the language, after all. ? [/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorNov 04.2003 — Hi there.

New query related to this above.

Is there a way instead of having to call all my staff profiles like page.php?p=staff-name that I can do page.php?p=staff?id=3 and it will give their info / pic?

How is this achieved?

Many thanks!
Copy linkTweet thisAlerts:
@pyroNov 04.2003 — You'd want to do it like this:

page.php?p=staff&id=3

Or better, like this, to validate:

page.php?p=staff&amp;amp;id=3
Copy linkTweet thisAlerts:
@DanUKauthorNov 04.2003 — Thanks for your reply.

Yes, page.php?p=staff&id=3 is what i'm looking for.

How is this achieved please?

Many thanks.
Copy linkTweet thisAlerts:
@JonaNov 04.2003 — [font=arial][color=maroon]You mean retrieve the values? Use $_GET["id"] for the second one, and $_GET["p"] for the first.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorNov 07.2003 — Hiya, sorry, I think i'm being dumb here.

What I want to achieve is a staff page to have the details of each staff member, as you helped me to begin with, staff.php for instance would be loaded with page.php (page.php?p=staff) and then i wanted to load the staff id, i.e. page.php?p=staff&id=2, how would I get the details to appear?

Thanks.
Copy linkTweet thisAlerts:
@JonaNov 07.2003 — [code=php]
<?php
if($_GET["p"] == "staff"){
$firstHeading = "Staff Members:";
}

if(isset($_GET["id"])){
$staff_id = $_GET["id"];
}

$staff_Ary = array("first staff member's name (id=0)", "second staff member's name (id=1)"); # add as many as you want

$staff_details = array("Information to be posted for the first staff member (id=0)", "Information to be posted for the second staff member (id=1)", "Information to be posted for the third staff member (id=2)"); # arrays start at zero rather than one

echo("<h1>". $firstHeading ."</h1>");
echo("<h2>". $staff_Ary[$staff_id] ."</h2>");
echo("<p>". $staff_details[$staff_id] ."</p>");
?>
[/code]


[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorNov 07.2003 — Yay thanks!

I'll give this a shot when I finish work later.

Many thanks again.
Copy linkTweet thisAlerts:
@DanUKauthorNov 08.2003 — Ok great, that worked wonderful!

Instead of starting another thread, I thoguht I'd ask my next query here.

On my contact form I wanted to have at the button something like:

Your IP address is: ...

Your browser is: ...

How would I achieve this please?

Would it be something like

[code=php]
Your IP address is: <?php ... ?><br>
Your browser is: <?php ... ?><br>
[/code]


Thanks.
Copy linkTweet thisAlerts:
@JonaNov 09.2003 — [code=php]
<?php
echo($_SERVER["REMOTE_ADDR"]); # ip address
echo("<br>". $_SERVER["HTTP_USER_AGENT"]);
?>
[/code]


[b][J]ona[/b]
Copy linkTweet thisAlerts:
@DanUKauthorNov 10.2003 — Fabulous, thank you!

I wanted to add a bit of text before, so I used:

[code=php]
<?php

echo("<b>Your IP:</b>". $_SERVER["REMOTE_ADDR"]); # ip address

echo("<br><b>Your browser:</b>". $_SERVER["HTTP_USER_AGENT"]);

?>
[/code]
Copy linkTweet thisAlerts:
@pyroNov 10.2003 — You could also use:

[code=php]Your IP address is: <?php echo $_SERVER['REMOTE_ADDR']; ?><br>

Your browser is: <?php $_SERVER['HTTP_USER_AGENT']; ?><br>[/code]
Copy linkTweet thisAlerts:
@DanUKauthorNov 11.2003 — Hi, would I not need "echo" on the second please?
Copy linkTweet thisAlerts:
@JonaNov 11.2003 — [font=arial][color=maroon]Must've been a typo. ?[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@pyroNov 11.2003 — Correct, you do need the echo. My bad.
Copy linkTweet thisAlerts:
@DanUKauthorNov 11.2003 — Hehe, Okay, thanks!

I am now on another mission ?

I've been hunting and hunting around sites such as HotScripts.com trying to find a PHP search engine.

The problem is most of them echo the file extension.

As my site uses page.php?p=blah to load a file, the Search script needs to be able to do that too.

At the moment, when it finds a file, it shows the link (quite correctly) as page.php?p=blah.php, but my page.php does not allow the file extension, it just has to be "page.php?p=blah" to work.

Are you aware of any decent php search script that I could get to do that?

I'm not that "Pro" on this yet, ...

Thanks.
Copy linkTweet thisAlerts:
@JonaNov 11.2003 — [font=arial][color=maroon]I'd modify the current search engine to exclude .php [i]after[/i] it, or just use [url=http://php.net/explode]explode()[/url] to get the URL without the .php extension in the "p" variable.[/color][/font]

[b][J]ona[/b]
×

Success!

Help @DanUK 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.18,
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,
)...