$v) { if ($newstring == $k) return mkstring(); } return $newstring; } // パラメートルがなければ、スキップ。 if (isset($_POST['sosin'])) { $newadd = $_POST['newadd']; if (!str_starts_with($newadd, 'http://') && !str_starts_with($newadd, 'https://')) { $title .= '〜'.LOC_FUSEINA_URL; $err = LOC_ERROR_URL_HTTP_HTTPS; include_once('../views/404.php'); exit; } if (strlen($newadd) > 500) { $title .= '〜'.LOC_FUSEINA_URL; $err = 'URLは500文字以内です。'; include_once('../views/404.php'); exit; } $data = file_get_contents('links.json'); $arr = json_decode($data, true); foreach ($arr as $k => $v) { if ($newadd == $v) { if (isset($_POST['api']) && $_POST['api'] == 1) { header('Content-Type: application/json'); echo json_encode(['res' => $k]); } else header('Location: /?newurl='.$k); exit; } } $newstring = mkstring(); $arr[$newstring] = $newadd; $newdata = json_encode($arr); file_put_contents('links.json', $newdata); if (isset($_POST['api']) && $_POST['api'] == 1) { header('Content-Type: application/json'); echo json_encode(['res' => $newstring]); } else header('Location: /?newurl='.$newstring); exit; } else if (!isset($_GET['url']) && isset($_GET['newurl'])) { $title .= '〜'.LOC_TANSYUKUZUMI; $newurl = $_GET['newurl']; include_once('../views/submitted.php'); } else if (isset($_GET['url']) && $_GET['url'] != '') { $data = file_get_contents('links.json'); foreach (json_decode($data) as $k => $v) { // jsonファイルでキーを見つければ、転送されます。なければ、404エラーが出ます。 if ($_GET['url'] == $k) { if (isset($_GET['api']) && $_GET['api'] == 1) { header('Content-Type: application/json'); echo json_encode(['res' => $v]); } else header('Location: '.$v); exit; } else { $title .= '〜'.LOC_MIKENSYUTU; $err = LOC_ERROR_URL_MITUKAREMASEN; include_once('../views/404.php'); } } } else if (!isset($_GET['url']) && $_SERVER['REQUEST_URI'] == '/') { $title .= '〜'.LOC_TOP; include_once('../views/index.php'); } else { $title .= '〜'.LOC_MIKENSYUTU; $err = LOC_ERROR_URL_MITUKAREMASEN; include_once('../views/404.php'); } ?>