Jump to content

Curiosity about dead link and fix using a php generated link


gwolgamott

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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);

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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-->";

Link to comment
Share on other sites

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>');

Link to comment
Share on other sites

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.

 

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.