You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mongoose environment variables are broken in a few ways:
* REQUEST_URI does not contain QUERY_STRING
* Pretty urls like "/index.php/company/5" have invalid values for SCRIPT_NAME and PHP_SELF keys
* SCRIPT_FILENAME and PATH_TRANSLATED contain forward slash before script name
When accessing url like "/pretty-urls.php/company/5" keys in $_SERVER variable
are:
Array
(
[REQUEST_URI] => /pretty-urls.php/company/5
[SCRIPT_NAME] => /pretty-urls.php/company/pretty-urls.php
[SCRIPT_FILENAME] => C:\phpdesktop\phpdesktop-chrome\www/pretty-urls.php
[PATH_TRANSLATED] => C:\phpdesktop\phpdesktop-chrome\www/pretty-urls.php
[PATH_INFO] => /company/5
[HTTP_REFERER] => http://127.0.0.1:49257/pretty-urls.php
[PHP_SELF] => /pretty-urls.php/company/pretty-urls.php/company/5
)
Before a final fix is released, you can use the PHP function below to fix these
issues. Apply this code at the top of PHP script:
<?php
function __fix_mongoose_env_variables()
{
// REQUEST_URI does not contain QUERY_STRING. See Issue 112
// in the tracker. The condition below will be always executed.
if (strpos($_SERVER["REQUEST_URI"], "?") === false) {
// Fix PHP_SELF and SCRIPT_NAME env variables which may be
// broken for pretty urls like "/index.php/company/5":
// >> [PHP_SELF] => /index.php/company/index.php/company/5
$php_self = $_SERVER["PHP_SELF"];
if (strrpos($php_self, "/") !== 0) {
// When PHP_SELF contains more than one slash. Remove
// path info from both PHP_SELF and SCRIPT_NAME.
$php_self = preg_replace('#^(/+[^/\\\]+)[\s\S]+#',
'\\1', $php_self);
$_SERVER["PHP_SELF"] = $php_self;
$_SERVER["SCRIPT_NAME"] = $php_self;
}
// Append QUERY_STRING to REQUEST_URI env variable.
if (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"]) {
$_SERVER["REQUEST_URI"] = $_SERVER["REQUEST_URI"]."?".(
$_SERVER["QUERY_STRING"]);
}
}
// Fix forward slash in SCRIPT_FILENAME and PATH_TRANSLATED:
// >> C:\phpdesktop\phpdesktop-chrome\www/pretty-urls.php
// should become:
// >> C:\phpdesktop\phpdesktop-chrome\www\pretty-urls.php
$_SERVER["SCRIPT_FILENAME"] = str_replace("/", "\\",
$_SERVER["SCRIPT_FILENAME"]);
$_SERVER["PATH_TRANSLATED"] = str_replace("/", "\\",
$_SERVER["PATH_TRANSLATED"]);
// Fixes were applied to $_SERVER only. Apply them to $_ENV as well.
$keys_to_fix = ["REQUEST_URI", "SCRIPT_NAME", "PHP_SELF",
"SCRIPT_FILENAME", "PATH_TRANSLATED"];
foreach ($keys_to_fix as $env_key) {
putenv("$env_key={$_SERVER[$env_key]}");
$_ENV[$env_key] = $_SERVER[$env_key];
}
}
__fix_mongoose_env_variables();
?>
Original issue reported on code.google.com by [email protected] on 27 Oct 2014 at 7:47
The text was updated successfully, but these errors were encountered:
Hi there, I know this bug have been discussed a long time ago but I really need a help.
I am facing the same problem of url redirection in my fresh intall laravel 5.6 on phpdesktop-chrome-57.0-rc-php-7.1.3.
Everything works fine when you launch the app. but when I start adding links to new pages, the redirection on click is keeping throwing this Error 404: Not Found File not found . and the same error in the console. but the route and file existe I don't know what to do.
I have try to follow of the solution discussed here. but not working. I which to know exactly where I have to insert the __fix_mongoose_env_variables(){ ...} in my laravel app.
Original issue reported on code.google.com by
[email protected]
on 27 Oct 2014 at 7:47The text was updated successfully, but these errors were encountered: