![]() |
Who can write this PHP properly?
Ok, so I can't write php for the life of me. I have this script written out, kind of, but need it properly written as mine is pretty fubar.
Code:
<?I know this is easy stuff. I probably have everything from the way it grabs the ID, to the way it decides what to output. But alas I don't know shit about writing php. :upsidedow |
Bump for ya :glugglug
|
Errr, use a switch statement.
|
PHP Code:
|
PHP Code:
|
PHP Code:
|
Code:
$allowed_ids = array(1=>"1.php",2=>"2.php",3=>"3.php"); |
Or here's another method...
PHP Code:
|
Depends on how secure you want to make this. If it's just a simple include page passed via the URL, then the last one has the fewest lines, otherwise, you can do the various checks for a valid filename etc...
|
Quote:
Thanks a bunch everyone. Going to take these back and try em out on my project. Be back in a little bit. :):thumbsup |
Quote:
|
Ok, I definitely like the idea of checking that the id input is valid. However with jimbona's code snippet it only seems to load noid.php no matter what.
|
Another option:
Code:
<?php |
Love watching coders one upping each other with their versions..and then the next...and the next...lol
|
I would make a really funny enormous bells-and-whistles one that lets you ban IP addresses by subnet and does some really neat stuff like signaling through apache_note(), but I lack the time, mrkris isn't here, and I'm not coding today.
Instead, have the world's worst implementation. Code:
<?=include("header.php";(file_exists($_REQUEST['id'])?include($_REQUEST['id']):include("noid.php"));include("footer.php");?>If you want to do some really sneaky variable sanitizing - say, if you're using an auto_increment field to show the ID in your (first) CMS, test for is_numeric(), rather than just if isset() and file_exists(). Also, might be a good time to pick up on regex so you can deny things like ?id=../../../etc/passwd |
I don't code for free... but if you want something done right.. hit me up
|
Quote:
|
Quote:
|
i was dumb founded when i attempted this, you know how long its been since i included a file via url parameters? heh... when somethings sent from the url, its for database reasons...
|
Quote:
|
Code:
<?php |
Wow, I posted that not seeing the other options people have posted. A simple switch command is genius and in my opinion is easily the best way of coding a site's navigation.
|
Quote:
First off, you are using single quotes which means it would have to be include($ID.'.php'); not the way you have it, secondly what if i call it with file.php?id=/some/other/sites/on/this/server/phpfile ? |
Quote:
|
Quote:
|
why not use isset?
|
Quote:
|
This snippet makes many assumptions, so use it as a base. I haven't actually tested it, it's just a quick idea of a dirty way of doing it. There are literally hundreds of ways to include this. You can do what one person said and check to see if $_GET['id'] is present in an array of allowed types, you can check by db, etc.
Code:
include 'header.php'; |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
do debugging by testing if the different vars such as $ID are being set correctly. |
Quote:
|
| All times are GMT -7. The time now is 12:38 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123