I'm trying to create a button in my website that counts the clicks and saves them to a text file on the server. I managed to make everything else work like it should except sending the data to server.
I tried using PHP but that requires page refreshing and I don't want that.
Basically I need some help on how to overwrite a server text file with a variable (without having to refresh the page)
Is it even possible to do this without using PHP? (Page refresh everytime data is saved)
Thanks in advance.
Related
Currently I am working on one project, that is a little complicated for my programming capabilities, so the general idea might be wrong. I need to do just one more thing to make everything functionable. I am using local storage in order to temporarily save data from page1.php and after that, display data on page2.php. But when I load page2.php, there is no data because I did not load page1.php first (it is needed to send data to local storage).
The user for his needs does not have to load page1.php first and that is a problem.
Is there any way to reload page1.php when any other page is loaded in order to save data on local storage. In JavaScript or PHP. Thanks in advance.
I tried some manipulations with reload() function, but did not find any solution.
I've been working and programming for a lot of time, but this simple yet a bit complicated question is always in my mind... this will be about core and plain PHP.
I want to know how can I archieve having just HTML/js files interacting with the server without changing the extension from .html to .php as effective as possible using just the necessary requests.
for example:
I have this website that has a login page:
the user types his username and passwork and its sent using AJAX to auth.php
auth.php do its thing then creates a $_SESSION if valid
the user gets redirected to dashboard.html
Now, how do I get in every reload the current user in the frontend? I can get it in the backend just calling for example $_SESSION["username"] for the purpose of having "welcome [the current username]".
The only solution I've got is to do in every redirect/refresh a AJAX request to ask for that (the request is sent to the PHP script and it echoes the session username for example) but I think this would get very heavy for the server.
what are your thoughts?
I'm trying to make a comment section for a locally hosted site, basically I am trying to make it so when you hit the submit button, it checks for a existing file, if it exists, then it will edit it, and put the comment into it, if it doesn't exist, then it'll create the file, and save the data, I'm trying to save it as JSON if possible, any ideas?
The only things I can find are to let the visitor save to the computer, which isn't what I'm trying to do, I want the site to only be able to access it. And I'm trying to not set up a server if possible.
You will definitely need some kind of backend server to do that since JavaScript runs on the client side. I can only recommend taking a look at a NodeJS http server that changes the files according to GET or POST requests or using said GET and POST requests in combination with a server-side PHP script.
It's surprisingly hard to find a definitive answer to this, I'm 95% sure what I'm trying to achieve is impossible, but here goes:
Front:
I have a multipart/form-data upload form. A user selects a file, but has to be logged in before he can post the form. The user can log in via Twitter. If he does so after selecting a file, due to the redirect to/from Twitter, the file input will be empty.
Back:
I have a PHP script using the $_FILES array to move the uploaded file to its final destination. (A solution to my problem would be to save the file to a temporary folder before redirecting to Twitter, but I currently can't set that up).
Problem:
I can store the selected file in localStorage using the FileSystem API (at least in modern browsers). But I obviously can't put that back in the input element. Now I'm at a loss: is there any way to get that file from my localStorage into the PHP $_FILES array?
Login to Twitter via ajax. This way you will stay on your current page and the file input will stay filled.
I have a online web application form which I have to open every time and have to fill data and Submit.. So, I have got an idea of making a Google Chrome extension, that will make that page stored inside localStorage So that I can access it like a desktop page.. Is this possible.. I do not have any permissions to change the web site at server side.. I am just a client side programmer.. Is it possible? if yes please let me know how can I achieve this..
in theorie, yes, you could. Practically, it won't work out like you want. The reason are the external resources the website is going to be needing.
Storing just the html (document.body.innerHTML) would be possible. BUt if you want the formatting/layout to be happening, you'd need to save the computedStyles for each element as well. And if an image, you'd need to Base64 encode the image and save it.
Even if you'd succeed in saving the page, you'd need to know when to expire your localStorage cache and refetch the resources to stay compliant to the server side parsing of the form data (if they'd change something).
if its just about submitting a form, you also could just trigger the forms post-action-url directly by writing a script that resends the data you want sent.