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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-20-2008, 01:26 PM   #1
potter
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');
}
?>
So basically if someone goes to said page.php?ID= and the ID is there it'll spit out the header and footer with a content page in the middle relating to that ID. If there is no ID then it'll include a completely different page all together.

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.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:42 PM   #2
chemicaleyes
UNSTOPPABLE
 
chemicaleyes's Avatar
 
Join Date: Aug 2003
Location: UK :: ICQ# 156068
Posts: 11,569
Bump for ya
__________________
No way as way, No limitation as limitation. AmeriNOC formally PhatServers
chemicaleyes is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:43 PM   #3
Sands
Confirmed User
 
Sands's Avatar
 
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
Errr, use a switch statement.
Sands is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:45 PM   #4
Bro Media - BANNED FOR LIFE
MOBILE PORN: IMOBILEPORN
 
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
PHP Code:
<?php
include("header.php");
if(
$_GET['id'] == true)
{
  if(
file_exists($_GET['id'] . ".php")
  {
    include(
$_GET['id'] . ".php");
  }else{
    include(
"noid.php");
  }
}else{
  include(
"noid.php");
}
include(
"footer.php");
?>
quick and dirty but it should give you alittle help on what you want to do
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:46 PM   #5
Sands
Confirmed User
 
Sands's Avatar
 
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
PHP Code:
<?php
    $id 
$_GET['id'];
    switch (
$id) {
        case 
1:
            include (
'header.php');
            include (
'1.php');
            include (
'footer.php');            
            break;
        case 
2:
            include (
'header.php');
            include (
'1.php');
            include (
'footer.php');            
            break;
        case 
3:
            include (
'header.php');
            include (
'1.php');
            include (
'footer.php');            
            break;
        default:
            include (
'noid.php');
    }
?>
I think this will work.
Sands is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:47 PM   #6
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
Industry Role:
Join Date: Sep 2002
Posts: 10,592
PHP Code:
<?php
$ID
=$_GET['ID'];
include (
'header.php');
switch (
$ID) {
case 
1:
    include (
'1.php');
    break;
case 
2:
    include (
'2.php');
    break;
case 
3:
    include (
'3.php');
    break;
default:
    include (
'noid.php');
}
include (
'footer.php');
?>
__________________

"I'm selflessly supporting the common good, but only coincidentally looking out for No.1."
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:47 PM   #7
jimbona
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');
}
__________________
Thanks
Paul
Thunder-Ball.net - Member
jimbona is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:48 PM   #8
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
Industry Role:
Join Date: Sep 2002
Posts: 10,592
Or here's another method...
PHP Code:
<?php
$ID
=$_GET['ID'];
include (
'header.php');
include (
'$ID.php');
include (
'footer.php');
?>
__________________

"I'm selflessly supporting the common good, but only coincidentally looking out for No.1."
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:50 PM   #9
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
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."
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 01:54 PM   #10
potter
Confirmed User
 
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
Quote:
Originally Posted by jimbona View Post
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');
}
Nice, I like that allowed arrays part.

Thanks a bunch everyone. Going to take these back and try em out on my project. Be back in a little bit.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:01 PM   #11
Bro Media - BANNED FOR LIFE
MOBILE PORN: IMOBILEPORN
 
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
Quote:
Originally Posted by jimbona View Post
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');
}
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:15 PM   #12
potter
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.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:31 PM   #13
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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');
}
?>
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:38 PM   #14
Hotrocket
Confirmed User
 
Hotrocket's Avatar
 
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
Hotrocket is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:44 PM   #15
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
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");?>
I will say, though, that Sands' use of switch is, well, a better abuse of logic than a ton of if/else/elif statements.

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
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:46 PM   #16
GeXus
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
__________________
GeXus is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 02:47 PM   #17
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by GeXus View Post
I don't code for free... but if you want something done right.. hit me up
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.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 03:19 PM   #18
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
Quote:
Originally Posted by Voodoo View Post
Or here's another method...
PHP Code:
<?php
$ID
=$_GET['ID'];
include (
'header.php');
include (
'$ID.php');
include (
'footer.php');
?>
need to put error trapping in if no id is sent.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 03:39 PM   #19
Bro Media - BANNED FOR LIFE
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...
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 03:40 PM   #20
Sands
Confirmed User
 
