Setting data to $_POST without using a form. Is it possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Setting data to $_POST without using a form. Is it possible?

Post by batfastad »

Hi

I was wondering whether it's possible to set data into the POST array to be transferred between pages, without using a form?

I've just tried this on a blank test page...

Code: Select all

<?php
$_POST = array();
$_POST&#1111;"test"] = "test data";
?>
<a href="test4.php">go</a><br />
<br />
<?php
echo($_POST&#1111;"test"]);
?>
And it appears that you can set the POST array within the page, and access the data.
Obviously you may as well just call your array something else to do this.

Then on the next page test4.php...

Code: Select all

<?php
print_r($_POST);
?>
Obviously doesn't return the data that I set on the previous page.

What I'd like to know is if there's a way to set the post data on one page, then access it on a subsequent page.
I guess it's down to how you switch to the next page - i'd like to be able to do this by just the user just clicking a link.

Just wondered if it is possible.
As I want to have data passed between pages, but I don't want to use the address bar $_GET data. And there will be quite a few variables I'll need to pass between pages, each with a large amount of data.

If it isn't possible then no problem - I'll just use sessions.

Is it possible though?

Thanks

Batfastad
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not use sessions?
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Post by batfastad »

I know sessiosn make sense but the way the site's been designed at the moment means I don't have access to the code at the top of the page, meaning I can't use session_start()

Just wondered if there was a way to do it using POST data to avoid a whole load of work undoing the previous "designer's" work.

Sessions are the way to go.
I have not actually used sessions before, but I have a good understanding of how they work and they don't seem complicated to learn.

Is there a way to do this?

Thanks

Batfastad
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's no real way to do it that I am aware of if you can't do sessions, you can't do cookies.. you can't use their ip as they could be running through a NAT.. so unless you pass it through the url ($_GET) nope.
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Post by batfastad »

Sessions it is then!

Thanks for clearing that up for me.
Looks like I can charge a nice redesign fee for the work in that case.
:lol: :lol:

Batfastad
Post Reply