Page 1 of 1
Quick Question
Posted: Wed Jan 04, 2006 7:51 pm
by Covenant
How do you make variables work with URL's like
http://mysite.com/index.php?45
as opposed to:
http://mysite.com/index.php?somevariable=45
Because I'd like a shorter url.
Posted: Wed Jan 04, 2006 9:42 pm
by spamyboy
Can we see PHP script that u use ?
Posted: Wed Jan 04, 2006 9:46 pm
by Covenant
It's simple. It's just like...Here's an example...
Code: Select all
if($_GET[food] == "yummy")
{
print ("that's right. food rules.");
exit;
}
print ("you don't like food? then you stink!");
Of course, you'd access this via /page.php?
food=yummy
Instead, I want it to be /page.php?
yummy
I've seen some sites do this but I want to know how it is possible.
Posted: Wed Jan 04, 2006 9:48 pm
by spamyboy
try
Code: Select all
if($_GET[] == "yummy")
{
print ("that's right. food rules.");
exit;
}
print ("you don't like food? then you stink!");
or
Code: Select all
if($_GET[?] == "yummy")
{
print ("that's right. food rules.");
exit;
}
print ("you don't like food? then you stink!");
Posted: Wed Jan 04, 2006 9:55 pm
by spamyboy
Well does it work ?
Posted: Wed Jan 04, 2006 10:00 pm
by Covenant
Neither work. Any other options?
Posted: Wed Jan 04, 2006 10:02 pm
by spamyboy
p.s. Im newbie on php, so sorry I cant tell you much
Posted: Wed Jan 04, 2006 10:07 pm
by spamyboy
Nut i know this
if you only want index.php?yummy , then you need to use isset() and key() on the $_GET array
Posted: Wed Jan 04, 2006 10:08 pm
by timvw
The easiest (imho) is to use mod_rewrite (the forum has a couple of nice threads on this topic, so use the search button to find out more about it).
Another possiblity is to look at the value of $_SERVER['QUERY_STRING']
Posted: Wed Jan 04, 2006 10:16 pm
by Covenant
I did $_SERVER['QUERY_STRING'].
So I'm just doing echo($_SERVER['QUERY_STRING']);
Can you explain to me why you can't do ?0, and ?1 ? Are there any other limitations? Would this be the best, and easiest way for me to do this?