Show DevBest [PHP] Index?page=

Status
Not open for further replies.

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
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.
what you could do is set the page that ?page=blah do something like this:
PHP:
<?php
include('thefirstpageIwant.html');
include('ohwaitIwantanotherone.html');
?>
 

Dzetki

The Prodigal Son Returns
Jul 16, 2010
990
220
what you could do is set the page that ?page=blah do something like this:
PHP:
<?php
include('thefirstpageIwant.html');
include('ohwaitIwantanotherone.html');
?>
I meant, how can i add multiple links via a MySQL database, something like that. But i've figured an answer for my question ages ago. But thanks anyways. :cool:
 

xenogfx

New Member
Oct 24, 2011
24
12
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" );
}
?>

thats better your last code was bad...due to the RFI or LFI in it LMFAO...
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
Remember (always) use urlencode to secure your $_GET parameters! Example like this:
Code:
$page = urlencode($_GET['page']);
int_val($news_id)===(int)$news_id
A nice feature is also, when you only wan't to parse integer (numbers) instead of string (text) do this:
Code:
$id = urlencode($_GET['id');
 
if(intval($id) === (int)$id) // checks if $id is a integer
{
// Do your stuff here...
}

You may ask Why not just use is_numeric? Because intval attempts to convert the string to a integer. is_numeric just return true or false. They do different things, so if the number you thought you typed really was outputted as string (for some reason) is_numeric will just not run the code that you wan't.
 
Status
Not open for further replies.

Users who are viewing this thread

Top