LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2007, 04:52 PM   #1
GavB
Member
 
Registered: Nov 2006
Posts: 54

Rep: Reputation: 15
PHP: variables in url


Might be a bit of a strange question but I know it can be done because I've done it before and just can't work it out again.

Basically when you have a variable in a url like this:

yourdomain.com/file.php?this=something

To print the value of $this you do

print $_GET['this'];


but I am trying to work out how to set a variable like this

yourdomain.com/file.php?something

print $_GET['something here?'];


I know I've explained it very badly haha but maybe someone will know what I mean

thanks
 
Old 04-22-2007, 05:16 PM   #2
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
Try this:

Code:
while(list($varname, $val) = each($HTTP_GET_VARS))
{
echo "$varname$val";
}
I'm not sure if this is the best way to do this. If you use spaces, the %20's come up as '_'. You can of course parse it out and display the spaces.

vxc

Last edited by vxc69; 04-22-2007 at 05:21 PM.
 
Old 04-22-2007, 05:46 PM   #3
derzok
Member
 
Registered: Aug 2004
Location: Ohio
Distribution: Debian, Slackware
Posts: 58

Rep: Reputation: 15
I usually just do:

if($isset($_GET['something'])) {
print $_GET['something'];
}
 
Old 04-22-2007, 05:53 PM   #4
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
Quote:
Originally Posted by derzok
I usually just do:

if($isset($_GET['something'])) {
print $_GET['something'];
}
That will only print whatever is after something=. I think GavB is looking for something that will print everything after file.php?.

BTW isset is not a variable.


vxc
 
Old 04-22-2007, 07:02 PM   #5
GavB
Member
 
Registered: Nov 2006
Posts: 54

Original Poster
Rep: Reputation: 15
I knew I hadn't explained it too well haha

What I want to do is instead of having URLs like this

www.domain.com/index.php?page=contact

I want them to look like this

www.domain.com/index.php?contact

(or even www.domain.com/?contact)



I'm 99% sure it can be done
 
Old 04-22-2007, 07:17 PM   #6
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
So from your latest example i take it that contact is the variable. So you should be able to do this using what I mentioned.

User goes to link www.yourdomain.com?contact, then $varname (in my code example) will contain contact.

EDIT: That is assuming that index.php has the code. If it's another page,let say testicles.php, then you can do the same with www.yourdomain.com/testicles?contact.

If this is not what you're looking for, then I still don't get your problem. Sorry.


So hope this helps,
vxc

Last edited by vxc69; 05-14-2007 at 07:39 PM.
 
Old 04-24-2007, 03:20 PM   #7
GavB
Member
 
Registered: Nov 2006
Posts: 54

Original Poster
Rep: Reputation: 15
Thanks for that Vxc it works great, but I'm sure there is another simpler way. I'll update this post if I find it, but your way works great for what I need
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 10:44 AM
PHP passing variables from url to ... latino Programming 3 08-31-2005 06:35 PM
Pass multiple URL variables PHP agallant Programming 3 10-21-2004 07:29 PM
url php variables aren't being recognized/used thrice Linux - Software 6 08-04-2004 05:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration