INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

PHP 5.3.3 vs. PHP 5.4.16

PHP 5.3.3 vs. PHP 5.4.16

(OP)
I have a PHP script which I'm using in a html form. It works fine in PHP 5.3.3, but not on 5.4.16.

<?PHP

$filename = "/tmp/restart.txt"; #Must CHMOD to 666
$text = $_POST['requester']; # Form must use POST. if it uses GET, use the line below:
$text2 = $_POST['reason']; # Form must use POST. if it uses GET, use the line below:

$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
$fp2 = fopen ($filename, "a"); # w = write to the file only, create file if it does not exist, discard existing contents

if ($fp) {
fwrite ($fp, "requester=");
fwrite ($fp2, $text);
fwrite ($fp2, "\nreason=");
fwrite ($fp2, $text2);
fclose ($fp);
sleep(1);
header("Location: http://mysite.com/restart-complete.html");
}
else {
echo ("ERROR: Please check the status of the app.");
header("Location: http://mysite.com/restart-error.html");
}

?>


Form:

<FORM action="restart.php" method="post">
<label for="technician">Requester:</label>
<input type="text" id="requester" name="requester" />
&nbsp;
<label for="reason">Reason:</label>
<input type="text" id="reason" name="reason" />
<br><br>
<input type="submit" value="Restart App!">
</form>

Any thoughts on what the issue could be? I'm using the same HTML form on both servers.

RE: PHP 5.3.3 vs. PHP 5.4.16

Hi

You will have to give us details about how is not working. The code itself is syntactically correct and works fine for me in 5.6.30. Try to add error_reporting(E_ALL); to the beginning of your script to make sure no message passes unnoticed. ( You may also need to set either display_errors or log_errors. )

Maybe the PHP version update replaced php.ini and now some of your old configuration is missing. For example open_basedir is different, which may affect the fopen()'s success.

Definitely no idea why are you opening the same file twice, but that is just weird, not a bug. But I would get rid of it as possible, just to be sure.

Quote (johngiggs)

echo ("ERROR: Please check the status of the app.");
header("Location: http://mysite.com/restart-error.html");
Unless you use output buffering, this will not work as header() must be called before any actual content is sent out.


Feherke.
feherke.github.io

RE: PHP 5.3.3 vs. PHP 5.4.16

(OP)
Hi feherke,

The only issue I'm having is that when I fill out the form on the HTML page it's not creating the .txt file.

All I'm attempting to do is to have the 2 form fields write to a text file. I have the code working fine on a few different machines, but for some reason in this case the file isn't being created.

I tried the error code snippet you mentioned, but it didn't seem to help.

Thanks,

John

RE: PHP 5.3.3 vs. PHP 5.4.16

Error reporting would help.

CODE

// enable error reporting to display in the browser
error_reporting(E_ALL);
ini_set('display_errors', 1); 

Are you testing between 5.3.3 and 5.4.16 in the same environment? This smells like a simple issue of permissions for the particular version of PHP to write to your location.

RE: PHP 5.3.3 vs. PHP 5.4.16

THe first thing to do is to get errors showing. Comment out the redirections (header), otherwise the error would just go unseen when you change the page.



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: PHP 5.3.3 vs. PHP 5.4.16

(OP)
Hi,

I tried removing the header redirects, but I'm not seeing any logging to indicate what the problem is.

As I mentioned, I run the same php code and form on CentOS 5 and 6 with earlier versions of PHP and don't have any issues. This issue is on CentOS 7 with PHP 5.4.16.

Any other thoughts on what the issue could be? Was anything I posted deprecated in a newer version of PHP?

Thanks,

John

RE: PHP 5.3.3 vs. PHP 5.4.16

(OP)
Hi,

Does anyone have any troubleshooting tips or ideas? It was a simple HTML form and PHP script, but it's no longer working on the new OS and PHP version.

If there's an alternate way to achieve the same thing I'd be open to doing it another way.

Thanks,

John

RE: PHP 5.3.3 vs. PHP 5.4.16

If this isn't working then there must be errors. Troubleshoot the error reporting first to troubleshoot the original problem.

Try creating a new PHP file to see if error reporting works. Then apply to your existing file.

CODE

<?php
// enable error reporting to display in the browser
// note that the following 2 lines are the very first functions in this script
error_reporting(E_ALL);
ini_set('display_errors', 1); 

// do something to prove an error
echo $anunsetvariable;
?> 

To troubleshoot your existing script, it would look like this...

CODE

<?PHP
error_reporting(E_ALL);
ini_set('display_errors', 1); 

$filename = "/tmp/restart.txt"; #Must CHMOD to 666
$text = $_POST['requester']; # Form must use POST. if it uses GET, use the line below:
$text2 = $_POST['reason']; # Form must use POST. if it uses GET, use the line below:

$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
$fp2 = fopen ($filename, "a"); # w = write to the file only, create file if it does not exist, discard existing contents

if ($fp) {
fwrite ($fp, "requester=");
fwrite ($fp2, $text);
fwrite ($fp2, "\nreason=");
fwrite ($fp2, $text2);
fclose ($fp);
sleep(1);
echo ("SUCCESS!");
//header("Location: http://mysite.com/restart-complete.html");
}
else {
echo ("ERROR: Please check the status of the app.");
//header("Location: http://mysite.com/restart-error.html");
}

?> 

RE: PHP 5.3.3 vs. PHP 5.4.16

(OP)
Hi,

I finally resolved the issue. I found that "PrivateTmp=true" is set in /usr/lib/systemd/system/httpd.service. I set it to false which resolved the issue.

systemctl daemon-reload
service httpd restart

Thanks,

John

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close