Use PHP_SELF, return source on ?source

main
Pk11 3 years ago
parent 9f6ff42c88
commit cda52b7a66

@ -1,30 +1,36 @@
<?php /* <?php
This is free and unencumbered software released into the public domain. /* This is free and unencumbered software released into the public domain.
*
Anyone is free to copy, modify, publish, use, compile, sell, or * Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled * distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any * binary, for any purpose, commercial or non-commercial, and by any
means. * means.
*
In jurisdictions that recognize copyright laws, the author or authors * In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the * of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit * software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and * of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of * successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this * relinquishment in perpetuity of all present and future rights to this
software under copyright law. * software under copyright law.
*
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*
For more information, please refer to <http://unlicense.org/> * For more information, please refer to <http://unlicense.org/>
*/ ?> */
// Return source code
if(isset($_GET['source'])) {
header("Content-Type: text/plain");
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ja"> <html lang="ja">
<head> <head>
@ -46,9 +52,6 @@
</head> </head>
<body> <body>
<?php <?php
// このページのURL
$self = "https://nextrip.xn--rck9c.xn--tckwe/";
// formの変数 // formの変数
$stop = $_GET['stop']; $stop = $_GET['stop'];
$favSet = $_POST['fav-set']; $favSet = $_POST['fav-set'];
@ -58,10 +61,10 @@
<header> <header>
<nav class="navbar navbar-light bg-light"> <nav class="navbar navbar-light bg-light">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="<?php echo $self; ?>">停留所のNexTrip情報</a> <a class="navbar-brand" href="<?php echo $_SERVER['PHP_SELF']; ?>">停留所のNexTrip情報</a>
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="https://gist.github.com/Epicpkmn11/6e60adbf3475277b753b259ab02a53cd" target="_blank">ソース</a> <a class="nav-link" href="?source">ソース</a>
</li> </li>
</ul> </ul>
</div> </div>
@ -106,7 +109,7 @@
// お気に入りフォームをプリント // お気に入りフォームをプリント
$favDesc = json_decode($_COOKIE['favorites'], true)[$stop]; $favDesc = json_decode($_COOKIE['favorites'], true)[$stop];
echo "<form method=\"post\" action=\"$self\">"; echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
echo "<input type=\"hidden\" name=\"fav-set\" value=\"$stop\">"; echo "<input type=\"hidden\" name=\"fav-set\" value=\"$stop\">";
echo '<div class="input-group">'; echo '<div class="input-group">';
echo '<label for="desc" class="input-group-text">お気に入り</label>'; echo '<label for="desc" class="input-group-text">お気に入り</label>';
@ -119,7 +122,7 @@
} }
} else { // HPを表示 } else { // HPを表示
// 停留所フォームをプリント // 停留所フォームをプリント
echo "<form method=\"get\" action=\"$self\">"; echo '<form method="get" action="' . $_SERVER['PHP_SELF'] . '">';
echo '<div class="input-group mb-3">'; echo '<div class="input-group mb-3">';
echo '<label for="stop" class="input-group-text">停留所</label>'; echo '<label for="stop" class="input-group-text">停留所</label>';
echo '<input type="number" min="0" id="stop" name="stop" class="form-control" placeholder="12345" required>'; echo '<input type="number" min="0" id="stop" name="stop" class="form-control" placeholder="12345" required>';
@ -151,7 +154,7 @@
// お気に入りがある場合、プリント // お気に入りがある場合、プリント
if(count($favorites) > 0) { if(count($favorites) > 0) {
echo '<h2>お気に入り</h2>'; echo '<h2>お気に入り</h2>';
echo "<form action=\"$self\">"; echo '<form action="' . $_SERVER['PHP_SELF'] . '">';
echo '<ul class="list-unstyled">'; echo '<ul class="list-unstyled">';
foreach($favorites as $favStop => $favDesc) { foreach($favorites as $favStop => $favDesc) {
echo '<li class="mb-1 d-flex">'; echo '<li class="mb-1 d-flex">';

Loading…
Cancel
Save