/    Sign up×
Community /Pin to ProfileBookmark

I just can’t figure out pages with variables in the address bar!

I often see web pages with a question mark in the address bar, and after the question mark appear to be variables that apparently modify the output of the webpage. (e.g. [URL=http://forums.webdeveloper.com/newthread.php?s=&action=newthread&forumid=2]http://forums.webdeveloper.com/newthread.php?s=&action=newthread&forumid=2[/URL]). And they’re not only in ASP and PHP pages; I even find it in HTML pages. For many a day I have tried to figure out and look for information on how to use this in my own webpages, but I found nada. I couldn’t find one explanation on the internet. Someone, PLEASE send me some links to pages that explains how to create a dynamic webpage modified by location bar variables after a “?” mark.

to post a comment
HTML

12 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 08.2003 — OK, I can use Javascript, ASP, PHP, and/or Perl/CGI to [i]parse[/i] the URL (address). Here is an example with Javascript: http://geocities.com/god_loves_07/Chris_parse_URL_test.htm

When you have say, "somesite.org/pages/page1.html?var1=haha&var2=hehe" you can use a server-side (or client side) language to parse the URL. You can use Javascript to print to the page that var1 (var = short for variable) is equal to "haha" and var2 is equal to "hehe." This is also done many times when a form is posted using the GET method:

<FORM name="formName" ACTION="someFile.cgi" METHOD="GET">

<input type=text name="txt1" value="hi"><br>

<input type=text name="txt2" value="lo"><br>

</form>

This will send all form data in the form to "someFile.cgi" with the form name elements and their values in the URL. The URL would look like this: http://somesite.com/someFile.cgi?txt1=hi&txt2=lo

See what I mean?
Copy linkTweet thisAlerts:
@NedalsMar 08.2003 — OK, so now you know how to get the form data into the URL. But how do you retrieve it.

Add this in the head section of your 'retrieving' page

<script language=JavaScript>

<!--

var URL = escape(window.top.location); // escape: encode charactures that javascript doesn't like

var query_string = unescape(URL.split("%3F")[1]); // split off the 'query_string'. Everything after '%3F' ( encoded '?')

var pairs = query_string.split("&");

var FORMDATA = new Array();

// Here we create an associative style array (hash). Widely used in Perl.

// ie. value = FORMDATA['fieldname'];

for (var i=0; i<pairs.length; i++) { FORMDATA[pairs[i].split("=")[0]] = pairs[i].split("=")[1]; }



// and here you can see the result.

alert(FORMDATA['txt1']);

//-->

</script>
Copy linkTweet thisAlerts:
@MarkEauthorMar 08.2003 — Okay, so now I see that using the form's "get" method, when the form is submitted all the form fields' values appear in the address bar, and before the question mark appears the address from the "action" of the form. But, I don't think it would be a good idea to use JavaScript to extract the values, because some people don't have JavaScript. When I look at the source codes of pages that receive variables from the address bar, I never really see a script that is used to extract the part after the ? mark as text. Instead, I think they probably use the POST method of a form. How exactly can I use a POST method?
Copy linkTweet thisAlerts:
@khalidali63Mar 08.2003 — There is only 2 ways of getting form data,either with the JavaScript or some server side programming language,If your concern is that JavaScript might not be enabled,then you have to look for a server side programming lang,suh as Java( servlets or jsp),asp,php ,perl etc.

A programming language will read through the HTTP message packet and determine that which posting method is used "GET" or "POST" , this action ( readingof HTTP packet) is transparent from user.and then appropriately parse the HTPP packet to get the data.

To learn or see how ?OST" is recieved by a programming language,you will have to read a book, at least.

Cheers

Khalid
Copy linkTweet thisAlerts:
@MarkEauthorMar 08.2003 — What is an HTTP packet? I don't exactly understand what you mean.

P.S. How do all of you get that animated icon next to your names?
Copy linkTweet thisAlerts:
@khalidali63Mar 08.2003 — click on user cp button at the top,the go to edit options and then at the bottom, look for avatar title and upload an image there.

HTTP packets....way beyond the scope of these forums,just remember any data that is transfered over the internet using allots of different protocols(HTTP is one of them) is transfered in chunks of data,these chunks of data are called packets,if you want to understand this in details,you will have to read books on Networking,they will have description of

OSI layer model and protocol deifferences and how the data is read at each layer of the OSI model at each machine.

Cheers

Khalid
Copy linkTweet thisAlerts:
@MarkEauthorMar 08.2003 — OK, now I'm catching on. The POST method can only be used with server-side programming, and if you're using HTML, you need JavaScript to extract it as text. Good, but I don't understand post number 8, by khalidali63, about all this server stuff. I'm sorry to say this, but I can comprehend very little about servers and networks. I don't know what these things mean -- protocols, data chunks, packets, OSI... A lot of networking I don't understand because I haven't even had an introduction to servers and networking. Trust me, I could look at the simplest web page, the simplest book on this stuff, and it's just a whole bunch of abbreviations and acronyms that I can't understand. But, hopefully, I'll understand it someday. ? Someday... ?
Copy linkTweet thisAlerts:
@MarkEauthorMar 30.2003 — Update:

I looked at the page for the USGS -- The United States Geological Survey ([URL=http://www.usgs.gov]click here to visit[/URL]), and they use dynamic web pages modified by variables in the address bar -- using HTML -- and without JavaScript!!! In fact, EVERY SINGLE HTML PAGE I have ever visited that uses address bar variables does NOT have a JavaScript in it (except, of course, the pages all of you showed me). I sure wonder how they pass the values to the form fields in the page? With the USGS page, I am astounded at how the entire site is run by HTML without a single script anywhere! ? ? ? ? ? ? ? ? ?
Copy linkTweet thisAlerts:
@jeffmottMar 30.2003 — [b]and they use dynamic web pages modified by variables in the address bar -- using HTML[/b][/quote]You can really use any file extension to mean anything you want. Especially in Apache, which is good at letting you override some of the default configuration settings. For example:[size=2]-- .htaccess --
AddHandler cgi-script .cgi .pl .html[/size]

Now in the directory in which this file resides .html files will be treated no differently than .cgi or .pl. They will all be executed at the server. The same can be done for PHP, ASP, SHTML, etc.
Copy linkTweet thisAlerts:
@MarkEauthorMar 30.2003 — In reply to jeffmont's reply:

  • 1. What is Apache?


  • 2. What is that script you gave me? Is it a CGI script? And where does it go?


  • In respnse to Dave Clark's reply:

    Oh, sorry about that. What I meant to say was, I didn't see any Javascript that took parts of the address and game the form fields those values. I neglected the rest of the Javascript that didn't apply to what I was trying to find out. Sorry! :o ?
    Copy linkTweet thisAlerts:
    @jeffmottMar 30.2003 — [b]What is Apache?[/b][/quote]The currently most widely used Web server software.

    http://httpd.apache.org/[b]What is that script you gave me? Is it a CGI script? And where does it go?[/b][/quote]It is a configuration file for Apache. It allows you to change the default operation of the server on a directory level basis. In the case above, files with the .html extension were added to list of types to be executed as a CGI script. So the query string could be parsed at the server for .html file.
    Copy linkTweet thisAlerts:
    @MarkEauthorApr 01.2003 — Okay, now this is starting to make sense. So the way the USGS page ([URL=http://www.usgs.gov]http://www.usgs.gov[/URL]) processes the "query string" (as I have just found out that name on the internet) without that JavaScript (which some browsers might not support), was that they used a CGI script to have the page parsed as a CGI page. Then, it sends output to the page (as in server side scripting), so that you can't see the source code they used to dynamically process that page. It's beginning to become clearer. ? Just one thing: where does the CGI script that specifies how the server will handle the page go? Is it a CGI file placed in the root directory?

    Gee, it sure sounds interesting, how they use server side scripting to do all this stuff. Sometime, I would like to go out and learn it. ?

    P.S. Oh shoot, I can't find the forum that this question started at. I know I got tons of replies, but I must have accidentally deleted it! :eek: Oh, no! Please tell me it's somewhere out there! ? ? ? ? ?

    Anyway, if someone else reads this post and has no idea what the heck we're talking about, just know that this question originated at some other post I started that must have gotten deleted. :mad:
    ×

    Success!

    Help @MarkE spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...