473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get values of a redirected a POST request ?

these are three files below :
submit.html
<html>
<head>
</head>
<body>
<form action="redirec t.php" method="POST" >
<input type="text" name="value" value="test" >
<input type="submit" >
</form>
</body>
</html>

redirect.php
<?php
header("HTTP/1.1 303 See Other");
header("Locatio n: post.php");
?>

post.php
<html>
<head>
</head>
<body>
<?php
if(isset($_REQU EST['value'])) {
echo "the value is : <font color=RED >{$_REQUEST['value']}</font>";
}
?>
</body>
</html>
When I submit, it does redirect to 'post.php', but it doesn't show
"test". If I change the submit.html to use the "GET" method ,and append
"?value={$_ GET['value']}" to the url int the redirect.php, it works
well. Why the "POST" method doesn't work? I use "apache http server
2.0.58" with "php 5" , "ms IE 6.0" and "firefox 1.5.0".

Jun 15 '06 #1
7 9290
Carl wrote:
these are three files below :
submit.html
<html>
<head>
</head>
<body>
<form action="redirec t.php" method="POST" >
<input type="text" name="value" value="test" >
<input type="submit" >
</form>
</body>
</html>

redirect.php
<?php
header("HTTP/1.1 303 See Other");
header("Locatio n: post.php");
?>

post.php
<html>
<head>
</head>
<body>
<?php
if(isset($_REQU EST['value'])) {
echo "the value is : <font color=RED >{$_REQUEST['value']}</font>";
}
?>
</body>
</html>
When I submit, it does redirect to 'post.php', but it doesn't show
"test". If I change the submit.html to use the "GET" method ,and append
"?value={$_ GET['value']}" to the url int the redirect.php, it works
well. Why the "POST" method doesn't work? I use "apache http server
2.0.58" with "php 5" , "ms IE 6.0" and "firefox 1.5.0".


You lose posted data when you redirect. You would need to re-post the
data along with sending the redirect, which i'm not sure is possible,
never tried it myself.

Why can you simply include the file?

Since you're using apache, you could use mod_rewrite to transparently
rewrite the request, not sure if that would accomplish what you want to
do.

Jun 15 '06 #2
NC
Carl wrote:

these are three files below :
[Snippets deleted]
When I submit, it does redirect to 'post.php', but it doesn't show
"test". If I change the submit.html to use the "GET" method ,and append
"?value={$_ GET['value']}" to the url int the redirect.php, it works
well. Why the "POST" method doesn't work?


Because redirection uses the GET method.

You should consider either including post.php into redirect.php or
saving the POSTed values into session variables:

redirect.php
<?php
session_start() ;
$_SESSION = $_POST;
header("HTTP/1.1 303 See Other");
header("Locatio n: post.php");
?>

post.php
<?php
session_start() ;
if(isset($_SESS ION['value'])) {
echo "the value is : <font color=RED >{$_SESSION['value']}</font>";
}
?>

Cheers,
NC

Jun 15 '06 #3
Richard Levasseur <ri********@gma il.com> wrote:
You lose posted data when you redirect. You would need to re-post the
data along with sending the redirect, which i'm not sure is possible,
never tried it myself.


Yes, it's possible :)

Using Curl, you might try something like this (adjust to fit your
needs):

if( condition )
{
$rePosts = '';

foreach( $_POST as $pk => $pv )
{
$rePosts .= "&$pk=" . urlencode($pv);
}

$rsrc = curl_init( 'http://site_to_redirec t_to/remote_script.p hp' );

if( is_resource($rs rc) )
{
curl_setopt( $rsrc, CURLOPT_USERAGE NT, $_SERVER['HTTP_USER_AGEN T']);
curl_setopt( $rsrc, CURLOPT_POST, 1 );
curl_setopt( $rsrc, CURLOPT_POSTFIE LDS, ltrim($rePosts, '&') );
curl_setopt( $rsrc, CURLOPT_HEADER, 0 );
curl_setopt( $rsrc, CURLOPT_FOLLOWL OCATION, 1 );
curl_setopt( $rsrc, CURLOPT_RETURNT RANSFER, 1 );

curl_exec( $rsrc );
curl_close( $rsrc );

exit;
}
else
{
// some error handling...
}
}

hih,

JJS.
Jun 15 '06 #4

NC wrote:
Carl wrote:

these are three files below :


[Snippets deleted]
When I submit, it does redirect to 'post.php', but it doesn't show
"test". If I change the submit.html to use the "GET" method ,and append
"?value={$_ GET['value']}" to the url int the redirect.php, it works
well. Why the "POST" method doesn't work?


