Can someone tell me what the 3 stands for in this URL?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
tommytx123
New php-forum User
New php-forum User
Posts: 23
Joined: Sat Sep 19, 2015 4:57 pm

Tue Jun 22, 2021 12:50 am

Code: Select all

error_log(‘Invalid input on user login’, 3, ‘/var/www/example.com/log/error.log’);
I have been using this type url quite a lot and I assumed that the 3, meant if there was no file it would make one and if there was a file it would append to it.... however I want it not to pend and simply delete and existing content and put the fresh new into the file... I tried a 2 and a 4 in hopes that would work but it did not for me..
Can anyone tell me what the digit is for writing.... no appending... maybe I just made a mistake...
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 137
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Tue Jun 22, 2021 1:12 am

From the documentation
message is appended to the file destination. A newline is not automatically added to the end of the message string.
If you want to completely overwrite any existing file with just this log entry, "error_log()" isn't the tool you need. file_put_contents will do it:

Code: Select all

file_put_contents('/var/www/example.com/log/error.log', 'Invalid input on user login');
I'd double check that's what you really want though; a log with only one entry in it isn't very useful.
tommytx123
New php-forum User
New php-forum User
Posts: 23
Joined: Sat Sep 19, 2015 4:57 pm

Tue Jun 22, 2021 9:38 am

Code: Select all

function idx_register_user(){
    if(!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['email']) && !empty($_POST['phone']) && !empty($_POST['pw'])){
        $userdata = [
            'user_pass' => get_option('idx_vow_mode') === 'onx' ? '8675309' : $_POST['pw'],
            'user_login' => $_POST['email'],
            'user_nicename' => $_POST['firstname'].'-'.$_POST['lastname'],
            'user_email' => $_POST['email'],
            'display_name' => $_POST['firstname'],
            'first_name' => $_POST['firstname'],
            'last_name' => $_POST['lastname'],
            'phone' => $_POST['phone']
        ];

error_log(json_encode($userdata)."\n", 3, '/home/myuser/public_html/wp-content/plugins/IDXSEO/include/ALL-LEADS/TommyLeads.htm');

Thanks for your response.... Let me explain exactly what I am doing and may you have a totally different and better approach.. So details:
1. yes a one line file is perfect since I need to capture all the data from a Modal register form for reformat and transfer to a hidden form so i can use the data normally from the Modal form I cannot find... hidden by a horrible developer that left town... he also encoded my site just before he left... i did get that decoded but the modal real estate registration form is hidden and no amount of searching can find it on the site. I used the tool box in chrome to find and the point to grab the data it captures but cannot find it to make minor tweaks so am working around it... Horrible story, If you are a good modal finder... I can pay a fair price.. to locate it.. Actually I have found some indications that the hidden form may be on another site but I don't know how to prove that.

2. The reason i used this line of code (and not file_put) is that its seems to be a simple way to grab all that data into a single file and it saves as json. Normally the .htm at the end would be .json but I found my security system did not like me loading a json file from that area. So i tried .txt no help... .htm and bingo it allows me to load that file and convert it to an array so that i can assess the data to send on my hidden form to the mautic Api and database.

3. So yes i understand that it has no newline so can see i simply added one.. and i was guessing changing the 3 to a 2 might write over the old and it works great. Works great but the 3 i think is append so it does append.. and not what i need.. I need write each time.

<quote>A newline is not automatically added to the end of the message string</quote>

4. I started out as you suggest file_put_contents.. but not sure if i can send the jason_encode data in a file_put.... i can try again.. but did not work... I may have coded it wrong.

5. you sent some notes from the docs... saying no newline... i looked for docs for this and could not find.. did it mention what he is getting from the use of the ,3 as the \n is obvious but not the 3.

6. I will be fine using file_put if I can grab that same data fields listed like first_name etc.. but do not know how to convert it to go down the file_put and text mode... Heck would love to save all the variables shown as txt line comma separated or even | vert bar separated..... can you help there.

7. Bottom line all i need is the data from user $userdata but its in json there....it hates txt handling.. so i guess that I need to somehow convert $userdata to text variable.. then i would be in hog heaven..

8. To explain why I must delete the file for each run is that i only want to grab this data immediately after i run the hidden modal register form and use and and when the next customer comes along i want it empty. I thought about letting it build up and just use the last entry but much simpler to delete the last contact info..as I no longer need it.. its now safe in the db..

9. Thanks for your interest and help and i hope this explanation gives you more ideas on how you can help me... and let me know if you are curious and i can dump the "Developer hidden modal details" to see if you have any ideas... I would use a new thread.. but the missing modal is not part of this thread.

10. If something does not make sense... let me know to further explain as I am desparatly in need of help on both projects... this one and the hidden modal registrar form..
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 137
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Wed Jun 23, 2021 11:07 pm

Both error_log and file_put_contents accept a string to put in the file; json_encode($userdata) will work fine. If it didn't work for you once, I'd guess there was an error elsewhere.
Post Reply