473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to get values of a redirected a POST request ?

these are three files below :
submit.html
<html>
<head>
</head>
<body>
<form action="redirect.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("Location: post.php");
?>

post.php
<html>
<head>
</head>
<body>
<?php
if(isset($_REQUEST['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 9281
Carl wrote:
these are three files below :
submit.html
<html>
<head>
</head>
<body>
<form action="redirect.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("Location: post.php");
?>

post.php
<html>
<head>
</head>
<body>
<?php
if(isset($_REQUEST['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("Location: post.php");
?>

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

Cheers,
NC

Jun 15 '06 #3
Richard Levasseur <ri********@gmail.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_redirect_to/remote_script.php' );

if( is_resource($rsrc) )
{
curl_setopt( $rsrc, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt( $rsrc, CURLOPT_POST, 1 );
curl_setopt( $rsrc, CURLOPT_POSTFIELDS, ltrim($rePosts, '&') );
curl_setopt( $rsrc, CURLOPT_HEADER, 0 );
curl_setopt( $rsrc, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $rsrc, CURLOPT_RETURNTRANSFER, 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("Location: post.php");
?>

post.php
<?php
session_start();
if(isset($_SESSION['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={$_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("Location: post.php");
?>

post.php
<?php
session_start();
if(isset($_SESSION['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*******@attglobal.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
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...
2
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...
5
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...
2
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...
3
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...
13
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...
6
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...
3
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...

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.