如何让链接在页面上加载一个随机的 php ID? [英] How can I make a link load a random php ID on the page?

查看:51
本文介绍了如何让链接在页面上加载一个随机的 php ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库行 ID 与 URL 相关联,如下所示:

Database row IDs are tied to the URLs like this:

第 2 行 的页面变为site.com/index.php?id=2

如果我手动刷新index.php,它会显示随机记录,但自然不会在地址栏中显示记录ID.

If I manually refresh index.php it displays a random record, but naturally it doesn't display the record ID in the address bar.

有没有办法让链接显示随机记录,同时在地址栏中显示 id 变化?

Is there a way to make a link display a random record while showing the id change in the address bar?

感谢您的帮助!

推荐答案

与其只显示随机记录,不如选择记录的 id 并重定向到显示该 id 的版本.

Instead of just showing the random record, choose the record's id and do a redirect to the version that shows the id.

$randomId = // whatever method you use to choose it
header( "Location: http://site.com/index.php?id=$randomId" );

这篇关于如何让链接在页面上加载一个随机的 php ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