By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,978 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,978 IT Pros & Developers. It's quick & easy.

Can you _POST variables in php without using a <FORM>

P: n/a
Hi fairly new to php, but picking it up quite well.
the question I have, is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form which captures login_id and password which are
posted to verify.php

verify.php checks the id and password against the database.
if the check succeeds I use $_SESSION to track the logged in user into
the page.
if the check fails, I use $_SESSION["error"] to set an error message
and then jump to login.htm, but I've lost the userid.
The only way I can see of transferring the userid (and some other data)
is by calling header ("Location: login.htm?id=$uid");
and then have some php code in login.htm to $GET['uid'] and pop that
into the user field on the form.

Is there any easy way I can post this data back without using a <FORM>
or at least a form that can be auto-submitted?

Thanks in advance.

Jan 20 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
ch**************@hotmail.com wrote:
Hi fairly new to php, but picking it up quite well.
the question I have, is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

yes its a VFAQ. learn how to use Google.

But you can't POST on a redirect - HTTP does not allow.
i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form

<snip>

So what's wrong with passing it in a GET?

C.
Jan 20 '06 #2

P: n/a
I tied using Gogle, either I'm not being specific enough in my question
search or too specific,
so I get hits for the normal processing of variables passed in using
POST, but nothing on how to POST back from within php.

if you could give me a link to such a site, that woud be appreciated.

yes, I could use get, and at the moment its just the userid, but the
login page may be expanded to have several fields, which is why I would
not want to paste all the variables/data into the url when sending
back.

Chris

Jan 20 '06 #3

P: n/a
Al
ch**************@hotmail.com wrote:
I tied using Gogle, either I'm not being specific enough in my question
search or too specific,
so I get hits for the normal processing of variables passed in using
POST, but nothing on how to POST back from within php.

if you could give me a link to such a site, that woud be appreciated.

yes, I could use get, and at the moment its just the userid, but the
login page may be expanded to have several fields, which is why I would
not want to paste all the variables/data into the url when sending
back.

Chris


You could try cookies?
Or you could have verify and login to be the same php page... then you
can set the values in the form youself.

If you still wanted them to have separate names they could both just
require("login/verify.php"); or something. Boths ways are good if you
want to avoid GETs, although I think the second works more nicely.
Cookies probably shouldn't be used for this purpose...

Jan 20 '06 #4

P: n/a
ch**************@hotmail.com wrote:
is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form which captures login_id and password which are
posted to verify.php

verify.php checks the id and password against the database.
if the check succeeds I use $_SESSION to track the logged in user into
the page.
if the check fails, I use $_SESSION["error"] to set an error message
and then jump to login.htm, but I've lost the userid.
use $_SESSION to save the userid and the error message

<?php
if ($check_failed) {
$_SESSION["error"] = "Check failed. Please try again.";
$_SESSION["userid"] = $userid;
}
?>
The only way I can see of transferring the userid (and some other data)
is by calling header ("Location: login.htm?id=$uid");
and then have some php code in login.htm to $GET['uid'] and pop that
into the user field on the form.

Is there any easy way I can post this data back without using a <FORM>
or at least a form that can be auto-submitted?


With the $_SESSION array.

If your web server isn't set up to call PHP for htm pages (it shouldn't)
change your login.htm to login.php first.

The first time a user calls login.php, $_SESSION is empty.
After a login failure $_SESSION has the error message *and* the userid

<?php // login.php
if (isset($_SESSION["error"])) {
echo '<p class="error">', $_SESSION["error"], '</p>';
}

// ...

echo '<input type="text" name="userid"';
if (isset($_SESSION["userid"])) {
echo ' value="', $_SESSION["userid"], '"';
}
echo '/>';
?>

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 20 '06 #5

P: n/a
YES! thank you Pedro.

It works perfectly, I use sessions to keep track of users who are
logged in,
it just never occurred to me to use it for anything like passing data
back and forth between scripts.

'Duh' - One of those Homer Simpson moments.

Mucha appreciated

Chris

Jan 21 '06 #6

P: n/a
ch**************@hotmail.com wrote:
YES! thank you Pedro.

It works perfectly, I use sessions to keep track of users who are
logged in,
it just never occurred to me to use it for anything like passing data
back and forth between scripts.

'Duh' - One of those Homer Simpson moments.

Mucha appreciated

Chris


That's what it's BEST at!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 21 '06 #7

P: n/a
the browser, if I am correct, feeds the variables over the HTTP port like a
terminal, and are read in STDIN like it was coming in from a keyboard. but
I am not sure how they are serialized.

you can use javascript to autosubmit the form.
document.forms[0].submit();

<ch**************@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi fairly new to php, but picking it up quite well.
the question I have, is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form which captures login_id and password which are
posted to verify.php

verify.php checks the id and password against the database.
if the check succeeds I use $_SESSION to track the logged in user into
the page.
if the check fails, I use $_SESSION["error"] to set an error message
and then jump to login.htm, but I've lost the userid.
The only way I can see of transferring the userid (and some other data)
is by calling header ("Location: login.htm?id=$uid");
and then have some php code in login.htm to $GET['uid'] and pop that
into the user field on the form.

Is there any easy way I can post this data back without using a <FORM>
or at least a form that can be auto-submitted?

Thanks in advance.

Jan 24 '06 #8

P: n/a
Although probably not very efficient, you may want to look at fsockopen
(http://us2.php.net/manual/en/function.fsockopen.php), which would
allow to connect to your web server with a POST request. I, however,
would use sessions.

Jan 25 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.