bachya Posted June 21, 2006 Share Posted June 21, 2006 Hi all,I have this bit of code:[code]<?php if (isset($_GET[article])) { if (file_exists($_GET[issue].'/'.$_GET[article].'.html')) include($_GET[issue].'/'.$_GET[article].'.html'); else include($_GET[issue].'/default.html'); } else { include($_GET[issue].'/default.html'); }?>[/code]What I need is this: if I have a URL that's something like - www.mydomain.com/articles.php?issue=sp06&article=1 - I want to use both the "issue" and "article" variables to descend into my directory structure and include the necessary article. The directory is something like this:articles.phpsp06 -> 1.html 2.html ...fl06 -> 1.html 2.html ......and so on. The above implementation is incorrect - perhaps my knowledge of concatenation in PHP is flawed...Can anyone point me in the right direction? Let me know if the above info is not adequate.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/12556-php-includes-through-directories/ Share on other sites More sharing options...
Buyocat Posted June 21, 2006 Share Posted June 21, 2006 What exactly is the error you are getting? It looks like the file that will be included will be something like this:public_html/issue_dir/article_html.htmlI am assuming the public_html. At any rate, the problem I see is that you're GET[ ] needs to have 's around the strings, so $_GET['article'] instead of $_GET[article]. Otherwise I'm not sure what else is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/12556-php-includes-through-directories/#findComment-48112 Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 Maybe try echo'ing your path to see how it looks? eg;[code]echo $_GET['issue'].'/'.$_GET['article'].'.html');[/code]Your code looks fine so....what exactly do you meen by?[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] The above implementation is incorrect[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/12556-php-includes-through-directories/#findComment-48113 Share on other sites More sharing options...
bachya Posted June 21, 2006 Author Share Posted June 21, 2006 [!--quoteo(post=386475:date=Jun 21 2006, 12:36 PM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Jun 21 2006, 12:36 PM) [snapback]386475[/snapback][/div][div class=\'quotemain\'][!--quotec--]What exactly is the error you are getting? It looks like the file that will be included will be something like this:public_html/issue_dir/article_html.htmlI am assuming the public_html. At any rate, the problem I see is that you're GET[ ] needs to have 's around the strings, so $_GET['article'] instead of $_GET[article]. Otherwise I'm not sure what else is wrong.[/quote]The scary thing is that there is no error - it's just a blank page (with my main CSS layout). I tried adding 's around the variable names in $_GET[], but that didn't seem to help.[!--quoteo(post=386476:date=Jun 21 2006, 12:40 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 21 2006, 12:40 PM) [snapback]386476[/snapback][/div][div class=\'quotemain\'][!--quotec--]Maybe try echo'ing your path to see how it looks? eg;[code]echo $_GET['issue'].'/'.$_GET['article'].'.html');[/code]Your code looks fine so....what exactly do you meen by?[/quote]Unfortuantely, that ALSO gives a blank page...it's baffling, because that should be right. I'm assuming it's incorrect because the desired results aren't appearing. :( I noticed that it echoes output in the ELSE part of the branch to check if the file exists or not...if that helps at all. Quote Link to comment https://forums.phpfreaks.com/topic/12556-php-includes-through-directories/#findComment-48114 Share on other sites More sharing options...
bachya Posted June 21, 2006 Author Share Posted June 21, 2006 Okay, so I finally was able to echo my path, piece by piece, and this code:[code]echo $_GET['issue'].'/'.$_GET['article'].'.html'[/code]...gave this result:sp06/1.html (when my URL was www.mydomain.com/articles.php?issue=sp06&issue=1)Still no dice - as I said before, the problem is (I believe) coming in the part of the code below that is the ELSE branch to the "file_exists" function:[code]<?php if (isset($_GET['article'])) { if (file_exists($_GET['issue'].'/'.$_GET['article'].'.html')) include($_GET['issue'].'/'.$_GET['article'].'.html'); else echo $_GET['issue'].'/'.$_GET['article'].'.html'; } else { include($_GET[issue].'/default.html'); }?>[/code]Since it's echoing the path correctly, that must mean that "file_exists" is having a problem with it. Unfortunately, I'm newbie enough to PHP that that doesn't help me.[b]EDIT:[/b] Okay, it definitely is "file_exists", because if I remove that, it includes correctly. However, now I've just left a huge hole in my site...sheesh. Does anyone know why this function is giving me so much trouble? Quote Link to comment https://forums.phpfreaks.com/topic/12556-php-includes-through-directories/#findComment-48123 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.