Quick Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Quick Question

Post 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.
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Can we see PHP script that u use ?
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Post 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.
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post 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!");
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Well does it work ?
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Post by Covenant »

Neither work. Any other options?
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

p.s. Im newbie on php, so sorry I cant tell you much
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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']
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Post 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?
Post Reply