doujuanxun7167 2013-01-07 13:34
浏览 53
已采纳

重定向到php中的另一个页面

I have a form with two fields name & email & i need to submit that form values on specific url, like below

http://www.abc.co.uk/acy/xyzerequest&name='me'&email='me@gmail.com'

for this i made the form & post it to php file.. where i am getting the value by using $_POST but where i feel stuck is how can i send these values to the specific URL, but user should not know.

So the end user just enter name & his email id & just directed to that URL with his values..

Kindly guide me how can i achieve..I was trying from last 3 hours & no good luck.

  • 写回答

7条回答 默认 最新

  • doujiu3882 2013-01-07 14:04
    关注

    As I understand it, you want your script to collect user's name and email, create a URL and redirect the user.

    So the script should look something like this (this is just a guide line).

        <?php
        if(isset($_POST['submit'])){
            $name = $_POST["name"];
            $email = $_POST["email"];
    
            //create the URL
            $url = "http://www.example.com/yourpage.php?name=" . urlencode($name) . "&email=" . urlencode($email);
    
            //send the header
            header("Location: " . $url);
            //exit the script
            exit();
        }
        ?>
        <html>
          <body>
            <form method="post" action="" name="name">
              Name:<input type="text" name="name">
              Email:<input type="text" name="name">
              <input type="submit">
            </form>
          </body>
        </html>
    

    As far as the URL goes, the ? denotes where your "variables" start.

    You should never create a URL from raw user data, especially if you are sending them to one of your other scripts. You should always use urlencode($data), this will make the data URL safe. You should also look into data validation and scrubbing.

    So what this script does is first check to see if anything has been posted to it, and if so, if collects the data, creates the URL, sends the header for redirection, and exits. If not, it presents a form for the user to enter their info.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办