Reputation: 2361
I have this problem. FOr example I have this URL http://site-myname.testingsite.localhost/auth/register?r=, uwing $_SERVER['REQUEST_URI'] I am able to get the value 'auth/register?r='. Now what I want to do is to check using regex and preg_match '/auth/register?r=' or '/auth/register?r=anyvalue' so that if any user who will have query string 'r' with any value or null value will be under scope.
My initial solution is:
preg_match('#/auth/register\?r=^$#', $_SERVER['REQUEST_URI'])
But it doesn't seem to work. Please help me! I'm stuck in this problem for an hour now and I don't want to waste time.. Answers will be much appreciated, thanks!
Upvotes: 0
Views: 60
Reputation: 116
Try this, it validates for me:
$uri = $_SERVER['REQUEST_URI'];
$strRegex = '%/auth/register\?r=%';
if (preg_match($strRegex, $uri)) echo "matched";
else echo "not matched";
Upvotes: 0
Reputation: 13914
Not entirely sure that I follow the question, but it seems what you want is just
^/auth/register\?r=
if you're trying to capture the value of r
perhaps…
^/auth/register\?r=([^;&]*)
Upvotes: 0
Reputation: 91373
Have a try with:
preg_match('#/auth/register\?r=[^&]*#', $_SERVER['REQUEST_URI'])
Upvotes: 1