Click to See Complete Forum and Search --> : Calling the theme & files.


DanUK
10-21-2003, 08:58 PM
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!

Jona
10-21-2003, 10:05 PM
For what you said about index.php, use this...


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


(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:


<!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>


And then use this at the beginning of every file:


<?php
include("headers.php");
?>


Then, use this as your footer:


</div>
</body></html>


And assuming it's named footers.php, this at the bottom of every page.


<?php
include("footers.php");
?>


So a simple page with simple text on it would look like this:


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


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.

[J]ona

DanUK
10-22-2003, 02:32 AM
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:


<?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");

?>


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:


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


Is that ok with the die message, etc?

Thanks! I'm now looking for "Sorry that file doens't exist" message :)

DanUK
10-22-2003, 07:42 AM
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.

Jona
10-22-2003, 01:36 PM
if(file_exists("dir/file.ext")){
echo("File exists.");
} else {
echo("File does not exist.");
}


[J]ona

DanUK
10-22-2003, 07:44 PM
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

Jona
10-22-2003, 11:13 PM
Not bad, well thought out.

[J]ona

DanUK
10-23-2003, 04:08 AM
Yay - that manual is good!

Jona
10-23-2003, 07:46 PM
Originally posted by skydan
Yay - that manual is good!

And why shouldn't it be? They wrote the language, after all. :D

[J]ona

DanUK
11-04-2003, 06:33 AM
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!

pyro
11-04-2003, 07:33 AM
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

DanUK
11-04-2003, 04:41 PM
Thanks for your reply.

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

Many thanks.

Jona
11-04-2003, 05:26 PM
You mean retrieve the values? Use $_GET["id"] for the second one, and $_GET["p"] for the first.

[J]ona

DanUK
11-06-2003, 06:37 PM
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.

Jona
11-06-2003, 08:24 PM
<?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>");
?>


[J]ona

DanUK
11-07-2003, 07:50 AM
Yay thanks!
I'll give this a shot when I finish work later.

Many thanks again.

DanUK
11-08-2003, 05:50 PM
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


Your IP address is: <?php ... ?><br>
Your browser is: <?php ... ?><br>


Thanks.

Jona
11-08-2003, 06:26 PM
<?php
echo($_SERVER["REMOTE_ADDR"]); # ip address
echo("<br>". $_SERVER["HTTP_USER_AGENT"]);
?>


[J]ona

DanUK
11-09-2003, 09:12 PM
Fabulous, thank you!

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


<?php

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

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

?>

pyro
11-09-2003, 09:22 PM
You could also use:

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

Your browser is: <?php $_SERVER['HTTP_USER_AGENT']; ?><br>

DanUK
11-10-2003, 06:32 PM
Hi, would I not need "echo" on the second please?

Jona
11-10-2003, 08:16 PM
Must've been a typo. ;)

[J]ona

pyro
11-10-2003, 09:04 PM
Correct, you do need the echo. My bad.

DanUK
11-11-2003, 07:23 AM
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.

Jona
11-11-2003, 11:08 AM
I'd modify the current search engine to exclude .php after it, or just use explode() (http://php.net/explode) to get the URL without the .php extension in the "p" variable.

[J]ona