gwolgamott Posted February 4, 2010 Share Posted February 4, 2010 I got this being a dead link /index.php?page=Management System Documentation/Shipping & Receiving/Receiving but with it being replaced with this it works fine for the obvious change. /index.php?page=Management System Documentation/Shipping And Receiving/Receiving Well I know why it caused the issue because php doesn't like the "&" here: $page = $_REQUEST['page']; $page = 'index/'.$page.'/struct.php'; Understandable once I figured out why it was puking on me... anyways... how do I go about and what special characters should I be error checking for here before the second line there? First off I know later in the use of this script there will be folders named with the "&" and perhaps others that may come along. Have no control over the naming scheme. Quote Link to comment Share on other sites More sharing options...
bbaker Posted February 4, 2010 Share Posted February 4, 2010 http://us.php.net/manual/en/function.urlencode.php ...maybe? Not sure how it handles &'s $page = 'index/'.urlencode($page).'/struct.php Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Author Share Posted February 4, 2010 Didn't work, but thanks man prolly gonna keep that in code anyways. Makes me super curious though, because if I use most other operators it seems to work ok and just seems almost exclusive to the & for some reason for this error. I did a bunch of tests to try and figure out if other would cause the problem but no it didn't.Strange huh Quote Link to comment Share on other sites More sharing options...
bbaker Posted February 4, 2010 Share Posted February 4, 2010 oh....wait.... where is the page=Management System Documentation/Shipping & Receiving/Receiving coming from. THAT is what needs the urlencode on it. Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Author Share Posted February 4, 2010 $page = 'index/'.urlencode($page).'/struct.php $page=Management System Documentation/Shipping & Receiving/Receiving so actual page is: index/Management System Documentation/Shipping & Receiving/Receiving/struct.php EDIT: tried this but it broke all my links this way $page = ('index/'.$page.'/struct.php'); $page = urlencode($page); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 4, 2010 Share Posted February 4, 2010 The problem is the character '&' is used for separating url variables withing a query string., eg file.php?var1=foo&bar=something. Your http server is thinking you're passing a query string and is breaking your urls. To prevent this you can replace & as & or remove it from your urls. However it is not really a good idea for urls to contain spaces either. Try to keep you urls as minimal and as clear as possible, for example the following is much more cleaner site.com/documentation/shipping/receiving If you have to use a space in your url then an underscore is a better replacement Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Author Share Posted February 4, 2010 The problem is the character '&' is used for separating url variables withing a query string., eg file.php?var1=foo&bar=something. Your http server is thinking you're passing a query string and is breaking your urls. To prevent this you can replace & as & or remove it from your urls. However it is not really a good idea for urls to contain spaces either. Try to keep you urls as minimal and as clear as possible, for example the following is much more cleaner site.com/documentation/shipping/receiving If you have to use a space in your url then an underscore is a better replacement Ah ok, makes that clearer then. I'd like to remove it spaces and the & altogether.... and will recommend to that to whomever controls this site. But since this is designed for someone to drop a folder with forms in it named whatever for people to d/l from an intranet. I have no control over what the folders will really be named. So would still like to have something in there for error checking... incase they name it like that. This was discovered on an test run and didn't accept the fix of "Well don't name it that way...you shouldn't... etc...". Do you recommend a specific error check I mean, I have one in there but all it does is check if that actually points to someplace with a file that exists and outputs that it doesn't exist. Quote Link to comment Share on other sites More sharing options...
bbaker Posted February 4, 2010 Share Posted February 4, 2010 problem is that he doesn't have control over the naming scheme, so I was trying to help out with what he has to work with....that's why I suggested urlencode "Management System Documentation/Shipping & Receiving/Receiving" is what I meant needs to have urlencode. So where ever that is coming from in the first place, needs to be sent through the urlencode function. So the URL would actually look like: index.php?page=Management+System+Documentation%2FShipping+%26+Receiving%2FReceiving Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Author Share Posted February 4, 2010 it getting confused before the request I think, makes sense actually.... I get this index/Management+System+Documentation%2FShipping+ instead of what I should be getting doing it in a variety of ways such as these among other combinations I've tried. $page = $_REQUEST['page']; //$page = urlencode($_REQUEST['page']); //$page = urlencode($page); $page = ('index/'.$page.'/struct.php'); //$page = str_ireplace("&","&",$page); echo "<!-- CCCCCCCCCCC ".$page." CCCCCCCCCCCC-->"; Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Author Share Posted February 4, 2010 Fixed it. Thank-you. Put it in a function that created the link before the request where it should have been to begin with Doh! haha... Thank-you. For curiousity sake here's where I put it. if (is_array($value) == TRUE) { if($value[0] == "LINK_ME") { $temp_key = $key_sub.'/'.$key; $temp_key = urlencode($temp_key); echo ('<li><a href="index.php?page='.$temp_key.'">'.$key.'</a></li>'); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 4, 2010 Share Posted February 4, 2010 urlencode needs to be used where you create the link not when you're retrieving it. However when you do retrieve it you'll need to use urldecode Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Author Share Posted February 4, 2010 urlencode needs to be used where you create the link not when you're retrieving it. However when you do retrieve it you'll need to use urldecode Yeah that's what I did to get it working. Thanks. Fixed it. Thank-you. Put it in a function that created the link before the request where it should have been to begin with Doh! haha... Thank-you. Quote Link to comment 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.