943,490 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Dec 26th, 2004
0

Variables in the URL - and how to get them

Expand Post »
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!
Similar Threads
Reputation Points: 15
Solved Threads: 0
Junior Poster in Training
2ndPlatform is offline Offline
61 posts
since Nov 2004
Dec 26th, 2004
0

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

Nevermind - I got it.
Reputation Points: 15
Solved Threads: 0
Junior Poster in Training
2ndPlatform is offline Offline
61 posts
since Nov 2004
Feb 7th, 2007
0

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

how?

please tell
Reputation Points: 10
Solved Threads: 0
Newbie Poster
melefire is offline Offline
6 posts
since Jan 2007
Feb 7th, 2007
0

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

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)
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Feb 12th, 2007
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
melefire is offline Offline
6 posts
since Jan 2007
Feb 12th, 2007
0

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

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
Reputation Points: 8
Solved Threads: 2
Junior Poster in Training
GliderPilot is offline Offline
57 posts
since Sep 2006
Feb 13th, 2007
0

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

cool, thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
melefire is offline Offline
6 posts
since Jan 2007
Feb 21st, 2007
0

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

You can do it only with php.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
X123 is offline Offline
4 posts
since Feb 2007
Feb 21st, 2007
0

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

Quote ...
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.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
May 9th, 2010
0
Re: Variables in the URL - and how to get them
Hi,

I have a website say www.test.com.
How do i give the variables linked URL to external website in PHP.

For instance, i have a variable $xyz in php code. $xyz indicates a url say www.yahoo.com, then it opens the page as www.xyz.com/www.yahoo.com

My code is as below:

<a href="$xyz">test</a>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
maddiv is offline Offline
2 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Layout Issue
Next Thread in HTML and CSS Forum Timeline: web dev notes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC