开发者

PHP $_SERVER and urls?

开发者 https://www.devze.com 2023-04-11 18:38 出处:网络
How can I get my full current url in php but minus all querystrings? Example echo \'http://\' . $_SERVER[\'SERVER_NAME\'] . $_SERVER[\'REQUEST_URI\'];

How can I get my full current url in php but minus all querystrings?

Example

echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

Would echo something like assuming query strings were in place...

http://www.example.com/example?tab=foo&dslip=yes

How can I get the same as above but cut off all the query strings?

How is this done in 开发者_高级运维php.

Thanks.


PHP_SELF is what you need I believe.

echo('http' . ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? '' : 's') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);

Or the __FILE__ constant, depending on your exact configuration and situation.


Try this

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

$part = explode('?',$url);

echo $part[0];


I think the solution is this:

echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];

the $_SERVER['SCRIPT_NAME'] variable returns path of your script without the query string like you want.

if you like to see all variables available in php just try this

phpinfo();

Best regards

0

精彩评论

暂无评论...
验证码 换一张
取 消