xref: /web-php/error.php (revision d14eb56a)
1<?php
2/*
3
4 This script handles all 401, 403 and 404 error redirects,
5 and some directory requests (like /images). Uses the
6 preferred language setting and the REQUEST_URI to guess what
7 page should be displayed. In case there is no page that can
8 be displayed, the user is redirected to a search page.
9
10*/
11
12// Ensure that our environment is set up
13include_once __DIR__ . '/include/prepend.inc';
14include_once __DIR__ . '/include/languages.inc';
15include_once __DIR__ . '/include/errors.inc';
16
17// Get URI for this request, strip leading slash
18// See langchooser.inc for more info on STRIPPED_URI
19$URI = substr($_SERVER['STRIPPED_URI'], 1);
20
21// ============================================================================
22// Mozilla Search Sidebar plugin resource file handling (need to be mirror
23// dependent, so the search results will show up in the sidebar)
24if ($URI == 'phpnetsearch.src') {
25    status_header(200);
26    include_once __DIR__ . '/include/mozsearch.inc';
27    exit;
28}
29// FIXME: Nuke the old firefox search plugin
30if ($URI == 'phpnetimprovedsearch.src') {
31    status_header(200);
32    include_once __DIR__ . '/include/mozopensearch.inc';
33    exit;
34}
35
36// ============================================================================
37// BC: handle bugs.php moved completely to bugs.php.net
38if (preg_match("!^bugs.php\\?(.+)$!", $URI, $array)) {
39    mirror_redirect("https://bugs.php.net/?$array[1]");
40}
41
42// ============================================================================
43// FC: handle advisories
44if (preg_match("!^security/advisories/PHPSA-(\\d+)\\.php$!", $URI, $array)) {
45    status_header(200);
46    $_GET["id"] = $array[1];
47    include_once __DIR__ . '/security/index.php';
48    exit;
49}
50
51// ============================================================================
52// Omit query string from URL and urldecode special chars
53$URI = urldecode(preg_replace("!(\\?.*$)!", "", $URI));
54
55// ============================================================================
56// An empty URI is useless at this point, so let's give them the search page
57if (empty($URI)) {
58    mirror_redirect("/search.php");
59}
60
61// ============================================================================
62// Perform a redirect for manual figures, other images display a 404 automatically
63if (preg_match("!^manual/(\\w+)/(print|printwn)/figures/(.+)$!", $URI, $parts)) {
64    mirror_redirect("/manual/$parts[1]/figures/$parts[3]");
65} elseif (preg_match("!\\.(pdf|gif|jpg|png)$!i", $URI)) {
66    error_404();
67}
68
69// ============================================================================
70// BC: handle .php3 files that were renamed to .php
71if (preg_match("!(.*\\.php)3$!", $URI, $array)) {
72    mirror_redirect("/$array[1]");
73}
74
75// ============================================================================
76// BC: handle moving english manual down into its own directory (also supports
77//     default language manual accessibility on mirror sites through /manual/filename)
78// @todo do we rely on this? how about removing it...
79if (preg_match("!^manual/([^/]*)$!", $URI, $array)) {
80    if (!isset($INACTIVE_ONLINE_LANGUAGES[$array[1]])) {
81        mirror_redirect("/manual/$LANG/$array[1]");
82    }
83} elseif (preg_match("!^manual/html/([^/]+)$!", $URI, $array)) {
84    $array[1] = preg_replace("!.html$!", ".php", $array[1]);
85    mirror_redirect("/manual/$LANG/$array[1]");
86}
87
88// ============================================================================
89// BC: News archive moved to subfolder
90if (preg_match("!^news-(\\d+)(\\.|$)!", $URI, $array)) {
91    mirror_redirect("/archive/$array[1].php");
92}
93
94// ============================================================================
95// BC: Release files moved to subfolder
96if (preg_match("!^release_([^\\.]+)(\\.php$|$)!", $URI, $array)) {
97    mirror_redirect("/releases/$array[1].php");
98}
99
100// ============================================================================
101// BC: Printer friendly manual page handling was separate previously, but we
102// only need to redirect the old URLs now. Our pages are now printer friendly
103// by design.
104if (preg_match("!^manual/(\\w+)/(print|printwn|html)((/.+)|$)!", $URI, $array)) {
105    $array[3] = preg_replace("!.html$!", ".php", $array[3]);
106    mirror_redirect("/manual/$array[1]$array[3]");
107}
108
109// ============================================================================
110// If someone is looking for something in distributions/* and it isn't there,
111// send them to the /releases page since that is likely to be most helpful.
112if (preg_match("!^distributions/.*!", $URI, $array)) {
113    status_header(404);
114    include_once __DIR__ . "/releases/index.php";
115}
116
117// ============================================================================
118// The trailing slash only causes problems from now on
119$URI = rtrim($URI, '/');
120
121// ============================================================================
122// Some nice URLs for getting something for download
123if (preg_match("!^get/([^/]+)$!", $URI, $what)) {
124    switch ($what[1]) {
125        case "php":
126            $URI = "downloads";
127            break;
128        case "docs": // intentional
129        case "documentation":
130            $URI = "download-docs";
131            break;
132    }
133}
134
135// ============================================================================
136// Nice URLs for download files, so wget works completely well with download links
137if (preg_match("!^get/([^/]+)/from/([^/]+)(/mirror)?$!", $URI, $dlinfo)) {
138
139    $df = $dlinfo[1];
140    if (strpos($df, "7-LATEST") !== false) {
141        include_once __DIR__ . "/include/version.inc";
142        [$latest] = release_get_latest();
143        $df = str_replace("7-LATEST", $latest, $df);
144    }
145
146    $mr = "https://www.php.net/";
147
148    // Check if that mirror really exists if not, bail out
149    if (!isset($MIRRORS[$mr])) {
150        error_nomirror($mr);
151        exit;
152    }
153
154    // Start the download process
155    include __DIR__ . "/include/do-download.inc";
156    $filename = get_actual_download_file($df);
157    if ($filename) {
158        status_header(200);
159        download_file($mr, $filename);
160    } else {
161        status_header(404);
162        /* The file didn't exist on this server.. ask the user to pick another mirror */
163        include __DIR__ . "/include/get-download.inc";
164    }
165    exit;
166}
167
168// php.net/42 --> likely a bug number
169if (is_numeric($URI)) {
170    mirror_redirect("http://bugs.php.net/bug.php?id=$URI");
171}
172
173// php.net/GH-123 -> php-src GH issue #123
174if (preg_match('/^GH-(\d+)$/', $URI, $matches)) {
175    mirror_redirect("https://github.com/php/php-src/issues/" . $matches[1]);
176}
177
178// ============================================================================
179// Redirect if the entered URI was a PHP page name (except some pages,
180// which we display in the mirror's language or the explicitly specified
181// language [see below])
182if (!in_array($URI, ['mirror-info', 'error', 'mod'], true) &&
183    file_exists($_SERVER['DOCUMENT_ROOT'] . "/$URI.php")) {
184    mirror_redirect("/$URI.php");
185}
186
187// Work with lowercased URI from now
188$URI = strtolower($URI);
189
190// Redirection hack, see error.inc for detailed description
191// These expect -foo not _foo
192$term = str_replace('_', '-', $URI);
193
194if ($path = is_known_ini($term)) {
195    status_header(301);
196    mirror_redirect("/manual/$LANG/$path");
197    exit;
198}
199if ($path = is_known_variable($term)) {
200    status_header(301);
201    mirror_redirect("/manual/$LANG/$path");
202    exit;
203}
204if ($path = is_known_term($term)) {
205    status_header(301);
206    mirror_redirect("/manual/$LANG/$path");
207    exit;
208}
209
210// ============================================================================
211// Major manual page modifications (need to handle shortcuts and pages in all languages)
212// Used permanent HTTP redirects, so search engines will be able to pick up the correct
213// new URLs for these pages.
214$manual_page_moves = [
215    // entry point changed
216    'installation' => 'install',
217
218    // was split among platforms (don't know where to redirect)
219    'install.apache' => 'install',
220    'install.apache2' => 'install',
221    'install.netscape-enterprise' => 'install',
222    'install.otherhttpd' => 'install',
223
224    // moved to platform sections
225    'install.caudium' => 'install.unix.caudium',
226    'install.commandline' => 'install.unix.commandline',
227    'install.fhttpd' => 'install.unix.fhttpd',
228    'install.hpux' => 'install.unix.hpux',
229    'install.iis' => 'install.windows.iis',
230    'install.linux' => 'install.unix',
231    'install.omnihttpd' => 'install.windows.omnihttpd',
232    'install.openbsd' => 'install.unix.openbsd',
233    'install.sambar' => 'install.windows.sambar',
234    'install.solaris' => 'install.unix.solaris',
235    'install.xitami' => 'install.windows.xitami',
236    'install.windows.installer.msi' => 'install.windows',
237    'install.windows.installer' => 'install.windows',
238
239    // Internals docs where moved
240    'zend' => 'internals2.ze1.zendapi',
241    'zend-api' => 'internals2.ze1.zendapi',
242    'internals.pdo' => 'internals2.pdo',
243    'phpdevel' => 'internals2.ze1.php3devel',
244    'tsrm' => 'internals2.ze1.tsrm',
245
246    // Replaced extensions
247    'aspell' => 'pspell',
248
249    // Refactored
250    'regexp.reference' => 'regexp.introduction',
251    "security" => "manual/security",
252];
253
254if (isset($manual_page_moves[$URI])) {
255    status_header(301);
256    mirror_redirect("/" . $manual_page_moves[$URI]);
257} elseif (preg_match("!^manual/([^/]+)/([^/]+).php$!", $URI, $match) &&
258          isset($manual_page_moves[$match[2]])) {
259    status_header(301);
260    mirror_redirect("/manual/$match[1]/" . $manual_page_moves[$match[2]] . ".php");
261}
262
263$manual_redirections = [
264    'class.oci-lob' => 'class.ocilob',
265    'oci-lob.append' => 'ocilob.append',
266    'oci-lob.close' => 'ocilob.close',
267    'oci-lob.eof' => 'ocilob.eof',
268    'oci-lob.erase' => 'ocilob.erase',
269    'oci-lob.export' => 'ocilob.export',
270    'oci-lob.flush' => 'ocilob.flush',
271    'oci-lob.free' => 'ocilob.free',
272    'oci-lob.getbuffering' => 'ocilob.getbuffering',
273    'oci-lob.import' => 'ocilob.import',
274    'oci-lob.load' => 'ocilob.load',
275    'oci-lob.read' => 'ocilob.read',
276    'oci-lob.rewind' => 'ocilob.rewind',
277    'oci-lob.save' => 'ocilob.save',
278    'oci-lob.seek' => 'ocilob.seek',
279    'oci-lob.setbuffering' => 'ocilob.setbuffering',
280    'oci-lob.size' => 'ocilob.size',
281    'oci-lob.tell' => 'ocilob.tell',
282    'oci-lob.truncate' => 'ocilob.truncate',
283    'oci-lob.write' => 'ocilob.write',
284    'oci-lob.writetemporary' => 'ocilob.writetemporary',
285    'class.oci-collection' => 'class.ocicollection',
286    'oci-collection.append' => 'ocicollection.append',
287    'oci-collection.assign' => 'ocicollection.assign',
288    'oci-collection.assignelem' => 'ocicollection.assignelem',
289    'oci-collection.free' => 'ocicollection.free',
290    'oci-collection.getelem' => 'ocicollection.getelem',
291    'oci-collection.max' => 'ocicollection.max',
292    'oci-collection.size' => 'ocicollection.size',
293    'oci-collection.trim' => 'ocicollection.trim',
294    'splstack.setiteratormode' => 'spldoublylinkedlist.setiteratormode',
295    'splqueue.setiteratormode' => 'spldoublylinkedlist.setiteratormode',
296    'class.allow-dynamic-properties' => 'class.allowdynamicproperties',
297    'class.return-type-will-change' => 'class.returntypewillchange',
298    'class.sensitive-parameter' => 'class.sensitiveparameter',
299    'function.curl-file-create' => 'curlfile.construct',
300    'simplexmliterator.current' => 'simplexmlelement.current',
301    'simplexmliterator.getchildren' => 'simplexmlelement.getchildren',
302    'simplexmliterator.haschildren' => 'simplexmlelement.haschildren',
303    'simplexmliterator.key' => 'simplexmlelement.key',
304    'simplexmliterator.next' => 'simplexmlelement.next',
305    'simplexmliterator.rewind' => 'simplexmlelement.rewind',
306    'simplexmliterator.valid' => 'simplexmlelement.valid',
307];
308
309if (preg_match("!^manual/([^/]+)/([^/]+?)(?:\.php)?$!", $URI, $match) && isset($manual_redirections[$match[2]])) {
310    status_header(301);
311    mirror_redirect("/manual/$match[1]/" . $manual_redirections[$match[2]]);
312}
313
314// ============================================================================
315// Define shortcuts for PHP files, manual pages and external redirects
316$uri_aliases = [
317
318    # PHP page shortcuts
319    "download" => "downloads",
320    "getphp" => "downloads",
321    "getdocs" => "download-docs",
322    "documentation" => "docs",
323    "mailinglists" => "mailing-lists",
324    "mailinglist" => "mailing-lists",
325    "changelog" => "ChangeLog-8",
326    "gethelp" => "support",
327    "help" => "support",
328    "unsubscribe" => "unsub",
329    "subscribe" => "mailing-lists",
330    "logos" => "download-logos",
331
332    # manual shortcuts
333    "intro" => "introduction",
334    "whatis" => "introduction",
335    "whatisphp" => "introduction",
336    "what_is_php" => "introduction",
337
338    "windows" => "install.windows",
339    "win32" => "install.windows",
340
341    "globals" => "language.variables.predefined",
342    "register_globals" => "security.globals",
343    "registerglobals" => "security.globals",
344    "manual/en/security.registerglobals.php" => "security.globals", // fix for 4.3.8 configure
345    "magic_quotes" => "security.magicquotes",
346    "magicquotes" => "security.magicquotes",
347    "gd" => "image",
348    "bcmath" => "bc",
349    'streams' => 'book.stream',
350    "mongodb" => "set.mongodb",
351    "hrtime" => "function.hrtime", // Prefer function over PECL ext
352
353    "callback" => "language.pseudo-types",
354    "number" => "language.pseudo-types",
355    "mixed" => "language.pseudo-types",
356    "bool" => "language.types.boolean",
357    "boolean" => "language.types.boolean",
358    "int" => "language.types.integer",
359    "integer" => "language.types.integer",
360    "float" => "language.types.float",
361    "string" => "language.types.string",
362    "heredoc" => "language.types.string",
363    "<<<" => "language.types.string",
364    "object" => "language.types.object",
365    "null" => "language.types.null",
366    'callable' => 'language.types.callable',
367
368    "htaccess" => "configuration.changes",
369    "php_value" => "configuration.changes",
370
371    "ternary" => "language.operators.comparison",
372    "instanceof" => "language.operators.type",
373    "if" => "language.control-structures",
374    "static" => "language.variables.scope",
375    "global" => "language.variables.scope",
376    "@" => "language.operators.errorcontrol",
377    "&" => "language.references",
378    "**" => "language.operators.arithmetic",
379    "..." => "functions.arguments",
380    "splat" => "functions.arguments",
381    "arrow" => "functions.arrow",
382    "fn" => "functions.arrow",
383    // ?:, ??, ??=
384    // These shortcuts can not be captured here since they
385    // don't actually produce a 404 error.
386    // Instead, we have a small check in index.php directly.
387
388    "dowhile" => "control-structures.do.while",
389
390    "tut" => "tutorial",
391    "tut.php" => "tutorial", // BC
392
393    "faq.php" => "faq",      // BC
394    "bugs.php" => "bugs",     // BC
395    "bugstats.php" => "bugstats", // BC
396    "docs-echm.php" => "download-docs", // BC
397
398    "odbc" => "uodbc", // BC
399
400    "links" => "support", // BC
401    "links.php" => "support", // BC
402    "oracle" => "oci8",
403    "_" => "function.gettext",
404    "cli" => "features.commandline",
405
406    "oop" => "language.oop5",
407    "enum" => "language.enumerations",
408    "enums" => "language.enumerations",
409
410    "const" => "language.constants.syntax",
411    "class" => "language.oop5.basic",
412    "new" => "language.oop5.basic",
413    "extends" => "language.oop5.basic",
414    "clone" => "language.oop5.cloning",
415    "construct" => "language.oop5.decon",
416    "destruct" => "language.oop5.decon",
417    "public" => "language.oop5.visibility",
418    "private" => "language.oop5.visibility",
419    "protected" => "language.oop5.visibility",
420    "var" => "language.oop5.visibility",
421    "abstract" => "language.oop5.abstract",
422    "interface" => "language.oop5.interfaces",
423    "interfaces" => "language.oop5.interfaces",
424    "autoload" => "language.oop5.autoload",
425    "__autoload" => "language.oop5.autoload",
426    "language.oop5.reflection" => "book.reflection", // BC
427    "::" => "language.oop5.paamayim-nekudotayim",
428
429    "__construct" => "language.oop5.decon",
430    "__destruct" => "language.oop5.decon",
431    "__call" => "language.oop5.overloading",
432    "__callstatic" => "language.oop5.overloading",
433    "__get" => "language.oop5.overloading",
434    "__set" => "language.oop5.overloading",
435    "__isset" => "language.oop5.overloading",
436    "__unset" => "language.oop5.overloading",
437    "__sleep" => "language.oop5.magic",
438    "__wakeup" => "language.oop5.magic",
439    "__tostring" => "language.oop5.magic",
440    "__set_state" => "language.oop5.magic",
441    "__debuginfo" => "language.oop5.magic",
442    "__clone" => "language.oop5.cloning",
443
444    "throw" => "language.exceptions",
445    "try" => "language.exceptions",
446    "catch" => "language.exceptions",
447    "lsb" => "language.oop5.late-static-bindings",
448    "namespace" => "language.namespaces",
449    "use" => "language.namespaces.using",
450
451    "factory" => "language.oop5.patterns",
452    "singleton" => "language.oop5.patterns",
453
454    "trait" => "language.oop5.traits",
455    "traits" => "language.oop5.traits",
456
457    "news.php" => "archive/index", // BC
458    "readme.mirror" => "mirroring", // BC
459
460    "php5" => "language.oop5",
461    "zend_changes.txt" => "language.oop5", // BC
462    "zend2_example.phps" => "language.oop5", // BC
463    "zend_changes_php_5_0_0b2.txt" => "language.oop5", // BC
464    "zend-engine-2" => "language.oop5", // BC
465    "zend-engine-2.php" => "language.oop5", // BC
466
467    "news_php_5_0_0b2.txt" => "ChangeLog-5", // BC
468    "news_php_5_0_0b3.txt" => "ChangeLog-5", // BC
469
470    "manual/about-notes.php" => "manual/add-note",   // BC
471    "software/index.php" => "software",          // BC
472    "releases.php" => "releases/index",    // BC
473
474    "migration7" => "migration70",      // Consistent with migration5
475    "update_5_2.txt" => "migration52",      // BC
476    "readme_upgrade_51.php" => "migration51",      // BC
477    "internals" => "internals2",       // BC
478    "configuration.directives" => "ini.core",       // BC
479
480    # regexp. BC
481    "regexp.reference.backslash" => "regexp.reference.escape",
482    "regexp.reference.circudollar" => "regexp.reference.anchors",
483    "regexp.reference.squarebrackets" => "regexp.reference.character-classes",
484    "regexp.reference.verticalbar" => "regexp.reference.alternation",
485
486    # external shortcut aliases ;)
487    "dochowto" => "phpdochowto",
488
489    # CVS -> SVN
490    "anoncvs.php" => "git",
491    "cvs-php.php" => "git-php",
492
493    # SVN -> Git
494    "svn" => "git",
495    "svn.php" => "git",
496    "svn-php" => "git-php",
497    "svn-php.php" => "git-php",
498
499    # CVSUp -> Nada
500    "cvsup" => "mirroring",
501
502    # Other items
503    "security/crypt" => "security/crypt_blowfish",
504
505    # Bugfixes
506    "array_sort" => "sort", // #64743
507    "array-sort" => "sort", // #64743
508
509    # Removed pages
510    "tips.php" => "urlhowto",
511    "tips" => "urlhowto",
512];
513
514$external_redirects = [
515    "php4news" => "https://github.com/php/php-src/raw/PHP-4.4/NEWS",
516    "php5news" => "https://github.com/php/php-src/raw/PHP-5.6/NEWS",
517    "php53news" => "https://github.com/php/php-src/raw/PHP-5.3/NEWS",
518    "php54news" => "https://github.com/php/php-src/raw/PHP-5.4/NEWS",
519    "php55news" => "https://github.com/php/php-src/raw/PHP-5.5/NEWS",
520    "php56news" => "https://github.com/php/php-src/raw/PHP-5.6/NEWS",
521    "php70news" => "https://github.com/php/php-src/raw/PHP-7.0/NEWS",
522    "php71news" => "https://github.com/php/php-src/raw/PHP-7.1/NEWS",
523    "php72news" => "https://github.com/php/php-src/raw/PHP-7.2/NEWS",
524    "php73news" => "https://github.com/php/php-src/raw/PHP-7.3/NEWS",
525    "php74news" => "https://github.com/php/php-src/raw/PHP-7.4/NEWS",
526    "php80news" => "https://github.com/php/php-src/raw/PHP-8.0/NEWS",
527    "phptrunknews" => "https://github.com/php/php-src/raw/master/NEWS",
528    "pear" => "http://pear.php.net/",
529    "bugs" => "https://bugs.php.net/",
530    "bugstats" => "https://bugs.php.net/stats.php",
531    "phpdochowto" => "http://doc.php.net/tutorial/",
532    "rev" => "http://doc.php.net/revcheck.php?p=graph&lang=$LANG",
533    "release/5_3_0.php" => "/releases/5_3_0.php", // PHP 5.3.0 release announcement had a typo
534    "ideas.php" => "http://wiki.php.net/ideas", // BC
535    "releases.atom" => "/releases/feed.php", // BC, No need to pre-generate it
536    "spec" => "https://github.com/php/php-langspec",
537    "sunglasses" => "https://www.youtube.com/watch?v=dQw4w9WgXcQ", // Temporary easter egg for bug#66144
538];
539
540// Temporary hack to fix bug #49956 for mysqli -- Please don't hate me for this. Data taken from mysqli/summary.xml
541$mysqli_redirects = [
542    "mysqli_affected_rows" => "mysqli.affected-rows",
543    "mysqli_get_client_version" => "mysqli.client-version",
544    "mysqli_connect_errno" => "mysqli.connect-errno",
545    "mysqli_connect_error" => "mysqli.connect-error",
546    "mysqli_errno" => "mysqli.errno",
547    "mysqli_error" => "mysqli.error",
548    "mysqli_field_count" => "mysqli.field-count",
549    "mysqli_get_host_info" => "mysqli.host-info",
550    "mysqli_get_proto_info" => "mysqli.protocol-version",
551    "mysqli_get_server_version" => "mysqli.server-version",
552    "mysqli_info" => "mysqli.info",
553    "mysqli_insert_id" => "mysqli.insert-id",
554    "mysqli_sqlstate" => "mysqli.sqlstate",
555    "mysqli_warning_count" => "mysqli.warning-count",
556    "mysqli_autocommit" => "mysqli.autocommit",
557    "mysqli_change_user" => "mysqli.change-user",
558    "mysqli_character_set_name" => "mysqli.character-set-name",
559    "mysqli_close" => "mysqli.close",
560    "mysqli_commit" => "mysqli.commit",
561    "mysqli_connect" => "mysqli.construct",
562    "mysqli_debug" => "mysqli.debug",
563    "mysqli_dump_debug_info" => "mysqli.dump-debug-info",
564    "mysqli_get_charset" => "mysqli.get-charset",
565    "mysqli_get_connection_stats" => "mysqli.get-connection-stats",
566    "mysqli_get_client_info" => "mysqli.get-client-info",
567    "mysqli_get_client_stats" => "mysqli.get-client-stats",
568    "mysqli_get_cache_stats" => "mysqli.get-cache-stats",
569    "mysqli_get_server_info" => "mysqli.get-server-info",
570    "mysqli_get_warnings" => "mysqli.get-warnings",
571    "mysqli_init" => "mysqli.init",
572    "mysqli_kill" => "mysqli.kill",
573    "mysqli_more_results" => "mysqli.more-results",
574    "mysqli_multi_query" => "mysqli.multi-query",
575    "mysqli_next_result" => "mysqli.next-result",
576    "mysqli_options" => "mysqli.options",
577    "mysqli_ping" => "mysqli.ping",
578    "mysqli_prepare" => "mysqli.prepare",
579    "mysqli_query" => "mysqli.query",
580    "mysqli_real_connect" => "mysqli.real-connect",
581    "mysqli_real_escape_string" => "mysqli.real-escape-string",
582    "mysqli_real_query" => "mysqli.real-query",
583    "mysqli_refresh" => "mysqli.refresh",
584    "mysqli_rollback" => "mysqli.rollback",
585    "mysqli_select_db" => "mysqli.select-db",
586    "mysqli_set_charset" => "mysqli.set-charset",
587    "mysqli_set_local_infile_default" => "mysqli.set-local-infile-default",
588    "mysqli_set_local_infile_handler" => "mysqli.set-local-infile-handler",
589    "mysqli_ssl_set" => "mysqli.ssl-set",
590    "mysqli_stat" => "mysqli.stat",
591    "mysqli_stmt_init" => "mysqli.stmt-init",
592    "mysqli_store_result" => "mysqli.store-result",
593    "mysqli_thread_id" => "mysqli.thread-id",
594    "mysqli_thread_safe" => "mysqli.thread-safe",
595    "mysqli_use_result" => "mysqli.use-result",
596    "mysqli_stmt_affected_rows" => "mysqli-stmt.affected-rows",
597    "mysqli_stmt_errno" => "mysqli-stmt.errno",
598    "mysqli_stmt_error" => "mysqli-stmt.error",
599    "mysqli_stmt_field_count" => "mysqli-stmt.field-count",
600    "mysqli_stmt_insert_id" => "mysqli-stmt.insert-id",
601    "mysqli_stmt_param_count" => "mysqli-stmt.param-count",
602    "mysqli_stmt_sqlstate" => "mysqli-stmt.sqlstate",
603    "mysqli_stmt_attr_get" => "mysqli-stmt.attr-get",
604    "mysqli_stmt_attr_set" => "mysqli-stmt.attr-set",
605    "mysqli_stmt_bind_param" => "mysqli-stmt.bind-param",
606    "mysqli_stmt_bind_result" => "mysqli-stmt.bind-result",
607    "mysqli_stmt_close" => "mysqli-stmt.close",
608    "mysqli_stmt_data_seek" => "mysqli-stmt.data-seek",
609    "mysqli_stmt_execute" => "mysqli-stmt.execute",
610    "mysqli_stmt_fetch" => "mysqli-stmt.fetch",
611    "mysqli_stmt_free_result" => "mysqli-stmt.free-result",
612    "mysqli_stmt_get_result" => "mysqli-stmt.get-result",
613    "mysqli_stmt_get_warnings" => "mysqli-stmt.get-warnings",
614    "mysqli_stmt_more_results" => "mysqli-stmt.more-results",
615    "mysqli_stmt_next_result" => "mysqli-stmt.next-result",
616    "mysqli_stmt_num_rows" => "mysqli-stmt.num-rows",
617    "mysqli_stmt_prepare" => "mysqli-stmt.prepare",
618    "mysqli_stmt_reset" => "mysqli-stmt.reset",
619    "mysqli_stmt_result_metadata" => "mysqli-stmt.result-metadata",
620    "mysqli_stmt_send_long_data" => "mysqli-stmt.send-long-data",
621    "mysqli_stmt_store_result" => "mysqli-stmt.store-result",
622    "mysqli_field_tell" => "mysqli-result.current-field",
623    "mysqli_num_fields" => "mysqli-result.field-count",
624    "mysqli_fetch_lengths" => "mysqli-result.lengths",
625    "mysqli_num_rows" => "mysqli-result.num-rows",
626    "mysqli_data_seek" => "mysqli-result.data-seek",
627    "mysqli_fetch_all" => "mysqli-result.fetch-all",
628    "mysqli_fetch_array" => "mysqli-result.fetch-array",
629    "mysqli_fetch_assoc" => "mysqli-result.fetch-assoc",
630    "mysqli_fetch_field_direct" => "mysqli-result.fetch-field-direct",
631    "mysqli_fetch_field" => "mysqli-result.fetch-field",
632    "mysqli_fetch_fields" => "mysqli-result.fetch-fields",
633    "mysqli_fetch_object" => "mysqli-result.fetch-object",
634    "mysqli_fetch_row" => "mysqli-result.fetch-row",
635    "mysqli_field_seek" => "mysqli-result.field-seek",
636    "mysqli_free_result" => "mysqli-result.free",
637    "mysqli_embedded_server_end" => "mysqli-driver.embedded-server-end",
638    "mysqli_embedded_server_start" => "mysqli-driver.embedded-server-start",
639];
640
641// Merge this temporary hack with $uri_aliases so it'll be treated as such
642$uri_aliases = array_merge($uri_aliases, $mysqli_redirects);
643
644// ============================================================================
645// "Rewrite" the URL, if it was a shortcut
646
647if (isset($uri_aliases[$URI])) {
648    $URI = $uri_aliases[$URI];
649    /* If it was a page alias, redirect right away */
650    if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/$URI.php")) {
651        mirror_redirect("/$URI.php");
652    }
653}
654
655// ============================================================================
656// Execute external redirect if a rule exists for the URI
657if (isset($external_redirects[$URI])) {
658    mirror_redirect($external_redirects[$URI]);
659}
660
661// Temporary hack for mirror-info, until all the pages
662// will be capable of being included from anywhere
663if ($URI == 'mirror-info') {
664    status_header(200);
665    include_once __DIR__ . "/$URI.php";
666    exit;
667}
668
669// ============================================================================
670// Try to find the page using the preferred language as a manual page
671include_once __DIR__ . "/include/manual-lookup.inc";
672$try = find_manual_page($LANG, $URI);
673if ($try) {
674    status_header(200);
675    include_once __DIR__ . $try;
676    exit;
677}
678// BC. The class methods are now classname.methodname
679if (preg_match("!^manual/(.+)/function\.(.+)-(.+).php$!", $URI, $array)) {
680    $try = find_manual_page($array[1], $array[2] . "." . $array[3]);
681    if ($try) {
682        status_header(301);
683        mirror_redirect($try);
684        exit;
685    }
686}
687
688// ============================================================================
689// For manual pages for inactive languages, point visitors to the English page
690if (preg_match("!^manual/([^/]+)/([^/]+).php$!", $URI, $match) &&
691    isset($INACTIVE_ONLINE_LANGUAGES[$match[1]])) {
692    $try = find_manual_page("en", $match[2]);
693    if ($try) {
694        error_inactive_manual_page($INACTIVE_ONLINE_LANGUAGES[$match[1]], $try);
695    }
696}
697
698// ============================================================================
699// 404 page for manual pages (eg. not built language)
700if (strpos($URI, "manual/") === 0) {
701    $legacy_manual_urls = get_legacy_manual_urls($URI);
702    if (count($legacy_manual_urls) > 0) {
703        fallback_to_legacy_manuals($legacy_manual_urls);
704    }
705    error_404_manual();
706}
707
708// ============================================================================
709// If no match was found till this point, the last action is to start a
710// search with the URI the user typed in
711$fallback = (myphpnet_urlsearch() === MYPHPNET_URL_MANUAL ? "404manual" : "404quickref");
712mirror_redirect(
713    '/search.php?show=' . $fallback . '&lang=' . urlencode($LANG) .
714    '&pattern=' . substr($_SERVER['REQUEST_URI'], 1),
715);
716