1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

1人コンプAdvent Calendar 2022

Day 19

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?