我有一个表格,URL例如: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';
?>
答案 0 :(得分:0)
创建一个文件夹 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]
谢谢