Because redirection uses the GET method.

You should consider either including post.php into redirect.php or
saving the POSTed values into session variables:

redirect.php
<?php
session_start() ;
$_SESSION = $_POST;
header("HTTP/1.1 303 See Other");
header("Locatio n: post.php");
?>

post.php
<?php
session_start() ;
if(isset($_SESS ION['value'])) {
echo "the value is : <font color=RED >{$_SESSION['value']}</font>";
}
?>

Cheers,
NC


In fact ,the destination that I want to redirect to is not developed by
me , and they won't change their code for me. They use "POST" to get
values ,I have to redirect the POST request.

Jun 16 '06 #5
Carl wrote:
NC wrote:
Carl wrote:
these are three files below :


[Snippets deleted]

When I submit, it does redirect to 'post.php', but it doesn't show
"test". If I change the submit.html to use the "GET" method ,and append
"?value={$_G ET['value']}" to the url int the redirect.php, it works
well. Why the "POST" method doesn't work?


Because redirection uses the GET method.

You should consider either including post.php into redirect.php or
saving the POSTed values into session variables:

redirect.ph p
<?php
session_start() ;
$_SESSION = $_POST;
header("HTTP/1.1 303 See Other");
header("Locatio n: post.php");
?>

post.php
<?php
session_start() ;
if(isset($_SESS ION['value'])) {
echo "the value is : <font color=RED >{$_SESSION['value']}</font>";
}
?>

Cheers,
NC

In fact ,the destination that I want to redirect to is not developed by
me , and they won't change their code for me. They use "POST" to get
values ,I have to redirect the POST request.


As others have said - you can't redirect post values. They're sent as part of
the request for the page, and a redirect doesn't resend them.

Your only real choices are to use CURL or send the header information yourself.

Then pass the results back to the client.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jun 16 '06 #6
NC
Carl wrote:
NC wrote:
Carl wrote:

Why the "POST" method doesn't work?


Because redirection uses the GET method.


In fact ,the destination that I want to redirect to is not developed
by me , and they won't change their code for me. They use
"POST" to get values ,I have to redirect the POST request.


You can't. HTTP does not work this way.

Cheers,
NC

Jun 16 '06 #7
NC
Jerry Stuckle wrote:

As others have said - you can't redirect post values. They're
sent as part of the request for the page, and a redirect doesn't
resend them.

Your only real choices are to use CURL or send the header
information yourself.

Then pass the results back to the client.


Alternatively, he could put all necessary information into the form and
POST directly to the page that requires POST inputs...

Cheers,
NC

Jun 16 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4249
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form:...
2
4693
by: Kostas kousinovalis | last post by:
Hello I have a asp page which it post some values to an external web page (not mine) with the method response.redirect (www.website.com/page.asp?username=user&password=mypass) The external web page response OK if the user exist and Error if the user not exists. How can I take this data to send it to my own pages somewhere? After the...
5
2125
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously expected behavior). What's the recommended/best way to persist these values through the post process? I know I could set them to the request.form...
2
1748
by: Sky Fly | last post by:
Hello, I have a web form which, when an exception is thrown in its codebehind, should be redirected to another from to display the details of the error message. I have a special asp textbox in this form which is invisible and which will be assigned the value of the error message in the exception handler so that in the Page_Load of the...
3
1627
by: Cyrus Donders | last post by:
Hi, We are developing a web application in asp.net and all of a sudden there is this new requirement and I am having problems to implement it. My problem is that when a regular html page posts values to a aspx page in our website, I lose the values that were posted. If the values are send with a GET request I can access them in the...
13
3951
by: RHPT | last post by:
I am wanting to capture the XML posted by an InfoPath form with .NET, but I cannot figure out how to capture the XML stream sent back by the InfoPath form. With Classic ASP, I could just create an MSXML object then load the XML with a simple objXML.Load(Request). This would give me the XML stream, which I could then manipulate. However,...
6
9676
by: Karthik | last post by:
I am trying to read Http request body values NOT form values The content type is text/xml and its POST I am posting data from Infopath to an asp.net page. In ASP it works by just writing Response.Write(request) the same does not work in ASP.NET I tried using Rquest.BinaryrRead() and Request.InputStream but it gives me text values as...
3
1595
by: Avlan | last post by:
Still new with asp, and I feel I haven't yet captured the logic of it completely ;-P I know how to post values to another asp-page through the use of a form and a submit-button, combined with the post or get-method. What I don't know is how to post those values one asp-page further through code, so without anyone having to press any button....
0
4085
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.