Kryten2k35 Posted May 10, 2010 Share Posted May 10, 2010 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§ion=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 Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/ Share on other sites More sharing options...
Muddy_Funster Posted May 10, 2010 Share Posted May 10, 2010 Is there a reason why you need to post the variables through the page headers and not through $_POST or $_SESSION super globals instead? Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055732 Share on other sites More sharing options...
Kryten2k35 Posted May 10, 2010 Author Share Posted May 10, 2010 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§ion=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§ion=bedding" to become something like index.php?dollshouse/bedding or something SEO compatible. Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055740 Share on other sites More sharing options...
Kryten2k35 Posted May 10, 2010 Author Share Posted May 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055754 Share on other sites More sharing options...
ignace Posted May 10, 2010 Share Posted May 10, 2010 I just grabbed that code somewhere to include pages dynamically Wherever that code came from put it back as it will cause more trouble in the future. Just see what happens when I pass: ?page=../../index Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055763 Share on other sites More sharing options...
Muddy_Funster Posted May 10, 2010 Share Posted May 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055766 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055770 Share on other sites More sharing options...
Muddy_Funster Posted May 10, 2010 Share Posted May 10, 2010 The OP can still use the code as starting point for his script.... Ken I thought I had hinted at that in my last sentence... Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055796 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 I was replying to ignace, not you. Ken Quote Link to comment https://forums.phpfreaks.com/topic/201236-need-help-with-url-variables/#findComment-1055809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.