Jump to content
Tuts 4 You

PHP $_POST help


Kruse

Recommended Posts

Posted (edited)

Hey everyone,

I'm writing an FTP script in PHP and I know the upload is working (tested it with out the HTML form), but as soon as I put a form in it to post some data to another page, it no longer works. the data i'm trying to post are in hidden fields in an html form:

<input type="hidden" name="action2" value="up">
<input type="hidden" name="hostname" value=<?php $hostname ?>>
<input type="hidden" name="user" value=<?php $user ?>>
<input type="hidden" name="password" value=<?php $password ?>>

where all the values were posted from another page and put into these vars (except for action2, which is also the only one which is read properly). When I try to pick them back up on the next page, they all return empty strings. Could anyone give me a reason why?

Edited by Kruse
Posted

It's not possible.

Because, every time script finishes, ftp connection are closed. And Even if it wouldn't you can't transfare that connection, to another script.

Posted
It's not possible.

Because, every time script finishes, ftp connection are closed. And Even if it wouldn't you can't transfare that connection, to another script.

I changed that so the connection is in the script it should be in and made the edits above (seemingly while you were posting your respose!) those fields i'm posting are entered by the user.

Posted

Add "quotes" around the values and maybe try using $_POST['hostname'] etc instead of just $hostname.

Posted

agree with n0p

Posted

Have you set register_globals in php.ini?

Posted (edited)

alright, so i made the suggested changes, so I now have:

<?php
$action = $_POST['action'];
$hostname = $_POST['hostname'];
$user = $_POST['user'];
$password = $_POST['password'];
switch($action)
{
case 'upload':
?>
<form action="transferScript.php" method="post">
<table align="center">
.
.
.
</table>
<input type="hidden" name="action2" value="up">
<input type="hidden" name="hostname" value="<?php $_POST['hostname'] ?>">
<input type="hidden" name="user" value="<?php $_POST['user'] ?>">
<input type="hidden" name="password" value="<?php $_POST['password'] ?>">
</form>

then in the next file:

		$action = $_POST['action2'];
$hostname = $_POST['hostname'];
echo "hostname $hostname";
$user = $_POST['user'];
$password = $_POST['password'];
echo "<br>user: $user <br>pass: $password";
$conn_id = ftp_connect($hostname);
$login_result = ftp_login($conn_id, $user, $password);

In the echos, none of the variables print anything out, and it gets a:

Fatal error: Maximum execution time of 30 seconds exceeded

on the $conn_id = ftp_login($conn_id, $user, $password); line. anyone have any ideas?

Thanks again.

p.s. register globals is enabled

Edited by Kruse
Posted
alright, so i made the suggested changes, so I now have:
<?php
$action = $_POST['action'];
$hostname = $_POST['hostname'];
$user = $_POST['user'];
$password = $_POST['password'];
switch($action)
{
case 'upload':
?>
<form action="transferScript.php" method="post">
<table align="center">
.
.
.
</table>
<input type="hidden" name="action2" value="up">
<input type="hidden" name="hostname" value="<?php $_POST['hostname'] ?>">
<input type="hidden" name="user" value="<?php $_POST['user'] ?>">
<input type="hidden" name="password" value="<?php $_POST['password'] ?>">
</form>

then in the next file:

		$action = $_POST['action2'];
$hostname = $_POST['hostname'];
echo "hostname $hostname";
$user = $_POST['user'];
$password = $_POST['password'];
echo "<br>user: $user <br>pass: $password";
$conn_id = ftp_connect($hostname);
$login_result = ftp_login($conn_id, $user, $password);

In the echos, none of the variables print anything out, and it gets a:

Fatal error: Maximum execution time of 30 seconds exceeded

on the $conn_id = ftp_login($conn_id, $user, $password); line. anyone have any ideas?

Thanks again.

p.s. register globals is enabled

you may not see anything echo'd because the IO is buffered, either flush the buffer, change the buffering mode or just add \n to the end of the strings you are echo'ing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...