Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: HTML URL Structure

  1. #1
    Join Date
    May 2013
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HTML URL Structure

    I visited one HTML Site .. I was confused How the URL's were created like

    example.com/folder/aap.html?code=32&version=0.1

    Suppose I clicked the above link on that site the more addition of same url with another page comes up


    example.com/folder/aap.html?code=32&version=0.1&releasedate=13

    I want to know how the multiple aap.html with same name is stored in the folder

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    These:

    ?code=32&version=0.1

    ?code=32&version=0.1&releasedate=13

    are known as query strings. Server side code (like asp or PHP), or even (though this isn't so common) client side code like javascript can use them to determine what content to show on a page.

    The basic idea is that the page itself is only a template, it's the query string that tells the server what content to put into it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2013
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Sir for your kind reply

    May I know the procedure How to achieve this..

    Like you said that the page is itself only a template, it's the query string that tells the server what content to put into it.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    This is a fundamental aspect of server-side languages like PHP, etc. In this case, for some reason it's claiming to be an .html file, even though it most likely has something else going on (maybe CGI? maybe PHP pretending to be HTML by generating a .html URL?).

    In terms of the URL, it's nothing special-- type anything you want, and that information will be available to the server. So I could type a URL like:
    /mypage.html?myvariable=myvalue
    [Note the URL for the forum pages here, or for any search you do on Google, and any number of other webpages.]

    And then I could access "myvariable" with the value "myvalue" in a serverside language, and do something with it-- maybe query a database, maybe decide which external .html page to include, whatever.

    But for making the serverside code work, you'll need to learn that. It's not especially hard, but it is something new, with completely new ideas compared to just using HTML. To be clear, the URL isn't doing anything at all-- it's just sending information to the server, then the server is doing something based on that information (and what it was programmed to do).

    First, you'll need to see what serverside language(s) your host/account supports (or get a new host/account). PHP is widely available, while other options are a little more specialized (ASP only on Windows servers, and various other languages like Python only if you choose to install them-- probably not on a "share hosting" account in most cases). You may also want to check on the other features you have, such as whether databases are available, and whether PHP (or whatever) is limited to "safe mode" (which might be problematic) or has any other restrictions or extra features (such as extended libraries for additional functions). But for now, just see what languages you can use. I'll guess PHP because it's common, and if not you can easily get a new account (for about $5/month from various companies, and in rare, possibly very limited cases, for free) to test it out on if not.

    Then you'll need to use what are called "get variables" in PHP (a kind of variable, not an action of "getting"). In short, for the example above, I'd write something like this:
    <?php echo $_GET['myvariable']; ?>
    That would output ("echo") "myvalue".
    You can use $_GET[] to grab any of the URL variables you'd like. Then, obviously, you'd need to set up your PHP script to do something with that information. Maybe query a database, etc.
    One very simple tool that is also very useful is called include():
    <?php include('mypage.html'); ?>
    That will grab all of the contents of "mypage.html" and dump them into the current page (as output, not changing the PHP code permanently). This is a very basic way to do what you're describing and it can help you keep your files organized.
    Beyond this, get a foundation in PHP (or some other serverside language) first and work out the details from there.


    By the way, there's also a very simple serverside language for just this purpose known as "SSI" or "server-side includes". I'm not sure how widely supported it is, but if you're only looking for this, that might work for you. It basically does PHP's version of include() without the rest of PHP. But PHP isn't all that hard to learn if you're up for something new anyway.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    It's complicated and depends to a degree upon which server side language you are using. It also depends upon how you want to code it. There are many ways to utilize the information in the query string. There are templates you can use though, so you don't have to do everything from scratch. I'm most familiar with PHP. A simple example would be - page.php:

    PHP Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    </head>
    <body>
    <?php
    if(!isset($_GET['page']){echo 'Hello'; die();}
    if(
    $_GET['page'] === 'page1'){include 'page1.htm';}
    if(
    $_GET['page'] === 'page2'){include 'page2.htm';}
    ?>
    </body>
    </html>
    If the URL is:

    page.php?page=page1

    it will show page1.htm. if it's:

    page.php?page=page2

    it will show page2.htm

    if it's just:

    page.htm

    it will show:

    Hello
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Just a minor adjustment to avoid missing close tags and add a default:
    PHP Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    </head>
    <body>
    <?php
    if(!isset($_GET['page']){echo 'Hello'; }
    else {
      if(
    $_GET['page'] === 'page1'){include 'page1.htm';}
      else if(
    $_GET['page'] === 'page2'){include 'page2.htm';}
      else { echo 
    'Sorry, requested page not found.'; }
    }
    ?>
    </body>
    </html>

    (By the way, you can reliably use == instead of === here because $_GET values will be strings based on the kind of input. Technically they could be something else, but I don't see how they'd end up that way, unless you're manually changing the values within $_GET, which is rarely necessary [unless you're doing some kind of extra layer of URL changes with .htaccess, for example, and even then they should still be strings, as if they were the original input]. Of course === won't hurt anything, so there's no reason not to use it either I guess.)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    It's because they're strings that the more efficient === may be used. You only need to use == when you want type not to matter. It's more work for the processor though because it has to determine if the types are different, if one can be converted to the other, and then if they're equal or not after conversion.

    But all of this is immaterial to the basic concept, which is all we're concerned with here. Except that it does illustrate in a small way how different code can be used for the same things. The question was almost too general, but I tried to Google it and found nothing basic. Are you aware of a good tutorial on this?

    Oh, and the server can process the .html page as .php, .asp, or whatever, simply by setting that in the .htaccess file or the server config.

    This same idea can be used to have only a portion of the page be different:

    PHP Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    </head>
    <body>
    Some stuff up here that will always be the same.
    <?php
    if(!isset($_GET['page']){echo 'Hello'; }
    else {
      if(
    $_GET['page'] === 'page1'){include 'page1.htm';}
      else if(
    $_GET['page'] === 'page2'){include 'page2.htm';}
      else { echo 
    'Sorry, requested page not found.'; }
    }
    ?>
    More stuff down here that will always be the same.
    </body>
    </html>
    Last edited by jscheuer1; 06-19-2013 at 08:08 AM. Reason: detail
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    It's because they're strings that the more efficient === may be used. You only need to use == when you want type not to matter. It's more work for the processor though because it has to determine if the types are different, if one can be converted to the other, and then if they're equal or not after conversion.
    Hm, I actually don't know which is more efficient. It might be more efficient to compare them without also comparing the types (that's how I've seen it phrased, that === is "== plus checking types"), or it might be more efficient to use === because it only checks one thing, or it might depend on whether they are or are not the same type (so that here it would not matter because they are).

    The question was almost too general, but I tried to Google it and found nothing basic. Are you aware of a good tutorial on this?
    No, not really. It is good general, because doing this requires some knowledge of a serverside language, yet with that knowledge it comes more or less for free. So a good place to start would be any tutorial on include() or just the documentation page on php.net with examples:
    http://php.net/manual/en/function.include.php
    Of course that will require other things, like having PHP available on the server, knowing how to save a .php (rather than .html) page and so forth. But it's not too hard, and it's a reasonable way to learn-- that was in fact the first thing I did using PHP, just putting together information from a few tutorials/manuals.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,933
    Thanks
    16
    Thanked 303 Times in 302 Posts
    Blog Entries
    9

    Default

    If it helps at all, there's a test pack I prepared a while ago here: http://www.dynamicdrive.com/forums/s...893#post282893

    Its only a general example and, as John and Daniel have said, you should still research and learn some basic PHP to understand what is happening.

    The home page auto-generates a list of links and sequentially numbered query strings but that's irrelevant. The important part is the URL+query string, which could be hardcoded instead as;
    Code:
    <a href="news.php?n=0001"> News One </a> 
    <a href="news.php?n=0002"> News Two </a> 
    <a href="news.php?n=0003"> News Three </a>
    The news page is where the magic happens. From the URL+query string that has been passed from the home page, $_GET takes the value of 'n' (John's example $_GET's the value of 'page') and then the contents of a similarly named file are pulled in. John's example uses include() while my test script uses file_get_contents(), which are similar functions, except that file_get_contents() will not allow scripts to execute from the file content it is getting. Include() will. You can decide which function is better for you.

    Because include() allows scripts to execute, it will prove more useful when pulling in other dynamic content - here's a simple tutorial: http://www.tizag.com/phpT/include.php and from there you can begin to see how versatile/time-saving PHP can be. In fact, have a look at some of the related tutorials offered on that website because it will help build your basic PHP knowledge pretty quickly.

    Good luck in your project.
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  10. #10
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yeah, good replies above. Think of it as you sending a request to the server with information, then the server responds and loads up your web page according. The same thing happens with this forum, ie,?74258-HTML-URL-Structure, where the 74258 is the thread number, located as a field in the db, or key.

Similar Threads

  1. PHP & HTML Structure
    By jdadwilson in forum PHP
    Replies: 3
    Last Post: 03-21-2013, 03:31 AM
  2. Structure of RSS feeds
    By biomike in forum Looking for such a script or service
    Replies: 0
    Last Post: 01-21-2010, 03:00 PM
  3. need a help for the structure of web
    By gurmeet in forum Looking for such a script or service
    Replies: 1
    Last Post: 10-30-2009, 11:43 AM
  4. php structure (MVC?)
    By Dennis_Gull in forum PHP
    Replies: 7
    Last Post: 09-10-2008, 07:36 AM
  5. Looking for a data structure that . . .
    By Trinithis in forum Other
    Replies: 0
    Last Post: 12-31-2007, 05:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •