POSTing without a form

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

maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

POSTing without a form

Post by maniac9 »

Is there a simple way to send POST data to another script without the use of a visible form, and automatically - ie. open one page (maybe directly in PHP) and have some data sent to another script
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

not quite sure what you are asking, but maybe this is close to it.

if you have a variable on a page that you would like to use on another, the best way is to call the include() function.

Example :

you have a php page called bob.php

in it is the following :

Code: Select all

<?php

$this = 'Hello';

?>
and you have another php page called george.php that you want to call bob.php's variable $this.

So, you would do it like so :

Code: Select all

<?php

ob_start();
        include "bob.php";
        echo ''.$this.' World!';
ob_end_flush();

?>
Another method is to use Sessions()

you can view information on them here : [php_man]Session[/php_man]

hope that helps.
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

I have done it using fsockopen check out this link viewtopic.php?t=7063


BTW the function 'httpParseResponse' in my code is incorrect. It explodes by \r\n\r\n when it should just split the headers from the content at the first occurrance of \r\n\r\n
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

Do you kind of mean a link?

I would suggest this. (in steps)

first page: automatically sends a user to next pag with variable:
http://www.yoursite.com/index.php?variable=value

second page: The page you send users to with new info.
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

well, like that, but instead of using GET, using POST
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

any way we can check the code to see what you are talking about?
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

well i dont have any yet ;)

Here's a simple description of the scenario...

I need to send a large amount of text from one script to another, and the limitations of GET will be in the way, so I need to POST it. However, the text being sent will be generated from another source, not by a user. Therefore, what I need is a way for one script to take some text, send it via POST (but transparent to the user) to another script.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could you use sessions for this?

Mac
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

wel u can use hidden fields but u hav to use form to in that case....
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I agree.

Hidden fields and javascript auto submit.

Or cookies/sessions to save the data and gather it on the next page.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

if the data is larger then 4kb then you cant use cookies :? , may wanna stick with sessions :wink:.
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

well, the problem with using sessions is the fact that the data could be coming from another language

i think what im going to do is hidden forms with a javascript autosubmit like Sami suggested - seems like my only option
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

OK, am I invisible here? Did you consider the option I suggested?
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

who said that :-)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Just out of curiosity... Why $_POST?
As Mac (and others) sais, $_SESSION is the obvious choise imho, for 'invisible' data transport.
Post Reply