LoginSignup
1
0

More than 1 year has passed since last update.

phpで現在のURLを取得する関数を作った。

Posted at

はじめに

phpで現在作動しているファイルのURLを取得する関数を作りました。

コード

function now_url($status = 0){
    if($status === 0){
        return (((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ) ? "https://" : "http://").$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }else if($status === 1){
        return strtok((((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ) ? "https://" : "http://").$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], '?');
    }
})

使い方

クエリ文字列あり

now_url(0);

クエリ文字列無し

now_url(1);

終わりに

便利だよね?ね?

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0