Your problem is you are saying "begins with and ends with ONLY", and only ONE DIGIT. Look:
*****.com/223
***.com/48
<?php if (preg_match("^[0-9]$", $_SERVER['QUERY_STRING'])) include("load.php");?>
^ This means "the string starts with"
$ this means "the string ends with"
And it's
one number, and only one number. Add the + quantifier for "one or more." (* means zero or more, which becomes important in a minute . . . )
Note that 0-9 and \d are equivalent, you don't need a class [] if you use \d.
A quick fix, remove the ^, add the +.
<?php if (preg_match('/\d+$/', $_SERVER['QUERY_STRING'])) include("load.php");?>
This would mean "only ends with one or more numbers." But there may be other problems, some browsers add / on the end in links, and there may be some condition where a digit may appear and mess up your scheme, like testversion2 or something. A little more specific, insuring it matches only on numbers after the last /,
<?php if (preg_match(
'/[^\/]+\/\d+\/*$/', $_SERVER['QUERY_STRING'])) include("load.php");?>
Should work for
example.com/something/something-else/1234
example.com/something/something-else/1234/
example.com/1234
example.com/1234/
I know I said lose the ^, but that character has different meanings in different contexts. By itself, at the beginning of a pattern, it means "string begins with" but within a class, if the first character in the class, it means "anything NOT these." So an examination,
[^\/]+ --> one or more of any character NOT a slash
\/ --> followed by a single slash
\d+ --> followed by one or more digits
\/* --> followed by ZERO or more slashes
$ --> followed by the absolute end of the string.