/    Sign up×
Community /Pin to ProfileBookmark

include and get?

hey im pretty new to php but i’d like to slowly ease my website into php…

i used the “include” function to make my website load a menu above the page but i want it to involve the “get” function so the url will be like “http://www.yoursite.com/index.php?page=index” or somthing like that ?

p.s. i dont want the extentions show if possible ?

Cheers in advance ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SyCoJan 29.2009 — Just to clarify GET isn't a function it's a variable, or more correctly a superglobal array. It's usually written GET in uppercase to distinguish it from a verb eg 'do you get this'?

So first to show you how not to do it, this is bad code

[code=php]include $_GET['page'];[/code]

because anyone can change the GET values and access any file, like you configurations perhaps or passwords. So you can only allow certain things to be accepted using the switch().
[code=php]switch($_GET['page']){
case 'index':
include 'index.php';
break;
case 'contact':
include 'contact.php';
break;
case 'gallery':
include 'pictures.php';//can be anything
break;
default:
'error.php';
}
[/code]

If someone tries to enter something not in the switch it will default to your error page (or index or whatever you put in default)

Of course you have to update this switch every time you add a new page. You can avoid this by securing the GET variables using an md5() hash but that might be a little ahead of you for right now.
Copy linkTweet thisAlerts:
@acidauthorJan 29.2009 — cheers works great ?

<3
Copy linkTweet thisAlerts:
@SyCoJan 29.2009 — You're welcome!
Copy linkTweet thisAlerts:
@kloon_zaJan 30.2009 — [code=php]
include $_GET['page'].'.php';
[/code]
Copy linkTweet thisAlerts:
@MigJan 30.2009 — [code=php]
include $_GET['page'].'.php';
[/code]
[/QUOTE]

No. SyCo [I]just [/I]said why not to do this. :rolleyes:
×

Success!

Help @acid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...