Show DevBest [PHP] Index?page=

Status
Not open for further replies.

RyanMK

Still alive
May 27, 2010
802
117
You know on websites when you get in the url bar:



With this PHP code you can do just that:
PHP:
<?php $page = $_GET['page']; 

switch($page)
{
case 'blah': /* This is what goes after page= */
include 'projects.html'; /* link to the file you want to open */
break;
} ; 
?>

Enjoy :)

To add more pages just copy and paste from case to break; and change the details.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
One thing you should NEVER do when using this method is this:

PHP:
<?php
$page = $_GET['page'];
include( $page );
?>

Because some crafty bastard will put a shell through the 'page' parameter:
Code:
www.site-link.com/index.php?page=http://www.linktoshell.com

And through that code, they can inject PHP shells into your site.
 

RyanMK

Still alive
May 27, 2010
802
117
One thing you should NEVER do when using this method is this:

PHP:
<?php
$page = $_GET['page'];
include( $page );
?>

Because some crafty bastard will put a shell through the 'page' parameter:
Code:
www.site-link.com/index.php?page=http://www.linktoshell.com

And through that code, they can inject PHP shells into your site.

'ucking hackers, seems you can't do anything on the web these days without getting defaced.
 

Benden

maging ang maganda mamatay
Jun 4, 2010
2,286
1,482
Thanks :) I will def use this but can you fix what m0nsta pointed out?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Retroa posted the correct way of doing it, I pointed out the bad/unsafe way of doing it.
If you do it my way, have a nice time getting defaced.
 

Savallusion

#swipeproject
Jul 16, 2010
990
220
I love the code ryan =D but i have one question, how can i add multiple links as in a navigational system without adding it lots of times, and manually? Going to use it anyways though.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
I love the code ryan =D but i have one question, how can i add multiple links as in a navigational system without adding it lots of times, and manually? Going to use it anyways though.

Do you mean like:
Code:
www.site.com/index.php?page=edit&do=password
...etc?
 

RyanMK

Still alive
May 27, 2010
802
117
There is a way, but I'm not sure on how it's supposed to work. I'll look it up for you :)
 

Savallusion

#swipeproject
Jul 16, 2010
990
220
Do you mean like:
Code:
www.site.com/index.php?page=edit&do=password
...etc?

I mean like, i could use a part of my admincp to add new navigator links with that code. When everything on it has been inserted i would like it to automatically add it to the navigator on my site.

@Ryan thanks mate ;D
 

blockustomz

New Member
May 28, 2011
5
0
thanks for this.. but i need help.. how do i get that page=album1 into the middle of the page.. instead of the top


i want it to appear in the middle
 

RyanMK

Still alive
May 27, 2010
802
117
thanks for this.. but i need help.. how do i get that page=album1 into the middle of the page.. instead of the top


i want it to appear in the middle

Insert the PHP code where you want the content to be loaded.

EDIT: For the text on index.php instead of typing it in the .php file you can make it load an external HTML file

PHP:
case '': /* This is what goes after page= */
include 'home.html'; /* link to the file you want to open */
break;
 

blockustomz

New Member
May 28, 2011
5
0
thanks for the fast reply..this is how its setup on lyrics.php
// output page
page_header($user->lang['Lyrics']);
//page_header($config['sitename']);


$template->set_filenames(array(
'body' => 'portal/lyrics.html'

));
$page = $_GET['page'];

switch($page)
{
case 'album1': /* This is what goes after page= */
include 'album1.html'; /* link to the file you want to open */
break;
} ;

// SQL + ACP eklenecek
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();

?>

?? shouldnt it be in the middle since its between header and footer?
 

RyanMK

Still alive
May 27, 2010
802
117
I see, your using a script.

In that case you will probably have to use the code in "portal/lyrics.html"
 

blockustomz

New Member
May 28, 2011
5
0
so i just put
<?php $page = $_GET['page'];

switch($page)
{
case 'album1': /* This is what goes after page= */
include 'album1.html'; /* link to the file you want to open */
break;
} ;
?>

into the page of portal/lyrics.html ?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
You can also do:

PHP:
<?php
$pages_arr = array( "home", "about", "contact", "services" );
$page = strip_tags( $_GET['page'] );
if( !in_array( $page, $pages_arr ) )
{
	echo "Invalid page!";
}
else
{
	include( strtolower( $page ) . ".php" );
}
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top