Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP $_POST help

Featured Replies

Posted

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

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.

  • Author
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.

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

agree with n0p

Have you set register_globals in php.ini?

  • Author

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

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.