我是php的新手,我需要的小帮助
我正在php中创建一个名为index.php的页面
我希望当有人自动查看该页面时,一个数字或任何东西都会添加到url端的
Like www.abc.com/index.php ---> www.abc.com/index.php?abc or ?132
当刷新索引页时,它应该在最后的中获得一个数字或任何变量
试试这个:
<?php
if (!isset($_GET["123"])) {
header("Location: " . $_SERVER["PHP_SELF"] ."?123");
}
$QS = $_SERVER["QUERY_STRING"];
$URL = "http://www.example.com/index.php";
// Check if Anything already assigned
if( empty($QS) ) {
// Generate Any RANDOM Number Here
$NUM = mt_rand(999, 9999);
// Reload Page and assign number
header("Location: {$URL}?{$NUM}");
}
将此代码放在页面的最顶部
试试
<?php
$num = '123';
if(!isset($_GET[$num])){
header("Location: /path/to/page?$num");
}