Variables in the URL - and how to get them

Reply

Join Date: Nov 2004
Posts: 62
Reputation: 2ndPlatform is an unknown quantity at this point 
Solved Threads: 0
2ndPlatform's Avatar
2ndPlatform 2ndPlatform is offline Offline
Junior Poster in Training

Variables in the URL - and how to get them

 
0
  #1
Dec 26th, 2004
Morning everyone --

Can anyone help me with what is probably very simple?

I have a page where I want to get a variable from the URL and display it... so if my url is http://www.mysite.com/page.html?variable=hi

I want to get that "hi" out of there and print it out to the page.

Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 62
Reputation: 2ndPlatform is an unknown quantity at this point 
Solved Threads: 0
2ndPlatform's Avatar
2ndPlatform 2ndPlatform is offline Offline
Junior Poster in Training

Re: Variables in the URL - and how to get them

 
0
  #2
Dec 26th, 2004
Nevermind - I got it.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 6
Reputation: melefire is an unknown quantity at this point 
Solved Threads: 0
melefire melefire is offline Offline
Newbie Poster

Re: Variables in the URL - and how to get them

 
0
  #3
Feb 7th, 2007
how?

please tell
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Variables in the URL - and how to get them

 
0
  #4
Feb 7th, 2007
It depends. It can be done in Javascript or using a serverside language.

Which would you rather do?

For reference, that part of the URL is called the 'query string'.

Server side langauges often have simplified interfaces to access the 'variables' in a query string. Javascript has no such interface; but it is possible to get reference to the entire URL of a page (address + query string), and to split that down into its component parts.

An example is here:

http://www.activsoftware.com/code_sa..._in_JavaScript

(That's a somewhat wasteful procedure if you want to repeatadly get at the different variables in a query string; but its not too bad if you have alot of potential variables and are only interested in a few of them)
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 6
Reputation: melefire is an unknown quantity at this point 
Solved Threads: 0
melefire melefire is offline Offline
Newbie Poster

Re: Variables in the URL - and how to get them

 
0
  #5
Feb 12th, 2007
Um, the java script lokos hard, could you please tell me how i would retrive the variable text, just the text, onto a page using php? or another server side language
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 57
Reputation: GliderPilot is an unknown quantity at this point 
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: Variables in the URL - and how to get them

 
0
  #6
Feb 12th, 2007
With PHP you simple use the
$_GET['variable'];

Variable. For example if you had a link

www.daniweb.com/fakeurl.html?id=12

Your PHP would be:

HTML and CSS Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $id = $_GET['id'];
  4.  
  5. echo $id;
  6.  
  7. ?>

this would output 12
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 6
Reputation: melefire is an unknown quantity at this point 
Solved Threads: 0
melefire melefire is offline Offline
Newbie Poster

Re: Variables in the URL - and how to get them

 
0
  #7
Feb 13th, 2007
cool, thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 4
Reputation: X123 is an unknown quantity at this point 
Solved Threads: 0
X123 X123 is offline Offline
Newbie Poster

Re: Variables in the URL - and how to get them

 
0
  #8
Feb 21st, 2007
You can do it only with php.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Variables in the URL - and how to get them

 
0
  #9
Feb 21st, 2007
You can do it only with php.
You can do it with any serverside language, and any client side script should be able to get the query string indirectly from the page URL.

PHP does it through Zend, which does it through C++; and it's delivered into an application's environment by the server software; so clearly, you can access it using other means than only PHP.

I'm sure you meant something different; and I don't mean to bite your head off; but there's a full wealth of ways in which you can access that data, PHP is one way to do it.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC