Jump to content

Recommended Posts

can someone give me a push here?  I've tried "file_put_contents" and "fputs" and neither one works for me.  I'm running PHP on an IIS server and a windows hosting plan.  PHP version is 7.3.1 I believe.  here is my code:

if ($validation = "true") {
    file_put_contents("ValidationsRedeemed.txt", $validationKey . "|", FILE_APPEND);
    //$handle = fopen("ValidationsRedeemed.txt", "a");
    //fwrite($handle, $validationKey . "|");
    //fclose ($handle);
                            }
else { //user entered a product key that is not recognized.  tell them to try again.
    echo "<script>alert('The product key entered is not valid.'+'\\n\\n'+'Please try again.');
    	 window.location.href='test.php';</script>";
    }

thanks!

Link to comment
https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/
Share on other sites

I tried this, gw:

if ($validation == "true") {
    //file_put_contents("ValidationsRedeemed.txt", $validationKey . "|", FILE_APPEND);
    $handle = fopen("ValidationsRedeemed.txt", "w");
    echo fputs($handle, $validationKey . "|");
    fclose ($handle);
                            }
else { //user entered a product key that is not recognized.  tell them to try again.
    echo "<script>alert('The product key entered is not valid.'+'\\n\\n'+'Please try again.');
    	 window.location.href='test.php';</script>";
    }

I put this line at the top of the php script page:

error_reporting(E_ALL);

when I run the script, I get a blank page.  there is no error log file on the server in the directory either.   ????

If you have a syntax error elsewhere in the script (and it sounds like you have) then it will not run at all, so your error reporting statement cannot be executed.

Error reporting needs to be defined in the php.ini file.

Berand,

I dont' believe I can access the php.ini file.  i remember a discussion between us about this a while back.  Do you remember that?  Here is what my setting is in the phpinfo() page on my domain:

Quote

display_errors                         Off                                Off

however, another line of the file says this:

Quote

log_errors                            On                                 On

 

Edited by ajetrumpet
59 minutes ago, ginerjm said:

One problem might be the very first line of your post.  That "if" statement is incorrect.

what's wrong with it?  is it spose to be 2 = signs or 3?  am I spose to check a boolean without the string in quotes?  I tried it with 2 = signs even, and that didn't work either.  sorry, I get confused sometimes with the difference between 2 and 3 = signs and the comparisons they're spose to make!

Berand,

I don't have an ini file yet on this hosting plan.  I will create one, which is ".user.ini", spose to be put in the root folder.  I'll get to it when I have time.  I'll let you know how it goes.  thanks.

Edited by ajetrumpet

A single = is an assignment operator, so

if ($validation = "true")

assigns the string "true" to $validation.

In your second code example you are checking equality correctly but your are checking if it is equal to the string value "true".

This will suffice...

if ($validation) {

as this means "if validation is true"

What comes to my mind is this:

if ($validation == "true") {

Notice the double equal signs.

This is saying the loop works if the variable $validation is the word TRUE not that $validation is true.

 

About what the same as Barand just posted.

 

BTW - I live in Urbandale, Ia

Edited by NotSunfighter

If you are getting a blank page then that means neither 'echo' is working and the code may be failing somewhere else. However, if the 'fputs' is outputting invalid HTML then that may also appear as a blank page. When that blank page is up, show the source to see if anything is there at all.

Edited by gw1500se

ok guys,

I sent the deployable to the requester with a workaround, so this is no longer relevant, however I will respond to all you guys:

=> yes i was trying to APPEND.  so I had that wrong as I was using "w".  thanks!

=> 'fputs' was embedded inside an ECHO statement in an attempt to see the number of BYTES fputs throw into the text file.  I got that debugging method from www.w3schools.com

=> I'm not sure what "showing the source" of the blank page would do for me.  I'm not even sure what you mean by that.  and how could 'fputs' output HTML?  that doesn't make sense.  isn't 'fputs' purpose to stream files, regardless if the process is "i" or "o"??  it's an I/O function, isn't it?

=> and YES, of course I know the difference between a freakin boolean and string!  i've been doing this job for 12 years!   😃

=> Berand, I really should have gone with your advice....if ($validation) { .....because it makes more sense.  I just picked a string in the form of "true/false" because it came to mind first.  no other reason.

=> NotSunFighter ------- you're not far from me.  where do you work?   would you be interested in connecting somehow?

this whole thing was simply an illustration for someone who wanted to validate product registration by checking a product key against keys that were purchased.  I used a combination of ms access, VBA code, HTML, CSS and PHP to accomplish the goal by sending the user to a webpage where they could validate their product by inputting their product key and then using PHP POST[] to do the work.  I know it's not the easiest way to do it, as the same can be accomplished with javascript with less coding, but that's what I had in my knowledgebase from years ago so it was easy to send to the person quickly.  It can easily be done in ms access as well.  but I've always hated that program because every release is extremely buggy.  and for good reason...MS makes no money with it so they obviously don't pay much attention to it's development.  If I was MS, I wouldn't care either.

Edited by ajetrumpet

Does this simple script work?

<?php
echo file_put_contents("ValidationsRedeemed.txt", 'This is a test' . "|", FILE_APPEND);
?>

(It should output 15 to the browser and add "This is a test|" to your file)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.