Page 1 of 1
[Solved] Webpage URLs that end in ".php?blah=5"
Posted: Mon Jun 20, 2005 12:10 am
by Jeefo
Of course that URL was an example, but I was wondering if someone can explain to me how to make webpages that end like that. (And also how to create links to those kind of pages.)
Thank you!
Posted: Mon Jun 20, 2005 12:11 am
by Revan
Huh? What do you mean..?
$_GET["GET_DATA"] = bleh.php?get_data=data
make a form
Posted: Mon Jun 20, 2005 2:36 am
by vulcan_
you can create that kind of URL in code, but the normal way to see it is the response to a form being sent back from a browser. So which thing are you trying to do?
Re: make a form
Posted: Mon Jun 20, 2005 4:09 am
by Jeefo
vulcan_ wrote:So which thing are you trying to do?
Let's say my website has a shop. My URL is
http://www.mydomain.com. So I click on the shop link, which goes to
http://www.mydomain.com/items.php. But my shop is divided into different genres of items. I click one genre, and it goes to
http://www.mydomain.com/items.php?=2. But if I go to another genre, it goes to
http://www.mydomain.com/items.php?=3. I did my best explaining. Hope that helped.

Try this one
Posted: Mon Jun 20, 2005 5:40 am
by namitjung
Well i m putting the code.
i don't know i should use this tag or not and if it is not acceptable please let me know. i will edit my post
let's suppose you have three files
1.test.html
2.test1.html
3.test1.html
in test.html write this code
<a href="test.php?id=2">Click me </a>
in test1.html write this code
<a href="test.php?id=3">Click me </a>
in test.php do something to use this value.
When you pass this value ur passing the value from client to browser and the server will use get method to get this value.if You are using forms then server will use post method.
I hope this will help
Posted: Mon Jun 20, 2005 1:39 pm
by Skara
file1.php
Code: Select all
<a href="e;file2.php?code=1"e;>One</a>
<a href="e;file2.php?code=2"e;>Two</a>
<a href="e;file2.php?code=3"e;>Three</a>
file2.php [newb version--easier to explain]
Code: Select all
<?php
if ($_GET['code'] == 1) {
// do this
}
elseif ($_GET['code'] == 2) {
// do this
}
elseif ($_GET['code'] == 3) {
// do this
}
else {
// do this
}
?>
file2.php [the way it should be]
Code: Select all
<?php
if (isset($_GET['code'])) {
switch $_GET['code'] {
case 1:
// do whatever
break;
case 2:
// do whatever
break;
case 3:
// do whatever
break;
default:
// a code was entered, but it wasn't 1, 2 or 3.
}
}
else {
// default display
}
?>
Or, you might want to read a file based on what was entered.
Code: Select all
<?php
$valid = range(1,3); // same as array(1,2,3);
if (isset($_GET['code']) && in_array($_GET['code'],$valid)) {
require $_GET['code'].'.php';
}
else {
// default page
}
?>
It's basically used so you don't have to repeat yourself or when you submit a form. Most forms will be post, though (you don't see it in the URL).
Take this page, for example. "viewtopic.php?t=34638"
This is viewtopic.php reading thread 34638. Without the variable at the end, there would have to be a physical page for each thread here (e.g. viewtopic34638.php).
Hope that helps.
Posted: Mon Jun 20, 2005 1:45 pm
by Burrito
Skara wrote:
Most forms will be post, though (you don't see it in the URL).
for your situation I'd avoid using POST however...for shopping sites et al, I find it better practice to use URL vars so one of your visitors could find a product, then send a link to one of their friends etc so they can see what the item is w/o having to drill any deeper into the site.
it makes for a much better experience for visitors to be able to just copy and paste a url to others or even save it for later viewing.