dongliang1223 2012-10-04 17:35
浏览 47
已采纳

我需要根据输入的代码将用户重定向到另一个页面

I need to create a form on my site where users enter a code and based on that code they're redirected to another page. Doing it through a database would be more secure but I wouldn't mind if the logic was handled on the form itself.

So, here's an example of what I mean:

Enter Code: (Box here)

Form searches through list of potential answers( s5d11, wy4sd, lk123, etc.), if it finds a match it redirects to a specific page for each code, if not it gives an error message that the code entered was wrong.

  • 写回答

2条回答 默认 最新

  • dongtang4954 2012-10-04 17:38
    关注

    This is an example with two files, one html and one php file. The html-page submits the contents of your input to a php-page, which redirects the browser to an URL based on the input.

    HTML, index.html:

    <form action="redirect.php" method="get">
      <input name="mytext" />
      <input type="submit" />
    </form>
    

    PHP, redirect.php:

    <?
    switch($_GET['mytext'])
    {
        case 's5d11':
            header('Location: http://somepage.com/');
            break;
        case 'qy4sd':
            header('Location: http://someotherpage.com/');
            break;
        default:
            print "<p>Wrong code. Try again</p>";
            include('index.html');
            break;
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 pip install后修改模块路径,import失败,需要在哪里修改环境变量?
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline