I have a problem and have been looking for an answer for 4 days - mainly on Google, but have hit a brick wall.
Can anybody help? Please.
HERE IS THE BACKGROUND :
All my web-pages are .php files.
I invite visitors to give me an alias name and an email address - using a form on a web-page.
I store the alias and email in a .txt file on my server.
I don't want the email to be in plain text but I am not looking for a clever encryption routine - I hold no other information about the visitor.
My quick and easy solution is to swap each bit in each character by using the PHP Binary NOT Operator ( ~ ).
Thus : $code = ~$email results in "abc" being coded (in Hex) from 61 62 63 to 9E 9D 9C
HERE IS HOW I WRITE TO AND READ FROM THE .txt FILE :
I use a form to get the "alias" and "email" from the visitor which I "post" to "savethisperson.php". In "savethisperson.php" I use the following code -
CODE SNIPPET 1
$fd = fopen("persondata.txt", "a");
fwrite($fd, $_POST['alias'] . ",");
fwrite($fd, ~$_POST['email']); // note the encryption of the string using ~
fwrite($fd, "
");
fclose($fd);
You will note that this creates one line per visitor with two strings in the line separated by a comma.
I now want to list every line in the "persondata.txt" file, showing the encrypted code -
CODE SNIPPET 2
$members = file("persondata.txt"); // Creates an array called "members" with one line in each element of the array.
foreach ($members as $nxtline) // Creates variable called "nxtline" for each element in turn
{
echo $nxtline, "<br>";
}
I now want to list every line in the "persondata.txt" file, un-encrypting the email address -
CODE SNIPPET 3
$members = file("persondata.txt"); // Creates an array called "members" with one line in each element of the array.
foreach ($members as $nxtline) // Creates variable called "nxtline" for each element in turn
{ $data = str_getcsv($nxtline); // Creates an array called "data" for each string separated by a comma.
echo $data[0]), "," ~$data[1], "<br>"; // Note the un-encryption of data[1] using ~
}
SO HERE IS MY PROBLEM?
I have changed my server provider and some of the above code has stopped working.
My old provider offered PHP version 5.4. Everything worked.
My local (on my own machine) testing server uses PHP 5.3.8. Everything works.
My new provider offers PHP 5.3.2-1ubuntu4.27 and I am having problems :
Code snippet 1 works.
Code snippet 2 works.
Code snippet 3 fails. So I assume that it is the "str_getcsv" function that fails with code in the (Hex) 8* and 9* range. But why would it work before and still work on my testing server?
Perhaps my assumption is wrong and there is some other reason for snippet 3 to stop working.
If it matters - all servers use Apache 2.0 handler.
PLEASE do not tell me to alter my encryption method.