Page 1 of 1
PHP in url?
Posted: Fri Jun 21, 2002 5:57 pm
by Dale
Hi,
I'm only 14 and im trying to earn PHP now one thing thats bugging me is how you make a files name like this:
http://www.beyondunreal.com/daedalus/ar ... php?show=5
Things that have like
.php?show=5 or
.php?id=15 ect... how do i do that?
Posted: Fri Jun 21, 2002 6:03 pm
by enygma
everything after the ? is called the GET string.
PHP takes this and sets variables according to what it finds.
For example:
http://www.beyondunreal.com/daedalus/ar ... php?show=5
If you went to that page and it contained:
<?php
echo "Show equals ".$show;
?>
then you would see on the page:
"Show equals 5"
pretty simple, huh?
Posted: Fri Jun 21, 2002 6:06 pm
by Dale
Still dont get ya....
Right what i wanna do is have a page called index.php then i want to add a link on it that links to index.php?map=1 (which will be lets say CTF-Php) what do i stick in the index.php file?
Posted: Fri Jun 21, 2002 6:18 pm
by enygma
just like a normal link....
<a href="index.php?id=1">link text here</a>
Posted: Fri Jun 21, 2002 6:19 pm
by Dale
yeah i know how to do a link but how do i make a page such as index.php?=map1 ??????
Posted: Fri Jun 21, 2002 6:25 pm
by enygma
I guess I'm not following....the "page.php?id=5" is just the URL for the page...not the page itself.
Describe what you want the page to do based on the URL and maybe I can help more.
Posted: Fri Jun 21, 2002 6:30 pm
by Dale
Ok sorry i cant really like explain it good but here goes:
On my site i want the main page of my site to be
index.php then in the menu i will put a link
<a href="http://www.mysite.com/index.php?=map1">Maps</a> but what i want to know is how do i created a page with a file name ending
index.php?=map1
Posted: Fri Jun 21, 2002 6:39 pm
by enygma
and that's what i was telling you in the first place...you dont make another file with that name.
the part after the ? is a GET string. PHP sees that and turns it into variables for you.
so if the URL is "index.php?id=5" then, when you load that URL, the index.php page is the same, except it now has a variable of $id set to a value of "5"
It's all the same page.
Posted: Fri Jun 21, 2002 6:49 pm
by Dale
But a while ago on another forum i posted on they said something about these things:
Code: Select all
<?
include('_header.php');
if($page==1)
{
?>
blablablabla
<a href=view.php?page=2>Next Page</a>
<?
}
if($page==2)
{
etc.....
}
Posted: Fri Jun 21, 2002 7:00 pm
by protokol
the part after the ? is a variable .. if you have:
http://somewhere/index.php?theme=2
then PHP says .. "A variable name $theme was passed to the URL and it contains the value '2'"
inside your script you would say ...
Code: Select all
<?php
switch ($theme) {
case 0:
echo "You are using theme 0";
break;
case 1:
echo "You are using theme 1";
break;
case 2:
echo "You are using theme 2";
break;
default:
echo "You are using the default theme";
break;
}
?>
So whatever number is passed .. index.php?theme=1 or index.php?theme=2 or whatever, then the variable and the value of that variable are set and you can deal with them in your code
--
protokol
Posted: Fri Jun 21, 2002 7:03 pm
by Dale
Protocol Your excellent!!!!!!!!!!!!!!!!!!!!111111111111111
Thats just what i wanted and thanks to all of you for helping me

Posted: Fri Jun 21, 2002 7:04 pm
by protokol
good luck with the rest of your coding

Posted: Fri Jun 21, 2002 7:17 pm
by Dale
1 last question....
How do i do a link in PHP cuz i keep getting a parse error when i do them
Posted: Fri Jun 21, 2002 7:24 pm
by protokol
if you are inside double quotes, and wish to print a double quote explicitly, then you use \"
Code: Select all
echo "<a href="index.php?theme=1">Theme #1</a>";
Posted: Fri Jun 21, 2002 7:25 pm
by Dale
Thx
