Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-13-2008, 11:20 AM   PM User | #1
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
Supplying a page with $_POST data follwing a server-side redirect

Hi all,

The following example will make the variables x and y available in mypage.php as $_GET data:

PHP Code:
header ("Location: mypage.php?x=1&y=2"); 
Is there a way to send variables to mypage.php using as POST data? (so that they need not be passed as part of the URL).

EDIT: I know I can mimick this using $_SESSION, but I wonder if there is a neat way of incorporating it into a request before the redirect (which ellicits a response) so that I don't have to do it explicitly with $_SESSION.

Last edited by mlse; 08-13-2008 at 11:31 AM..
mlse is offline   Reply With Quote
Old 08-13-2008, 11:32 AM   PM User | #2
hinch
Regular Coder

 
hinch's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 921
Thanks: 25
Thanked 79 Times in 79 Posts
hinch is on a distinguished road
hidden form and javascript submit instead of a php based header redirect
__________________
A programmer is just a tool which converts caffeine into code

My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
My hobby: http://www.angel-computers.co.uk
My life: http://www.furious-angels.com
hinch is offline   Reply With Quote
Old 08-13-2008, 11:41 AM   PM User | #3
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
Yep, thanks, I know that will work, but I would like to do it purely server-side.
mlse is offline   Reply With Quote
Old 08-13-2008, 11:51 AM   PM User | #4
the-dream
Regular Coder

 
the-dream's Avatar
 
Join Date: Mar 2007
Location: Northamptonshire, UK
Posts: 477
Thanks: 8
Thanked 4 Times in 4 Posts
the-dream can only hope to improve
I cannot think of a way to do this with just the header() function but you could use cURL to send the POST data.

Then you don't even have to leave the page, i don't know if this is exactly what you were looking for but...

POST Example:
PHP Code:
<?php
$ch1 
curl_init();

curl_setopt($ch1CURLOPT_URL,"http://www.example.com/page.php");
curl_setopt($ch1CURLOPT_POST1);
curl_setopt($ch1CURLOPT_POSTFIELDS,"x=hello&y=goodbye");

curl_exec ($ch1);
curl_close ($ch1); 
?>
GET Example:
PHP Code:
<?php
$ch 
curl_init();

curl_setopt ($chCURLOPT_URL"http://www.example.com/page.php?x=hello&y=goodbye");
curl_setopt ($chCURLOPT_HEADER0);

curl_exec ($ch);

curl_close ($ch);
?>
__________________
Branchr Advertising Network
the-dream is offline   Reply With Quote
Old 08-13-2008, 01:18 PM   PM User | #5
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
Hi, yep I had thought of that, but I think the $_SESSION solution is easier. I'll stick with $_SESSION until someone comes up with something else!
mlse is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:05 PM.


Advertisement
Log in to turn off these ads.