00:00
00:00
Newgrounds Background Image Theme

novaruah just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php:page Id

15,587 Views | 24 Replies
New Topic Respond to this Topic

Php:page Id 2006-06-16 08:42:12


PHP Main

Have you even seen a pager where its has index.php?id= ? wel; in this tutorial i will show you how to make it so instead of typing in somesite.com/somepage.html into somesite.com/index.php?id=2 so it can be more secure if its a page yo dont want them to know the adress for

Now enough about the infromation your going like WTF about heres the tutorial

The Code
i will explain it after

1. Create a new PHP file and call it index.php

no inside that inject this inbetween the Doctype and html paremeters

<?php
switch($id) {
default:
include('index.html');
break; case "2":
include('games.html');
break; case "3":
include('support.htmll');
break; case "4":
include('contact.html');
break; case "5":
include('page.html');
break; case "6":
include('page.html');
break; case "7":
include('page.html');
break; case "8":
include('page.html');
}
?>

The Explaination

switch($id) {
default:
include('index.html'); Meants that when index.php first loads this is the file that it will load and if you ever want to link back to it its id is 1

break; case "2":
include('games.html'); id=2 loads games.html

... and so on and so on

Linking

Now to link to those pages add this to its link

index.php?id=X
Replacing X with id number or Letter

Response to Php:page Id 2006-06-16 08:46:12


Excellent tutorial sir.

Even though I've never coded a line of PHP in my life, I'm feeling ever so slightly intrigued. I've got two exams left, so I might start giving PHP a go during the break :D

Response to Php:page Id 2006-06-16 11:51:54


Hah, pretty usefull acctualy :)

Response to Php:page Id 2006-06-16 12:10:53


Great tutoral!


-Disregard females (fuck bitches)

-Acquire currency (get money)

-Ignite cannabis frequently (smoke sum with your homies)

BBS Signature

Response to Php:page Id 2006-06-16 13:20:18


You can also use includes!

Example:

Index.php
<?php
if (!isset($_GET['id'])) {
//The main page
include("main.php");
}
else {
$page = $_GET['id'];
include($page.".php");
}
?>
You would need to had pages in the same directory.


Psychotropiaaaaaa!

BBS Signature

Response to Php:page Id 2006-06-17 07:48:07


1 You did not mention databases at all
2 You are as good at security as I am at quatium physics.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Response to Php:page Id 2006-06-17 08:14:37


This usage isn't useful at all. The reason for using IDs is normally related to database IDs you fetch with (SELECT * FROM table WHERE id = $id).

Response to Php:page Id 2006-06-17 10:40:56


At 6/17/06 07:48 AM, henke37 wrote: 1 You did not mention databases at all
2 You are as good at security as I am at quatium physics.

ummm i don't think it's intented to be used with a DB.


[PHP: Main]-[AVGN Club]

"You know a dame is classy when she got some jiggle in her assy." - Unknown

BBS Signature

Response to Php:page Id 2006-06-17 11:45:27


At 6/17/06 07:58 AM, -cherries- wrote: Answer now!

GEEK! But seriously, the answer's 37.

Response to Php:page Id 2006-06-17 12:12:24


i forgot to say that many time i've asked about this subject and never got answers but now i know how to do it.

dawsome. toally dawsome - Crackhead Bob


[PHP: Main]-[AVGN Club]

"You know a dame is classy when she got some jiggle in her assy." - Unknown

BBS Signature

Response to Php:page Id 2006-06-17 13:05:13


At 6/17/06 07:48 AM, henke37 wrote: 1 You did not mention databases at all
2 You are as good at security as I am at quatium physics.

1 Maby cuz you dont need to use databases for this.. dumbass :)
2 Maby cuz you dont use databases for this since you dont store your pages in a DB... dumbass :)

Lol where the fuck did you "learn" php & MySQL??

Response to Php:page Id 2006-06-17 13:51:17


my guess would be the Dumbass University (go Dumbass Donkeys!)


[PHP: Main]-[AVGN Club]

"You know a dame is classy when she got some jiggle in her assy." - Unknown

BBS Signature

Response to Php:page Id 2006-06-22 23:18:40


bump

Response to Php:page Id 2006-06-22 23:31:54


At 6/17/06 01:51 PM, JimmyDallas wrote: my guess would be the Dumbass University (go Dumbass Donkeys!)

no, it would be the Dum Donkee's

(spelling error on perpose idiots)

oh yea, and nice tutorial. Always wondered how you do that.


Hello, from the past!

[ PHP: Main ]

BBS Signature

Response to Php:page Id 2006-06-23 15:55:51


