Reputation: 35
My apologies for asking this question that I'm sure has been done before.
I'm not that knowledgable as far as PHP so the research I've done on this has been fruitless.
I've purchased and used an HTML template which has an email subscribe form at the bottom. The form is supposed to capture the entered email and add it to a text file with a list of submitted emails from what I understand.
Here is the excerpt from the html in the footer:
<form action="save-email.php" method="post" style="margin-top: 0px;">
<input type="text" name="email" placeholder="Get email updates...">
</form>
And here is the content of the corresponding save-email.php file:
<?php
$email = $_POST['email'];
$fp = fopen('submitted-emails.txt', 'a');
$savestring = $email . '
';
fwrite($fp, $savestring);
fclose($fp);
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
I've contacted the creators who pretty much told me to make sure my PHP version was up to date and that it was a server configuration error so they won't help me further...
I have PHP version 5.5.9 on an Ubuntu 14.04 Digital Ocean VPS
I've also edited the php.ini file to have register_globals turned on, but that did not help so I turned it off as I've read that is a security issue.
Any help would be greatly appreciated, thank you very much.
Upvotes: 1
Views: 5188
Reputation: 3907
This answer is in another context then question Because I was here to check the solutions.
I was posting(method="post"
) the form but it was not posting the data. When I check the data with print_r($_POST)
I was getting blank array.
I have felt this issue several times on servers.
The cause of this error is redirection from .htaccess
file.
Some time it happens our site is running on http://www.example.com/* and we have created rules in .htaccess to redirect all the request to http://example.com/* to http://www.example.com/* or vice versa.
If post request is to different location then this issue occurs. So make sure the post url starting string should be same(www or without www check in url).
I have spent lot of time on the same issue but could not find the solution any where in stackoverflow. So I have given the solution.
Upvotes: 2
Reputation:
Well, Are you sure post not working, Please check post method contains data or not by using.
var_dump($_POST); and var_dump($_REQUEST);
if you not found email id in post then it will be in request if it is then your request is submitting by get method.
if it display an array with email entered in post then your post method in working and problem is with file file was unable to open due to security problem/incorrect path or may be due to file permission. So check and let me know.
Upvotes: 0
Reputation: 1019
Try to create a file with name submitted-emails.txt
at the same directory with save-email.php
and change the permissions of file to +w
for all users.
Upvotes: 0