• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

how would i go about doing this

is0lized

See Below
how would i go about doing this or where could i find it, dont know what category it would be under at a php resource site


site.com/index.php?page=info
site.com/index.php?page=stats
site.com/index.php?page=other/index


ect, anyone know?
 
Are you assuming that each of these files will have an extension of .html and you're using relative paths?

You can do:

include("$page.html");

That's it. :biggrin2:
 
I don't remember the basic syntax, but all you have to do is link to the page like href="index.php?something" then use $something in your script to include a txt file or whatever in that part of the page. Someone else can explain it better. I don't exactly remember.


Okay, found my old files. Just link like i said, href="$PHP_SELF?page", then add this php code in your site where you want to include the binary file to process:

<?php
include("./$page.php");
?>

So, if you link to href="$PHP_SELF?home", it will include the file "home.php", which is found in your root directory. If you don't know any php whatsover, this won't make much sense, but ask questions, I'll try to explain it.
 
you need to read the query string and separate the page thing, then setup if(page == blah) { your stuff }
 
index.php:
PHP:
<html>
<head>
<title>My Page</title>
</head>

<body>

<?

// no variable value... your main page
if (!$page) {
include("home.php");
}

// if the variable is "info"
elseif ($page == "info") {
include("info.php");
}

// if the variable is "stats"
elseif ($page == "stats") {
include("stats.php");
}

// if all else fails, could be your "404 error" page
else {
include("error.php");
}

?>

</body>
</html>
etc, etc...

you could store all you pages in another directory that no one knows exists [since it's embedded in the php output], then the php code would look like this:
PHP:
<?

if (!$page) {
include("pages/home.php");
}

elseif ($page == "info") {
include("pages/info.php");
}

elseif ($page == "stats") {
include("pages/stats.php");
}

else {
include("pages/error.php");
}

?>
so if domain.com is called, it'll parse/pages/home.php into index.php

if domain.com/?page=info is called, it'll parse/pages/info.php into index.php

if domain.com/?page=doink, etc... is called, it'll load /pages/error.php, your error page

the code hayama-kun typed above will work, but this code will avoid the default php error text that looks like crap.
 
Last edited:
is0lized, you just can't jump into the guts of PHP. I did that 2 years ago with Perl and screwed up big time. You need to start with the basics, and I suggest you find a book or a tutorial online.
 
Originally posted by Canuckkev
Isn't it a lot easier to just:

PHP:
<?php 
include("./$page.php"); 
?>

yeah, but if someone were to manually enter /index.php?page=asdf [or any variable not pre-defined], you get the generic php error text. it just keeps the site a lot neater and more professional looking in the example i gave.

but if you're lazy and want to give people the location of your site's server paths, be my guest.
 
Why not just use the function FILE_EXISTS to check? So even with hundreds link, you don't have to edit/add. You can also customised the error page. :D

PHP:
<?php
if(FILE_EXISTS("$page.php")) {
include("$page.php");
} else {
include("error.php");
}
?>
 
thats kool, I never though of that either but that takes the whole index.php?file=2e13392 thing and throws it out the window :D
 
Good idea, bad programming none the less. Later on, you use to learn switch() instead of if() { } elseif() { } else { }...

Code:
switch($page)
{
case '':
 include('blah.html');
break;
case 'stats':
 include('stats.html');
break;
case 'so on':
 include('whateverotherpage.html');
break;
}
 
Originally posted by AlieXai
Good idea, bad programming none the less. Later on, you use to learn switch() instead of if() { } elseif() { } else { }...

Code:
switch($page)
{
case '':
 include('blah.html');
break;
case 'stats':
 include('stats.html');
break;
case 'so on':
 include('whateverotherpage.html');
break;
}
You can also read a dir, and loop the files in the dir and print them with some kind of order....
there is many ways to do stuff like this....
 
Originally posted by AlieXai
Good idea, bad programming none the less. Later on, you use to learn switch() instead of if() { } elseif() { } else { }...

Code:
switch($page)
{
case '':
 include('blah.html');
break;
case 'stats':
 include('stats.html');
break;
case 'so on':
 include('whateverotherpage.html');
break;
}

I've seen that way, but I heard it wasn't any "better". Is it?
 
Back
Top