At 6/22/06 11:18 PM, ElementalFlash wrote: bump

Well, it is a decent tutorial. It has minimal use but I know sometimes people just want the "advanced" look as if they're coding in a dynamic language. You should explain what that approach is typically used for.

Rarely is it used for simple include statements. It would make more sense to use something like page.php?module=HomePage to include files to display. Using a numerical value for a textual file name doesn't make a whole lot of sense.

As someone else said, I would explain and encourage them to only use this approach when necessary. In my experience, avoid URL variables if possible. It only gives the user more power than you intended in most cases.

Response to Php:page Id 2007-07-26 13:46:40


<?php
switch($id) {
default:
include('index.html');
break; case "2":
include('games.html');
break; case "3":
include('support.htmll');
break; case "4":
include('contact.html');
break; case "5":
include('page.html');
break; case "6":
include('page.html');
break; case "7":
include('page.html');
break; case "8":
include('page.html');
}
?>

The problem with this code is that you cannot link to another PHP file. For instance this following code, would result in your site loading as a simple white screen.

<?php
switch($id) {
default:
include('index.php');
break; case "2":
include('games.php');
break; case "3":
include('support.php');
break; case "4":
include('contact.php');
break; case "5":
include('page.php');
break; case "6":
include('page.php');
break; case "7":
include('page.php');
break; case "8":
include('page.php');
}
?>

But, If you can find a version of the code that would allow me to export the link as the .PHP file, that would be great.

Also, I tried redirecting the page (ex. I put a redirect script in page.html so that it would move me to page.php,) however, the above script runs the redirect script, and my page moves w/out me clicking a link.


.

BBS Signature

Response to Php:page Id 2007-07-26 13:53:22


and I would declare it as?


.

BBS Signature

Response to Php:page Id 2007-07-26 13:53:53


At 7/26/07 01:49 PM, cherries wrote: The example in the tutorial actually won't work.
In the switch statement you're doing: switch ( $id ) {
but you haven't declared the $id variable yet.

I can't believe no one has pointed that out yet... An awful lot of people must have register_globals on which is a case in which this would work.

Response to Php:page Id 2007-07-26 13:54:57


At 7/26/07 01:53 PM, Migashi wrote: and I would declare it as?

$id = $_GET['id'];

Response to Php:page Id 2007-07-26 13:55:19


At 7/26/07 01:54 PM, DFox wrote:
At 7/26/07 01:53 PM, Migashi wrote: and I would declare it as?
$id = $_GET['id'];

And thats it?


.

BBS Signature

Response to Php:page Id 2007-07-26 13:56:34


At 7/26/07 01:55 PM, Migashi wrote: And thats it?

Yeah just put that at the top of the script he showed in the first post.

Response to Php:page Id 2007-07-26 13:57:36


At 7/26/07 01:56 PM, DFox wrote:
Yeah just put that at the top of the script he showed in the first post.

Put it in the top like this?

<?php
switch($id) { $id = $_GET['id'];
default:
include('rmenu.php');
break; case "2":
include('index.php');
}
?>


.

BBS Signature

Response to Php:page Id 2007-07-26 13:58:50


At 7/26/07 01:57 PM, Migashi wrote:
At 7/26/07 01:56 PM, DFox wrote:
Yeah just put that at the top of the script he showed in the first post.
Put it in the top like this?

No, that's not the top.

$id = $_GET['id'];
switch($id) {
default:
include('rmenu.php');
break; case "2":
include('index.php');
}

Response to Php:page Id 2007-07-26 14:09:28


At 7/26/07 01:58 PM, DFox wrote:
At 7/26/07 01:57 PM, Migashi wrote:
At 7/26/07 01:56 PM, DFox wrote:
Yeah just put that at the top of the script he showed in the first post.
Put it in the top like this?
No, that's not the top.

$id = $_GET['id'];
switch($id) {
default:
include('rmenu.php');
break; case "2":
include('index.php');
}
At 7/26/07 01:58 PM, DFox wrote:
At 7/26/07 01:57 PM, Migashi wrote:
At 7/26/07 01:56 PM, DFox wrote:
Yeah just put that at the top of the script he showed in the first post.
Put it in the top like this?
No, that's not the top.

$id = $_GET['id'];
switch($id) {
default:
include('rmenu.php');
break; case "2":
include('index.php');
}

That makes "break; case "2": and proberally 3 and 4, and up, act as a PHP include and actually insert the page into the page I want these links

Response to Php:page Id 2007-07-26 14:14:07


That makes "break; case "2": and proberally 3 and 4, and up, act as a PHP include and actually insert the page into the page I want these links

Is there any way around this?