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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程