Jump to content

Need help with url variables


Kryten2k35

Recommended Posts

Hi,

 

I'm wanting help with some url variables and advice on the best way to implement them.

 

I already have some code inplace to grab pages from a location.

 

<?php



// GETS VALUE FOR $page
$page = strip_tags($_GET['page']);

// SEES IF $page IS DEFINED
// IF IT ISN'T IT WILL DISPLAY home.txt
if (!$page)
{
  $include = 'includes/pages/home.php';
  include ($include);
}

else
{
  // $include ADDS THE DIRECTORY AND PAGE EXTENSION OF page
  $include = 'includes/pages/'.$page.'.php';

  // CHECKS IF $include EXISTS
  if (is_file("$include"))
  {
    // SHOWS THE CONTENT OF $include
    include ($include);
  }

  // DISPLAY ERROR MESSAGE IF $include IS NOT FOUND
  else
  {
    include ('includes/pages/404.php');
  }
}

?>

 

So my url looks like this:

 

http://bronte-crafts.com/index.php?page=home

 

I also need a secondary section of that url like so:

 

http://bronte-crafts.com/index.php?page=gallery&section=dollshousebedding

 

However, I don't want the script to force a page to be loaded if section isn't defined as it won't always be defined.

 

The site I'm working on is my girlfriend's website and the section variables will all be sub sections of the gallery page. So they'll only be shown/needed when we're viewing the gallery. I'm not sure where I'll put the links for the subsections yet. Perhaps they'll into the same area as the original page include or perhaps they'll go in a different element of the site. Which would be better?

 

Also, is there any way to clean up the URL a hell of a lot? I've tried mod rewrite tutorials but they always end up destroying my pages and doesn't seem to want to use my stylesheet.

 

Thanks in advance!

 

Matt

Link to comment
Share on other sites

I don't know :(

 

I just grabbed that code somewhere to include pages dynamically

 

What I'm going to do on the gallery page is have a list of links to the different categories such as dolls house bedding, jewellery, etc. From dolls house bedding I also want to then have sub categories such as beddings and linens, furniture, etc.

 

So, then I could have, page=dollshouse&section=bedding

 

the page "dollshouse.php" would have some information given at the top and then at the bottom would be links to bedding, furniture. clicking those links would then, in turn, show a new page altogether.

 

I'm not sure php navigation is the best option for me right now, though. Can you recommend another way of going about this?

 

 

Also, I would like "page=dollshouse&section=bedding" to become something like index.php?dollshouse/bedding or something SEO compatible.

 

 

 

Link to comment
Share on other sites

Basically I need:

 

If no $page is defined then use "home" .php else use the defined page

 

also, if no $section is defined, do nothing, else, show defined section

 

else, if error, show 404.php

 

That's what I need to be able to do! But I can't write php :(

Link to comment
Share on other sites

If your only using html links to other static html pages then php is not needed, and if it's not needed you shouldn't really use it - it's just over complicating things. That said it sounds to me like you want to take all this static content and condense it into one dynamic page.  If that's the case then php is the tool for the job.  If you are trying to make it all one dynamic page then post up your a few of your existing html page titles along with the full code for your index.php and we'll get to work.

Link to comment
Share on other sites

The OP can still use the code as starting point for his script. As long as the input is sanitized and validated it's fine. I use something similar all the time.  Disallow any value that looks like a URL or has slashes in it. Then validate the value against valid page names. If the value passed in is not valid, just show the default page.

 

Ken

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.