Sands's Avatar
 
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
Quote:
Originally Posted by GrouchyAdmin View Post
I will say, though, that Sands' use of switch is, well, a better abuse of logic than a ton of if/else/elif statements.
I abuse my logic like a red-headed orphan.
Sands is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 03:46 PM   #21
xentech
Confirmed User
 
xentech's Avatar
 
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";
}

?>
xentech is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 03:48 PM   #22
xentech
Confirmed User
 
xentech's Avatar
 
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.
xentech is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 04:04 PM   #23
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
Quote:
Originally Posted by Voodoo View Post
Or here's another method...
PHP Code:
<?php
$ID
=$_GET['ID'];
include (
'header.php');
include (
'$ID.php');
include (
'footer.php');
?>
Fail.
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 ?
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 04:07 PM   #24
GeXus
Confirmed User
 
Join Date: May 2003
Location: Yo Mommas Pussy
Posts: 3,320
Quote:
Originally Posted by GrouchyAdmin View Post
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.
In my experience, If you do free work, you're wasting your time.
__________________
GeXus is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 04:12 PM   #25
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
Industry Role:
Join Date: Sep 2002
Posts: 10,592
Quote:
Originally Posted by k0nr4d View Post
Fail.
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 ?
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."
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 05:25 PM   #26
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
why not use isset?
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 05:28 PM   #27
Iron Fist
Too lazy to set a custom title
 
Join Date: Dec 2006
Posts: 23,400
Quote:
Originally Posted by Hotrocket View Post
Love watching coders one upping each other with their versions..and then the next...and the next...lol
Yup... see ... don't tell anyone, but if you time it just right and space out requests far enough so no one can piece them together, you could build an entire project for free through here...
Iron Fist is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 05:34 PM   #28
mrkris
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';
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 05:36 PM   #29
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by sharphead View Post
Yup... see ... don't tell anyone, but if you time it just right and space out requests far enough so no one can piece them together, you could build an entire project for free through here...
I don't consider it a bad thing, I consider it an opportunity for a developer to see how other developers approach a problem with a solution.
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 05:43 PM   #30
Sands
Confirmed User
 
Sands's Avatar
 
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
Quote:
Originally Posted by mrkris View Post
I don't consider it a bad thing, I consider it an opportunity for a developer to see how other developers approach a problem with a solution.
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.
Sands is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 05:54 PM   #31
Bro Media - BANNED FOR LIFE
MOBILE PORN: IMOBILEPORN
 
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
Quote:
Originally Posted by Sands View Post
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.
you liked it and you know it!
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 06:10 PM   #32
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by Sands View Post
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.
Remind me to never pee in a urinal next to you
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 06:38 PM   #33
Sands
Confirmed User
 
Sands's Avatar
 
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
Quote:
Originally Posted by mrkris View Post
Remind me to never pee in a urinal next to you
Yeah, wouldn't want you to feel inadequate.
Sands is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 08:23 PM   #34
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by Sands View Post
Yeah, wouldn't want you to feel inadequate.
sad but true
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 08:44 PM   #35
jimbona
Confirmed User
 
Join Date: Jan 2007
Posts: 190
Quote:
Originally Posted by potter View Post
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.
Just tested the code locally and works fine for me, make sure the id you are passing via get is ?ID= and not ?id=

do debugging by testing if the different vars such as $ID are being set correctly.
__________________
Thanks
Paul
Thunder-Ball.net - Member
jimbona is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-20-2008, 09:47 PM   #36
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by mrkris View Post
Remind me to never pee in a urinal next to you
You pee sitting down, so the point is moot.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.