User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 373,527 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,760 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 4974 | Replies: 8
Reply
Join Date: Nov 2004
Location: Milwaukee, WI
Posts: 62
Reputation: 2ndPlatform is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
2ndPlatform's Avatar
2ndPlatform 2ndPlatform is offline Offline
Junior Poster in Training

Variables in the URL - and how to get them

  #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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Milwaukee, WI
Posts: 62
Reputation: 2ndPlatform is an unknown quantity at this point 
Rep Power: 4
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

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

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

  #3  
Feb 7th, 2007
how?

please tell
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 5
Solved Threads: 46
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

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

  #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)
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jan 2007
Posts: 6
Reputation: melefire is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
melefire melefire is offline Offline
Newbie Poster

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

  #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  
Join Date: Sep 2006
Location: Canada
Posts: 55
Reputation: GliderPilot is an unknown quantity at this point 
Rep Power: 2
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

  #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:

<?php
 
$id = $_GET['id'];
 
echo $id;
 
?>

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

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

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

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

  #8  
Feb 21st, 2007
You can do it only with php.
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 5
Solved Threads: 46
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

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

  #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.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb HTML and CSS Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the HTML and CSS Forum

All times are GMT -4. The time now is 6:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC