Forum Topic: Php:page Id

(1,888 views • 28 replies)

This topic is 1 page long.

<< < > >>
None

keifer121

Reply To Post Reply & Quote

Posted at: 6/16/06 08:42 AM

keifer121 EVIL LEVEL 07

Sign-Up: 08/31/05

Posts: 400

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


None

jarrydn

Reply To Post Reply & Quote

Posted at: 6/16/06 08:46 AM

jarrydn FAB LEVEL 08

Sign-Up: 07/15/02

Posts: 4,616

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


None

seel

Reply To Post Reply & Quote

Posted at: 6/16/06 11:51 AM

seel FAB LEVEL 19

Sign-Up: 06/27/05

Posts: 2,196

Hah, pretty usefull acctualy :)


None

eWhabs

Reply To Post Reply & Quote

Posted at: 6/16/06 12:10 PM

eWhabs DARK LEVEL 13

Sign-Up: 05/04/06

Posts: 987

Great tutoral!

yo... yeah.

BBS Signature

None

Absorb

Reply To Post Reply & Quote

Posted at: 6/16/06 01:20 PM

Absorb EVIL LEVEL 11

Sign-Up: 09/12/05

Posts: 323

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.

hey, is this a sig?


None

henke37

Reply To Post Reply & Quote

Posted at: 6/17/06 07:48 AM

henke37 NEUTRAL LEVEL 16

Sign-Up: 09/10/04

Posts: 2,627

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

Move on to ActionScript 3! And please, drop the mysql PHP extension, it's so stale that it lacks features that is no longer considered new! Go mysqli or pdo instead.


None

cherries

Reply To Post Reply & Quote

Posted at: 6/17/06 07:58 AM

cherries LIGHT LEVEL 18

Sign-Up: 06/07/05

Posts: 4,561

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.

How good are you at quantum physics?

Define the annihilation and creation operators for the simple harmonic oscillator in one dimension, using either notation A and A+ (G3, p112, G2 p131) or a and a+ (L4 p193, L3 p201):
a) Do G3 problem 11, p118 (not in G2). This problem can usefully be preceded by G3, problems 5-6, and the definition of the unit operator in problem 7.
b) Use these problem(s) as a means of clarifying your notes on the SHO, and submit a short summary of these notes for assessment. Include in your discussion the derivation of how you find the ground state wave function of the SHO, including normalization, by an operator method.

Answer now!


None

GalactiGames

Reply To Post Reply & Quote

Posted at: 6/17/06 08:14 AM

GalactiGames NEUTRAL LEVEL 03

Sign-Up: 05/20/06

Posts: 140

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


None

patheticcockroach

Reply To Post Reply & Quote

Posted at: 6/17/06 10:09 AM

patheticcockroach LIGHT LEVEL 30

Sign-Up: 07/01/03

Posts: 473

At 6/17/06 07:58 AM, -cherries- wrote:
At 6/17/06 07:48 AM, henke37 wrote: 2 You are as good at security as I am at quatium physics.
How good are you at quantum physics?
[chinese-like stuff]

You are as good at humour as I am at quantium physics... :D

At 6/17/06 08:14 AM, GalactiGames wrote: 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).

Yup, that's how I use this on my site. I get the id, which loads a page called id.php + informations stored in a table with the same id. And don't forget to clean the data, for instance use intval($_GET["id"]).


None

JimmyDallas

Reply To Post Reply & Quote

Posted at: 6/17/06 10:40 AM

JimmyDallas NEUTRAL LEVEL 30

Sign-Up: 05/17/03

Posts: 1,034

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]
"Well, chaos is a dish best served at random but never after 9 pm." - Me

BBS Signature

None

Cybex

Reply To Post Reply & Quote

Posted at: 6/17/06 11:45 AM

Cybex NEUTRAL LEVEL 20

Sign-Up: 03/04/05

Posts: 7,744

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

GEEK! But seriously, the answer's 37.


None

JimmyDallas

Reply To Post Reply & Quote

Posted at: 6/17/06 12:12 PM

