Use PHP_SELF, return source on ?source

main
Pk11 3 years ago
parent 9f6ff42c88
commit cda52b7a66

@ -1,30 +1,36 @@
<?php /*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
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
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
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
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/ ?>
<?php
/* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* 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
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* 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
* OTHER DEALINGS IN THE SOFTWARE.
*
* 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>
<html lang="ja">
<head>
@ -46,9 +52,6 @@
</head>
<body>
<?php
// このページのURL
$self = "https://nextrip.xn--rck9c.xn--tckwe/";
// formの変数
$stop = $_GET['stop'];
$favSet = $_POST['fav-set'];
@ -58,10 +61,10 @@
<header>
<nav class="navbar navbar-light bg-light">
<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">
<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>
</ul>
</div>
@ -106,7 +109,7 @@
// お気に入りフォームをプリント
$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 '<div class="input-group">';
echo '<label for="desc" class="input-group-text">お気に入り</label>';
@ -119,7 +122,7 @@
}
} else { // HPを表示
// 停留所フォームをプリント
echo "<form method=\"get\" action=\"$self\">";
echo '<form method="get" action="' . $_SERVER['PHP_SELF'] . '">';
echo '<div class="input-group mb-3">';
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>';
@ -151,7 +154,7 @@
// お気に入りがある場合、プリント
if(count($favorites) > 0) {
echo '<h2>お気に入り</h2>';
echo "<form action=\"$self\">";
echo '<form action="' . $_SERVER['PHP_SELF'] . '">';
echo '<ul class="list-unstyled">';
foreach($favorites as $favStop => $favDesc) {
echo '<li class="mb-1 d-flex">';

Loading…
Cancel
Save