php - 我想在我的 URL 后面创建一个唯一的 id 并在其上回显一个页面怎么做?
问题描述
我有一个表格,网址是例如:www.site.com/index.php
. 但是当我单击表单按钮时,我希望它创建一个这样的链接www.site.com/index.php?1wejf23912
,然后在其上回显一个页面,您可以在其中输入用户名和密码。如何执行此操作并从示例页面上的该页面获取输入,例如www.site.com/index.php
.
谢谢您的帮助。
<?php
require 'includes/header.php';
?>
<main>
<form action="includes/create-page.inc.php">
<button type="submit" name="create-submit" id="create-submit">Create Link
With Page</button>
</form>
<div class="show-input">
<a href="new-link">This is your link: <?php echo $newLink; ?></a>
...input from created page
<button type="submit" name="delete-url" id="delete-url">Delete New URL</button>
</div>
</main>
<?php
require 'includes/footer.php';
?>
解决方案
创建一个文件夹c,您将添加它。
<?php
function randomURL() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
$rpass = randomURL();
echo "<h2>You link is <a target='_blank' href='/c/". $rpass. "'>". $_SERVER["REQUEST_SCHEME"]. "://". $_SERVER["HTTP_HOST"]. "/c/";
echo $rpass;
echo "</a></h2>";
$myfile = fopen("../c/". $rpass .".php", "w") or die("Unable to create file!");
$txt = "Your text or variable or php code" ."\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
在c文件夹中使用 .htaccess 。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
谢谢
推荐阅读
- python - 在 python 中将生成器转换为 Numpy 数组
- python - 如何将 Plotly 升级到最新版本?
- python - 无法使用导出导出 Yolov5 模型
- ansible - Ansible Inventory:如何从不在某些其他组中的主机构建组
- javascript - Oracle APEX 警告消息
- r - 如何在函数中使用包含多个变量的选择?
- reactjs - 类型对象上不存在属性“过滤器”
- bootstrap-5 - 未捕获的类型错误:z.fn.dropdown 未定义
- macos - 您应该如何在 Metal 中正确编码大量 blit 或缩放命令?
- javascript - 如何覆盖html表中的数据并将此数据导出到现有的excel文件