FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php and page id - how to?





anakin_skyrunner
I've just begun to learn php and there is something bugging me. I often see php pages, which load content the following way:
index.php?id=16
What does this mean? Is there a single index.php file and the content of a different file (in this case 16) is loaded into this page? Is this advantagous? And: how do I create such id-pages?
I've already googled it and made a search here, but couldn't find any answers... If you could simply tell me how this function is called it would already help me a lot!

Thanks in advance!
Marcuzzo
you can send variables to a php script by using a form
depending on the method...
Code:
<form method="post">
<input type="text" name="inputValue" />
</form>

or
Code:
<form method="get">
<input type="text" name="inputValue" />
</form>


you can use
Code:
$_POST["inputValue"]


or
Code:
$_GET['inputValue']

to fetch the details passed with the form.
to get details directly from the url you can use
Code:
$_REQUEST["value"]



the "id" variable passed to the index.php file you are referring to can be pretty much anything.

check these links for the full details

http://be2.php.net/manual/en/reserved.variables.post.php
http://be2.php.net/manual/en/reserved.variables.get.php
http://be2.php.net/manual/en/reserved.variables.request.php
anakin_skyrunner
Hm, thanks for your answer Marcuzzo but I think you misunderstood me...

There are many websites, I'll just use the one from my school as an example:

http://www.bhak1.at/index.php --> Homepage
http://www.bhak1.at/index.php?id=16 --> still the index.php file, but it shows different content in the content area, the menu and the sidebar remain the same.

How do I do this?

EDIT: I think I just found what I was searching for, php section (index.php?section=index)

Thanks anyway Smile
Diablosblizz
Well, that's pretty easy.

Code:

<?php
switch($_GET['page']) { // change page to something like id if you'd like - basically it'll be index.php?WHATEVER=CASE

default:
//this is the default page users will see - so if they go to index.php they will see what's in this case.
break; // always remember to break

case 'whatever':
// if a user goes to index.php?page=whatever they'll see what's in this case.
break;

}
?>


I think that's what you're looking for, I hope so!
sonam
The sistem is quite simple. We can say you have one index.php where you want to include different content independent of id. On the top you are check is there some id in url or not. And then you need to get right content.
Code:
<?php
$id = @$_GET['id']; // @ will stop error if id is empty

if(empty($id) || $id > 3) { // if id is empty or bigger then 3
   include_once("homepage.php);
} else {
   switch ($id) {
       case 1:  include_once("page1.php"); break;
       case 2:  include_once("page2.php"); break;
       case 3:  include_once("page3.php"); break;
   }
}
?>


Homepage.php, page1.php, etc. are in most situation the content of one div or table. HTML construction and style are comming from index.php what is main page.

Sonam
anakin_skyrunner
Thanks Diablosblizz and sonam, I'm going to have a look at it and let you know whether it helped me or not Cool
sonam
You are welcome. If you need any other help post here.

Sonam
anakin_skyrunner
Thank you again, sonam, I was exactly searching for the script you mentioned in your post. I didn't even had to adapt it much, I only changed the script so an error message is shown when the id is bigger than 3 (in this case, I have more pages waiting Wink ).

@ Diablosblizz: I think you meant the same thing, but it was more complicated, but anyway thanks for your script-offer =)
sonam
It is great if you find good solution. Actualy I don't like error messages because some users are afraid when is comming out something what they don't recognise like site page. Instead I am include homepage because wrong id can come only if someone type bigger id in url bar. If I need more pages then three I just type bigger nuber and more including. Also, in most situation when I using number I am check is this nuber or letter because some eviluser can write in url bar something like: yoursite/index.php?id=jkasdfu8ufasd to see how is protect your site and php scripts.

Sonam
rvec
huh?
I don't see why it has to be made that complicated.
Code:

$page = isset($_GET['page'])?$_GET['page']:'';
switch($page){
case '':
//homepage
break;
case 1:
//page 1
break;
case 2:
//page 2
break;
default:
//error page or homepage
break;
}

That way there's nothing an evil user can do, you'll have an error page if you want and the user will see the homepage by default.
anakin_skyrunner
rvec wrote:
huh?
I don't see why it has to be made that complicated.
Code:

$page = isset($_GET['page'])?$_GET['page']:'';
switch($page){
case '':
//homepage
break;
case 1:
//page 1
break;
case 2:
//page 2
break;
default:
//error page or homepage
break;
}

That way there's nothing an evil user can do, you'll have an error page if you want and the user will see the homepage by default.

Well, I'm fine with what I have right now. And all an "evil" user will see if he enters hilfe.php?id=kasdfu8ufasd is the page without the content div. If this is his aim, well, congratulations. And all other users will just click the links I provide.
Perhaps I'll have a go at your code, thanks anyway, but as I said, it's functioning and that's all I need =)
sonam
rvec wrote:
huh?
I don't see why it has to be made that complicated.


Because my mind think complicated. Brick wall

Sonam
halilibo
Page id is used to hide the page name, or to create artistic page names (In my opinion.)

You can use ?pageid=##, ?pagename=******, ?load=somepage, ?innerpage=mailme etc.

The usage does not matter anything. Only the address bar looks nicer than complex addresses.

As i said before you can use anything you want .

I, personnally, use ?pn=about for about.php, pn as page name.

and the function is : include("pagename.php");

makes your main page, include the other page as it was already a part of the main page.

For Example:

Main Page:

<html>
<?include($_GET["pn"].".php");?>
<body>
</body>
</html>

Title Page:

<title>This is the title of the page.</title>


and
mainpage.php?pn=titile
looks like in any browser:

<html>
<title>This is the title of the page.</title>
<body>
</body>
</html>
anakin_skyrunner
@rvec: I have no implemented your solution as it suited a different page better than sonam's and I like having the same scripts on all pages, it's already enough confusing^^

Thank you!

And thanks again to all others who tried to help me out here Wink
jmraker
It would seem that parameter is usually a key to a database record where id=16 is to use the 16th record and when no id is in the url, it lists records


Code:
... header ....
if(isset($_GET['id']))
  printDBRecord($_GET['id']);
else
  printDBIndex();
... footer ...
Related topics
E-Cards with PHP & MySQL
HTTP AUTH with PHP and mySQL
IIS, PHP and Tomcat not cooperating!
Never Mind Problem Resolved
PHP Page
How to Make A PHP Portal.
Creating a page with php
Developing a Login System with PHP and MySQL
help - download pop up on php page
how do i make a window/iframe in a table within php page..??
php page flickering, maybe caused by flash item
PHP page can't be loaded
PHP page turning problem
How to make a php page act differently
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.