| | |
Variables in the URL - and how to get them
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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!
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!
Web Design in Wisconsin : Milwaukee Web Design : Second Platform
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)
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..
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:
this would output 12
$_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)
<?php $id = $_GET['id']; echo $id; ?>
this would output 12
•
•
•
•
You can do it only with php.
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..
![]() |
Similar Threads
- Passing variables via url with slashes (Python)
- Is there a way in Ajax to not send variables in the url BUT using hidden variables? (JavaScript / DHTML / AJAX)
- sending variables in the URL (PHP)
- Retreiving a Variable from a URL (PHP)
Other Threads in the HTML and CSS Forum
- Previous Thread: Anyone good with Favlets? window links?
- Next Thread: how do i perform these calculations without writing redundant code?
| Thread Tools | Search this Thread |
appointments asp background backgroundcolor beta browser bug calendar cart cgi code codeinjection corporateidentity css design development displayimageinsteadofflash dreamweaver emailmarketing epilepsy explorer firefox flash form format google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization pnginie6 positioning problem scroll seo shopping studio swf swf. textcolor timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7






