简体   繁体   English

如何打开发送POST数据的网页

[英]How to open a webpage sending POST data

I've a php page that contain some html code. 我有一个php页面,其中包含一些html代码。 It's a confirmation page for user who register to the site, so, i want to show it only in case of effective registration (with no possibilty to access it from external). 这是一个向注册该网站的用户的确认页面,因此,我只想在有效注册的情况下显示该页面(无法从外部访问它)。 For do that i've placed this condition at the beginning of confirmation.php 为此,我将这种情况放在了Confirmation.php的开头

if (empty($_POST))
{header('location: registration.php');} 

the rest of the file is: 该文件的其余部分是:

<div id="logo"> <img src=my_logo_small_grey.png  height="60"/> </div>
<div id="msgConfirm">Thank You</div>

(by the way, it is a good solution?) (顺便说一句,这是一个好的解决方案?)

But staring from registration.php, how to launch/redirect to confirmation.php sending it POST params? 但是,从registration.php开始,如何启动/重定向到Confirmation.php发送POST参数? Actually i've used AJAX: 其实我用过AJAX:

url = "confirmation.php";
params = "ok"
ajaxReq.setRequestHeader("Content-length", params.length);
ajaxReq.open("POST", url, true); 

But it seems that only execute the script (thought), with no effective redirection.. why? 但似乎只执行脚本(思想),却没有有效的重定向。为什么?

use jQuery 使用jQuery

$.post() will be key to implementing your solution. $.post()将是实现您的解决方案的关键。


but looking more generally at your question, normally, the workflow is following 但一般来说,您的问题通常都遵循以下工作流程

  1. fill a form 填写表格
  2. send email 发电子邮件
  3. user clicks on email link 用户点击电子邮件链接
  4. confirmation page is opened 确认页面已打开
  5. check hash, validate user 检查哈希,验证用户
  6. log-in and redirect to success page 登录并重定向到成功页面

if you really-really need to hide access to success page, create one-time-usable tokens. 如果确实需要隐藏对成功页面的访问,请创建一次性可用的令牌。

having (!empty($_POST)) is not a "strong" way of limiting access to that site. (!empty($_POST))并不是限制访问该站点的“强”方法。

sorry, I don't full understand the question, but I'll give a shot at helping. 抱歉,我不完全理解这个问题,但是我会提供帮助的。

First, if the rest of the file is that small then you could just put it in an if loop. 首先,如果文件的其余部分很小,则可以将其放入if循环中。

<?php
if(isset($_POST['yourpost']))
{
?>

<div id="logo"> <img src=my_logo_small_grey.png  height="60"/> </div>
<div id="msgConfirm">Thank You</div>

<?php
}
?>

You can also create a redirect by writing out Javascript like below: 您还可以通过编写如下的Javascript来创建重定向:

<?php
echo "<script>location.href='".$redirecturl."'</script>";    
?>

Post data is usually sent to a different page where it is processed and then you are taken to another page showing confirmation. 通常将过帐数据发送到处理该数据的其他页面,然后将您带到另一个显示确认的页面。 This data can be retrieved by getting it from the database again.(If you are doing that) 再次从数据库中获取数据即可(如果您这样做的话)

If you do want to pass on POST data retrieved onto another page, then you could add it as GET variables to the link like so www.url.com/index.php?get=something 如果您确实希望将检索到的POST数据传递给另一个页面,则可以将它作为GET变量添加到链接中,例如www.url.com/index.php?get=something

You could also store a session variable as $_SESSION['var']="something"; 您也可以将会话变量存储为$ _SESSION ['var'] =“ something”; Remembering to start session_start(); 记住要启动session_start(); at the beginning of the php pages using sessions. 在使用会话的php页面的开头。

Sorry, I am not that experienced so maybe someone else will give better help, hope this helps for now. 抱歉,我没有那么丰富的经验,所以也许其他人会提供更好的帮助,希望现在能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM