I'm going to take the time to explain to you step-by-step what this code does. I'll log into your ftp server and get it working for you if that's what it takes. It's not very hard so here goes.
<a href=index.php?page=50000>hello</a>
Look at the above link. When you click that link, it's going to take you to the page index.php, and it's going to create a variable called page with a value of 50000. You access this variable by using $_GET['page']
if you were to
echo $_GET['page']
on index.php, you would see 50000 appear on the page. If you changed the number to something else then echo'd $_GET['page'], the number in the url would appear. It's simply a variable located in the url that works like any other variable. Got it?
Now, take the code I gave you. Put it in a file called index.php
if(!isset($_GET['page'])) {
include("index2.php");
} else {
if(!file_exists($_GET['page'].".php")) {
include("404.php");
} else {
include($_GET['page'].".php");
}
}
I'm going to break this down for you line by line.
- if(!isset($_GET['page'])) {
I assume you know what an if statement does. So what does the function
isset() do? It basically determines whether a variable has been set or not. Now, the variable you want to have in the url is $_GET['page'], right? If that variable isn't there, the script won't know the proper file to include. So line 1 says "if variable 'page' is NOT set"...do something
- include("index2.php.php");
This is what is going to happen if the variable 'page' is NOT set because it is within the if statement. It will include the file "index2.php". index2.php is a file that should contain your home page content. "Welcome to this page" etc etc
- } else {
If this else evaluates, that means that variable 'page' IS set. It's in your url and has a value.
- if(!file_exists($_GET['page'].".php")) {
So now, within this else statement, there's another if statement. What does the function file_exists() do? Well, it checks if a certain file actually exists on the server. But what's the point of using this function? Well, when you put variable in the url, it's possible for someone to change the variable then refresh the page. Let's say the url is
index.php?page=dogs
but they change it to
index.php?page=giraffes
You don't have any files named giraffes on your server, so you need to load a file that will have a "This page does not exist on our server" type error message. What this line of code does is says "If the following file DOESN'T EXIST: [variable page goes here].php", do something....
- include("404.php");
Include a file named 404.php. This only happens when "The following file DOESN'T EXIST: [variable page goes here].php" returns true. 404.php needs to be created and put on your server so it will load when people mess around with the page variable in the url.
- } else {
Else, the file [variable page goes here].php DOES exist on the server, and needs to be included.
- include($_GET['page'].".php");
include [variable page goes here].php
listen carefully: YOU DON'T HAVE TO MANUALLY INSERT THE PAGE TO INCLUDE. THAT'S WHAT VARIABLES ARE FOR. This script takes the variable in the url, and automatically includes the proper page. Get it?
Try the code. Play around with it.
im going to say you dont know.
That's very offending and I almost didn't respond because of that. I've been trying to help you out, but you gotta play around with the code given to you. Look up functions at php.net if you have to figure out what it does, or else ask me to break it down line by line. Don't threaten to go somewhere else because something isn't working the way you want. Ask better, more-detailed questions, include links to the script so I can see it in action, and tell me what you tried (if you tried anything at all) so I know where you are. Then, tell me the results you got when you tried that. It's difficult helping someone without adequate information.
Anyways, I spent a lot of time breaking this down for you. I hope you'll take some time to read it and play around with it.
Cgraz