Submit a form in a hidden php script
I am working in a form, which is in a hidden script called by Ajax method.
In this php script, I want t submit the information using an URL,using this piece of code:header("location: https://www.page.com/servlet/?encoding=UTF-8&oid=333&first_name=$first_name&开发者_运维知识库;last_name=$last_name");
But the informaton is not submitted.
Any idea?? Thanks in advance.
edit: use $_GET
to retrieve the variables
More about $_GET here
It's not that the code you have given is not working. It's only that maybe the program counter of the system is not going to that destination page or that destination page is not capable yet to retrieve the values.
First of all, your code should be:-
header("Location: https://www.page.com/servlet/?encoding=UTF-8&oid=333&first_name=$first_name&last_name=$last_name");
exit();
The "exit()
" function must be used after every "header()
" function call, because the "header()
" function is meant to redirect the current web page to the desired web page. However the execution of the script continues in the parent page, so you need to use the "exit()
" function to stop its execution.
Now in the destination page, you need to write the following code, to retrieve the values:-
<?php
foreach ($_GET as $key => $val) {
$$key = $val;
}
echo "<br/>Encoding - ".$encoding;
echo "<br/>O ID - ".$oid;
echo "<br/>First name - ".$first_name;
echo "<br/>Last Name - ".$last_name;
?>
So you see I have just used the "$_GET
" superglobal variable (click here to know more about it), to retrieve the values send from another page to this destination page.
Hope it helps.
The thing was the function header()
If I use the function fopen, everything is well redircted:
$handle = fopen("https://www.salesforce.com/.WebToLead?encoding=UTF-8&oid=333&first_name=$first_name&last_name=$last_name", "r");
Thans anyway for your answers
精彩评论