I am trying to find a PHP breadcrmb system that works on InfinityFree. I have found two so far, but each returns a 500 error (In witch I blamed Cloudflare + Logflare for, sorry about that). Is there a reason why that would be happeneing here? I am trying to but them in the <body> section of my PHP file (Other PHP code there works just fine), but it just wont work.
Is there a reason why it is not working, or am I doing something wrong (I really dont think so).
For starters, the links you shared are from 2003 and 2004. PHP has changed a lot since then so the code might not be compatible anymore.
It doesn’t seem likely to me that the 500 error is a result of Cloudflare. Cloudflare just forwards whatever the backend server generates, including any errors. Perhaps you could try enabling display_errors and see if you can get an actual error message?
Oh, it’s not. I just said I blamed them and took my frustration out on them before finding the real issue was not with them, but with the code.
I found another breadcrumb script that might work, and I’m not on a device with access to my files, so I’ll enable error messages and get back to you when I can.
Parse error : syntax error, unexpected ‘crumbs’ (T_STRING), expecting ‘;’ or ‘,’ in /home/vol1000_7/epizy.com/epiz_2xxxxxx7/htdocs/test/other.php on line 2
The code:
<?php
echo "<ul id="crumbs">";
/* get array containing each directory name in the path */
$parts = explode("/", dirname($_SERVER['REQUEST_URI']));
echo "<li><a href="/">Home</a></li>";
foreach ($parts as $key => $dir) {
switch ($dir) {
case "about": $label = "About Us"; break;
/* if not in the exception list above,
use the directory name, capitalized */
default: $label = ucwords($dir); break;
}
/* start fresh, then add each directory back to the URL */
$url = "";
for ($i = 1; $i <= $key; $i++)
{ $url .= $parts[$i] . "/"; }
if ($dir != "")
echo "<li>> <a href="/$url">$label</a></li>";
}
echo "</ul>";
?>
Console is empty
Others:
Parse error : syntax error, unexpected '' (T_NS_SEPARATOR), expecting identifier (T_STRING) in /home/vol1000_7/epizy.com/epiz_28335187/htdocs/test/sitepointone.php on line 9
Not just the first line. Every single line with echo in that example uses " to terminate the PHP strings, and then also uses " to terminate the HTML, which will most definitely break.
You need to either escape the quotes in the PHP string, or mix quotation to prevent this.
The #91 etc. part on line 16 are the cause of this.The # is a comment sign, meaning everything after parts& is not interpreted, including the crucial ; and } characters.
I’m shocked that someone would write $parts[$i]. I have no idea what it’s supposed to do, and I don’t see how this could have ever worked in PHP.
The main reason I liked this one is because it seems to have the feature to change things. Like if the URL is /hello_hello than the breakcymb could say something different like /hello
For some strange reason it looks like it went through the htmlentities() php function, or at least part of it did…
p.s. The sorely abused php echo() function, or return() for that matter, by php-ers everywhere, is still a function.
Even though the php parser lets us use it without the including brackets, I always do write the brackets. If it’s a function then call it like one. At least, in my opinion, that makes for more legible code. That’s from an old c/c++ guy.
Also, when you need to escape double quotes, then escape them. Makes you realize what you are actually writing and why. Dont be lazy and use single quotes unless they are necessary. There will come a time when they will be actually necessary (regex).
I just noticed that in your last screenshot, on line 16, you have omitted the dot before the equals sign. You need to have that there. Or, even better, for more legibility, you can write
If you don’t have it, every element of the array $parts will overwrite all the previous contents of the $url variable when iterating through the for loop, and you’ll end up with just the last element in the variable, which in this case is a string, representing a url. So the url in each of your breadcrumbs links, will be wrong in the end. It’s the difference between writing
And that is fine (It’s the beginnings what I want), except the path to the file is “/path/to/file/about.html”. Is there a way “About” (The filename) and “To” (Part of the directory) can be added?
Thanks!