JimmyDallas NEUTRAL LEVEL 30

Sign-Up: 05/17/03

Posts: 1,034

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]
"Well, chaos is a dish best served at random but never after 9 pm." - Me

BBS Signature

None

seel

Reply To Post Reply & Quote

Posted at: 6/17/06 01:05 PM

seel FAB LEVEL 19

Sign-Up: 06/27/05

Posts: 2,196

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??

None

JimmyDallas

Reply To Post Reply & Quote

Posted at: 6/17/06 01:51 PM

JimmyDallas NEUTRAL LEVEL 30

Sign-Up: 05/17/03

Posts: 1,034

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

[PHP: Main]-[AVGN Club]
"Well, chaos is a dish best served at random but never after 9 pm." - Me

BBS Signature

None

keifer121

Reply To Post Reply & Quote

Posted at: 6/22/06 11:18 PM

keifer121 EVIL LEVEL 07

Sign-Up: 08/31/05

Posts: 400

bump


None

Momo-the-Monkey

Reply To Post Reply & Quote

Posted at: 6/22/06 11:31 PM

Momo-the-Monkey EVIL LEVEL 30

Sign-Up: 10/15/05

Posts: 3,096

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.

You should see Gir's Soundboard...
{ PHP: Main | | Java: Main }
Every Villian Is Lemons

BBS Signature

None

ProxyJock

Reply To Post Reply & Quote

Posted at: 6/23/06 03:55 PM

ProxyJock LIGHT LEVEL 02

Sign-Up: 05/25/05

Posts: 21

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.


None

West-End-Pro

Reply To Post Reply & Quote

Posted at: 8/9/06 11:29 AM

West-End-Pro NEUTRAL LEVEL 23

Sign-Up: 02/15/06

Posts: 2,359

But, how would you do this so that it only includes certain pages; say games and support?


None

Migashi

Reply To Post Reply & Quote

Posted at: 7/26/07 01:46 PM

Migashi DARK LEVEL 09

Sign-Up: 04/24/05

Posts: 1,140

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

Everytime you jack-off, I fuck your woman.

BBS Signature

Kissing

cherries

Reply To Post Reply & Quote

Posted at: 7/26/07 01:49 PM

cherries LIGHT LEVEL 18

Sign-Up: 06/07/05

Posts: 4,561

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.


None

Migashi

Reply To Post Reply & Quote

Posted at: 7/26/07 01:53 PM

Migashi DARK LEVEL 09

Sign-Up: 04/24/05

Posts: 1,140

and I would declare it as?

Everytime you jack-off, I fuck your woman.

BBS Signature

None

DFox

Reply To Post Reply & Quote

Posted at: 7/26/07 01:53 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

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.


None

DFox

Reply To Post Reply & Quote

Posted at: 7/26/07 01:54 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

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

$id = $_GET['id'];


None

Migashi

Reply To Post Reply & Quote

Posted at: 7/26/07 01:55 PM

Migashi DARK LEVEL 09

Sign-Up: 04/24/05

Posts: 1,140

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?

Everytime you jack-off, I fuck your woman.

BBS Signature

None

DFox

Reply To Post Reply & Quote

Posted at: 7/26/07 01:56 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

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.


None

Migashi

Reply To Post Reply & Quote

Posted at: 7/26/07 01:57 PM

Migashi DARK LEVEL 09

Sign-Up: 04/24/05

Posts: 1,140

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');
}
?>

Everytime you jack-off, I fuck your woman.

BBS Signature

None

DFox

Reply To Post Reply & Quote

Posted at: 7/26/07 01:58 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

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');
}


None

migashii

Reply To Post Reply & Quote

Posted at: 7/26/07 02:09 PM

migashii NEUTRAL LEVEL 01

Sign-Up: 09/18/06

Posts: 3

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


None

migashii

Reply To Post Reply & Quote

Posted at: 7/26/07 02:14 PM

migashii NEUTRAL LEVEL 01

Sign-Up: 09/18/06

Posts: 3

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?


All times are Eastern Standard Time (GMT -5) | Current Time: 08:07 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!