Views: 22985
Last Modified: 19.05.2022

In order to store identifiers of elements/sections of information blocks the field Symbolic Code is most convenient. For example, in the link www.myserver.com/catalog/mobile/nokia_3310/, mobile is the symbol code of the section Mobile telephones, and nokia_3310 is the symbol code of the element located in the section Mobile telephones. The symbol code must be unique, and the system itself checks its uniqueness.

The variable $_SERVER["REQUEST_URI"] in the error 404 handler must be broken down by parameters. To do so, a number of useful functions are available in PHP:

For example, links similar to myserver.com/users/ are processed in the file 404.php as follows:

<?
if(preg_match("~^/users/([a-z_][a-z0-9_]{2,14})/?$­~i",$_SERVER["REQUEST_URI"],$match))
{
header("HTTP/1.1 200 OK");
//selection by the identifier
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.­php");
$res = CUser::GetList($O, $B, Array("LOGIN_EQUAL_EXACT"=>$match[1],"ACTIVE"=>"Y"­));
//$match[1] contains login
if($arUser = $res->GetNext())
{
//user’s data are displayed
}
else
{
//error: there is no such user
}
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
}
else
{
header("HTTP/1.1 404 Not Found");
//error
}
?>

But fixed check in preg_match not permit to do links similar to www.myserver.com/users/user_login/?r1=banner&r2=com­puterra.com that are very much needed to analyze advertising campaigns. That is why we write the following in the beginning of the file 404.php:

<?$arURI = parse_url($_SERVER["REQUEST_URI"]);
$_SERVER["REQUEST_URI"] = $arURI["path"];
if(!empty($arURI["query"]))
{
parse_str($arURI["query"],$par);
foreach($par as $key => $val)
{
global $$key;
$$key = $val;
}
}
?>




Courses developed by Bitrix24