![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
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:
<? $ID = $_GET['ID']; if($ID == ('1')) { include ('header.php'); include ('1.php'); include ('footer.php'); } elseif ($ID == ('2')) { include ('header.php'); include ('2.php'); include ('footer.php'); } elseif ($ID == ('3')) { include ('header.php'); include ('3.php'); include ('footer.php'); } else { include ('noid.php'); } ?> 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. ![]()
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
UNSTOPPABLE
Join Date: Aug 2003
Location: UK :: ICQ# 156068
Posts: 11,569
|
Bump for ya
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
|
Errr, use a switch statement.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
PHP Code:
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
|
PHP Code:
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
♥ ♦ ♣ ♠
Industry Role:
Join Date: Sep 2002
Posts: 10,592
|
PHP Code:
__________________
![]() ![]() ![]() "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Jan 2007
Posts: 190
|
Code:
$allowed_ids = array(1=>"1.php",2=>"2.php",3=>"3.php"); $ID = intval($_GET['ID']); $page = ""; if(array_key_exists($ID,$allowed_ids)) { $page = $allowed_ids[$ID]; include ('header.php'); include ($page); include ('footer.php'); } else { include ('noid.php'); } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
♥ ♦ ♣ ♠
Industry Role:
Join Date: Sep 2002
Posts: 10,592
|
Or here's another method...
PHP Code:
__________________
![]() ![]() ![]() "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
♥ ♦ ♣ ♠
Industry Role:
Join Date: Sep 2002
Posts: 10,592
|
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...
__________________
![]() ![]() ![]() "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
Quote:
Thanks a bunch everyone. Going to take these back and try em out on my project. Be back in a little bit. ![]() ![]()
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
Quote:
![]() ![]() ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
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.
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
Another option:
Code:
<?php $id = $_GET['id']; $page = preg_replace('/[^a-z0-9]+/', '', $id); if( is_file("$page.php") ) { include('header.php'); include("$page.php"); include('footer.php'); } else { include('noid.php'); } ?>
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Confirmed User
Join Date: May 2004
Posts: 1,327
|
Love watching coders one upping each other with their versions..and then the next...and the next...lol
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
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
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Confirmed User
Join Date: May 2003
Location: Yo Mommas Pussy
Posts: 3,320
|
I don't code for free... but if you want something done right.. hit me up
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
In my experience: If you charge for a simple 'please help' PHP 101, you're not likely to get a lot of response from the peanut gallery.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
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...
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
Confirmed User
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
Confirmed User
Join Date: Jan 2006
Location: England
Posts: 1,405
|
Code:
<?php switch ($id) { case 1: include("header.php"); break; case 2: include("header.php"); break; case 3: include("header.php"); break; default: echo "No number between 1 and 3"; } ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 |
Confirmed User
Join Date: Jan 2006
Location: England
Posts: 1,405
|
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.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 | |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
|
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 ?
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 |
Confirmed User
Join Date: May 2003
Location: Yo Mommas Pussy
Posts: 3,320
|
In my experience, If you do free work, you're wasting your time.
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 |
♥ ♦ ♣ ♠
Industry Role:
Join Date: Sep 2002
Posts: 10,592
|
You should read my post right under this one. I did a couple versions, and indicated that he could use that method if he wasn't concerned with security. There are many ways to do what he's asking for. I'm just giving him options.
__________________
![]() ![]() ![]() "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 | |
Too lazy to set a custom title
Join Date: Dec 2006
Posts: 23,400
|
Quote:
![]() ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 |
Confirmed User
Join Date: May 2005
Posts: 2,737
|
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'; $path = 'some/lib/path/' . (isset($_GET['id']) ? intval($_GET['id']) : 1) . '.php'; if (!file_exists($path)) { die("handle error goes here"); } include $path; include 'footer.php'; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 | |
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#30 |
Confirmed User
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
|
I love looking at other people's code. Always gives me new ideas and a new perspective on programming. It's sort of like staring at another man's junk when he's next to you in the urinal, but without all that awkwardness when he catches you looking and grabs your ass.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#31 | |
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#32 | |
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#33 |
Confirmed User
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#34 |
Confirmed User
Join Date: May 2005
Posts: 2,737
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#35 | |
Confirmed User
Join Date: Jan 2007
Posts: 190
|
Quote:
do debugging by testing if the different vars such as $ID are being set correctly. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#36 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
You pee sitting down, so the point is moot.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |