php?id=something

Nate_Benton

New Member
Messages
570
Reaction score
0
Points
0
I'm creating a site and want to use this "effect" where its the same php page, but its like different sites, with id's though.
I'm dumb with php, so if anybody can run down how to do this, I'd greatly appreciate it.
 

celebraces

Banned
Messages
12
Reaction score
0
Points
0
Code:
<?php
include($_GET['id'].".php");
?>
Save your files as *.php and save them in the same folder as the script. Link to the individual pages as <a href="index.php?id=home"> etc.
 

Tomballa

New Member
Messages
30
Reaction score
0
Points
0
celebraces said:
Code:
<?php
include($_GET['id'].".php");
?>
Save your files as *.php and save them in the same folder as the script. Link to the individual pages as <a href="index.php?id=home"> etc.
Correct me if I am wrong, but can't someone load a remote php page and destroy your site using that?
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
PHP:
<?php
$page = $_GET['id'];
if (file_exists("public_html/$page.php")) {
include("$page.php");
} else { echo "file not found"; }
?>

would that help prevent people from messing up your site?
 
Last edited:

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
Instead of using .php?id=something, look into permalinks and mod_rewrite. X10 supports rewrite rules, and they can help the security of your site and look a helluva lot nicer than ?id=...

Instead of yourdomain.com/index.php?id=something&a=b you would have yourdomain.com/something/b/ or similar.
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
The_Magistrate said:
Instead of using .php?id=something, look into permalinks and mod_rewrite. X10 supports rewrite rules, and they can help the security of your site and look a helluva lot nicer than ?id=...

Instead of yourdomain.com/index.php?id=something&a=b you would have yourdomain.com/something/b/ or similar.

is this how you would do it?
in htaccess file
RewriteRule index/(.*)$/(.*)$ /index.php?id=$1&a=$2
 

[XiRE]

New Member
Messages
44
Reaction score
0
Points
0
Nate_Benton said:
I'm creating a site and want to use this "effect" where its the same php page, but its like different sites, with id's though.
I'm dumb with php, so if anybody can run down how to do this, I'd greatly appreciate it.
i wrote about a solution for this after seeing your thread in my PHP includes tutorial.
 

Tomballa

New Member
Messages
30
Reaction score
0
Points
0
PHP:
<?php
function index()
{
include ("home.php");
}

$choice=$_GET['id'];

switch($choice)
{
case "faq":
include ("faq.php"); 
break;

case "tutorials":
include ("tuts.php"); 
break;

default:
index();
}
?>
In the script above, if someone where to go to index.php, it would show the home.php file. If someone where to go to index.php?id=faq, faq.php would load but the url would still look like index.php?id=faq

This is just an example of what you can use to fit your needs. You don't have to use includes for this to work. I just did b/c that is the simplest way.
 
Last edited:

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
Tomballa said:
PHP:
<?php
function index()
{
include ("home.php")
}

$choice=$_GET['id'];

switch($choice)
{
case "faq":
include ("faq.php"); 
break;

case "tutorials":
include ("tuts.php"); 
break;

default:
index();
}
?>
In the script above, if someone where to go to index.php, it would show the home.php file. If someone where to go to index.php?id=faq, faq.php would load but the url would still look like index.php?id=faq

This is just an example of what you can use to fit your needs. You don't have to use includes for this to work. I just did b/c that is the simplest way.

That way isn't the simplest, but it is definately a secure way ;). The quickest was the first idea posted in this thread - but it was highly insecure.
 

Tomballa

New Member
Messages
30
Reaction score
0
Points
0
lambada said:
That way isn't the simplest, but it is definately a secure way . The quickest was the first idea posted in this thread - but it was highly insecure.
I was talking about echoing all of the pages in that one file vs includes. :)



Also, I edited my post. I forgot a semicolon at the end of include ("home.php")
 
Last edited:

celebraces

Banned
Messages
12
Reaction score
0
Points
0
Hmm, I did it very quickly, I did't think about security, sorry. Perhaps this is a simpler and more secure way?

<?php
include("/home/your_user_name/public_html/your_directory/".$_GET['id'].".php");
?>
 
Top