-2

I have this url: http:www.blabla.com/x/x/x/x?username=testuser I need a string to read this url, but forget everything and including the ? mark. So it becomes this: http:www.blabla.com/x/x/x/x

The reason for this is because I am making this variable:

$host = $_SERVER['SERVER_NAME']  . $_SERVER['REQUEST_URI'];

And this code:

if($host == "http:www.blabla.com/x/x/x/x") {
    echo "lul";
}

But right now, the URL changes depending on what user is on, and it has to execute the echo no matter what user is on.

So I read some reges and preg_match etc. and I just wanted to hear your opinions or advice. How would I accomblish this the best? thanks!

owwyess
  • 165
  • 14

2 Answers2

0

Or if you must omit the get / request section just explode ? and use $host[0]

alexisdevarennes
  • 5,165
  • 3
  • 23
  • 37
0

This is too trivial of a task for regex.

$host = $_SERVER['SERVER_NAME'] . explode("?", $_SERVER['REQUEST_URI'], 2)[0];

(Note: this assumes you're up-to-date, or at least using PHP 5.4, for the dereference to work without a temporary variable)

Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566