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 12-05-2012, 02:20 PM   PM User | #1
Oatley
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 56
Thanked 0 Times in 0 Posts
Oatley is an unknown quantity at this point
Access $POST data using header re-direct?

Hello, I am looking for some help with a form I am designing please.

I have a form, where a user enters their $_POST['user_id'] and their $_POST['name'].

Now whatever number they enter for their $_POST['user_id'] and hit submit on the form I use to make a URL string for examlple

search/123456/
Or
search/123473/

Which is done using a header redirect

PHP Code:
header('Location: search/'.$_POST['user_id']).'');
exit; 
However, on the page I am re-directing to I also want to be able to access
echo the $_POST['name'].

Is it possible without passing the name in the URL string, or is there a way around this?

Thank you
Oatley is offline   Reply With Quote
Old 12-05-2012, 02:59 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,395
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
Not gonna work. Why don't you simple do the search on the script the form submits to?
sunfighter is offline   Reply With Quote
Old 12-05-2012, 03:06 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Oatley View Post
However, on the page I am re-directing to I also want to be able to access
echo the $_POST['name'].

Is it possible without passing the name in the URL string, or is there a way
Contrary to sunfighter, yes. Sessions.

A session is basically a bit of memory you can read and write which php automatically saves and reads from a file on the servers hard disk. It is unique to each user and identified by a cookie.

At the top of your script BEFORE any output such as html or print statements AND in every script that use the $_SESSION array:
session_start();

Then after:
$_SESSION['name'] = $_POST['name'];

Likewise to access it in your next script:
session_start();
$Name = $_SESSION['name'];

I'm not sure why sunfighter thinks this isn't possible..
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
Oatley (12-05-2012)
Old 12-05-2012, 11:11 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,395
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
I didn't think it would work because header('Location: search/'.$_POST['user_id']).''); just didn't make sense to me.
sunfighter is offline   Reply With Quote
Old 12-05-2012, 11:26 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
These are both correct.
$_POST becomes unusable. You cannot post and get. You should be dealing with post at the location where you intend to post.
$_SESSION can be populated with $_POST. So you can retrieve $_SESSION['post'] for example from the page redirected to.

The final solution doesn't deal with redirection. You can connect to the page via socketing or curl and send the POST data manually.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Oatley (12-06-2012)
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 06:25 AM.


Advertisement
Log in to turn off these ads.