Reply
need some help with PHP varible stuff
Old 05-24-2005, 04:05 PM need some help with PHP varible stuff
Novice Talker

Posts: 9
ok well on my website we use a basic php code that displays a page in on the layout decided by the inputted page name like

?page=contact
heres the code we use

Code:
<?php
$pool = @include($_GET['page'] . ".php");
if (!$pool) { include("news/show_news.php"); }
?>
and the danger of this is that apperntly someone can enter other url;s in the varible and do things like launch attacks and other un wanted things. i was told theres some kind of IF statement or something you can use to only make it display internal pages or only pages specified. but i dont know what this code is, any help is appreciated

~scoot
scoot is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-27-2005, 02:02 PM Map your pages
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Scoot,

I am not aware of the code to which you are referring, but you could writ e something more secure for yourself. Create some random numbers -- let's say 57, 412, 3088, 5699

Then map each of those to a page. So in $_GET[page], you'll just pass a number and it provides you the security that user input cannot short-circuit your logic. Then:

PHP Code:

$pageNum 
$_GET[page];

if( ! empty (
$pageNum) )
{
    
$includeFile mapPg$pageNum );
    include( 
$includeFile );
}


function 
mapPg$v )
{
    
$page "";

    switch( 
$v )
    {
        case 
57:  $page "something1.php"; break;
        case 
412:  $page "something2.php"; break;
        case 
3088:  $page "something3.php"; break;
        case 
5699:  $page "something4.php"; break;
        default:  
$page "error.php"; break;
    }
    return 
$page;



__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 05-29-2005, 01:34 PM
Average Talker

Posts: 28
I am not really sure why you would do it this way and not just store everything in arrays and call to it when needed based on $_POST['criteria']
techniner is offline
Reply With Quote
View Public Profile
 
Old 05-29-2005, 01:53 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Moved to the php board.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 05-30-2005, 01:53 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Quote:
Originally Posted by techniner
I am not really sure why you would do it this way and not just store everything in arrays and call to it when needed based on $_POST['criteria']
tehniner,

This was just an idea that will require very little code change from the current mechanism but does provide some security from malicious code. Please post your code ideas as an alternative.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Reply     « Reply to need some help with PHP varible stuff
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14787 seconds with 13 queries