Run PHP page automatically in server with Wordpress - javascript

I am developing plugin in WordPress in which I want automatically and regularly call of PHP page if user visit the page or not.
Basically I am storing the date when user access the website and want to send mail using PHP file after one week. I am storing the current date and next week date in my plugin database. When one week passed and next date is arrived I want to send them mail.
As per this question, we can create JavaScript and make AJAX call to particular PHP page, compare current date and if next date in database and current date matches we can send mail.
But what if someone ain't access my site for next 10 days? Then there is no AJAX call for my PHP page, right?
I mean that JavaScript and PHP page will not going to executed and mail will not send.
Plugin will be on any server and may be that server not allow for schedule task, so I think cron will also not going to work.
I want to call my PHP page if someone access my site or not. How can I do this process?
Your help will be appreciated. Thanks in advance.

I think you need to break this problem down into smaller components.
If a user visits your site, make an AJAX call to update the date and time he accessed the site. That's the first step.
Next you'll need to have some type of scheduled job, if you're using Linux, you could use a cron job. This will run through and send the mails by checking the last time that the user logged in.
See more information here: Newbie: Intro to cron

Related

Reload data on change

so I will try to be as clear as possible on my question!
On my site I have a table with the latest reservations, it's a fetch request that retrieves the data in PHP in JSON format and Javascript that puts them in shape, it works very well. But now I would like to go one step further, and make an automatic system, which would only have the Javascript function to retrieve and format the data. But I would need to do this without having to do a setInterval() or wait for the user's click, somehow only when a row is added (which is not done by the admin but the system the detect), the array is reloaded. I don't know at all if it's possible or not, and that's why I'm asking here?
(I only work in Javascript with Jquery and with PHP, I don't know if I need another lib?)
Thanks in advance and have a nice day!
I think if you use websocket, you can get better system.
but, if you can't, I recommend you use setInterval() to check if the row added.
You can install websocket server with nodejs easily.
and you have to add send event from php to nodejs ( http ) when new row added in your PHP server.
and add javascript websocket client.

Building a javascript web analytics tool from scratch

I am fairly new to javascript, I do know basics. I am looking to build my own (from scratch) java script library just like google analytics.js that will track user behavior on websites. Basically I'm looking to collect data like
Click through data
Dwell time
Page hits etc..
I spent lot of time trying to find website/tutorials to get me started on this but I keep ending up on google analytics.js or some private tools.
What I am looking for :
Is there any good starting point/resource/website which can help me build this js library
Are there reference for archetecture of end to end system including back-end?
Any open-source library that I can directly use?
Some things I already looked into
Chaoming build your own analytics tool
Splunk BYO analytics
At it's most basic, the architecture of such an application would only require a client, server, and database.
You can use basic javascript functions to record specific user actions on the frontend and then push them to your server. To identify your users you can set a cookie with a unique id. Then, everytime you send data to your server, you will get the specific user request as well so you can keep track of their actions. (Be careful of privacy laws first though).
For page hits, simply send a response to the server everytime someone opens your site - so call this function as soon as your Javascript loads. On the server, send a request to increment the appropriate value in your database.
For user dwell time, write a function that records the date when the user first hits your site and then count how long they stay there. Push your data to the server every so often and save updates to the user record by adding the new time spent to the current time spent. You could also watch for when a user is about to exit out of the site and then send the data all at once that way - although this method is more fragile.
For clicks and hovers, set up onclick and mouseover event handlers on your links or whatever elements you want to track. Then push the url of the link they clicked or whatever data you want - like "Clicked navbar after 200 seconds on site and after hovering over logo`.
If you want suggestions on specific technologies, then I suggest Node.js for your server side code and MongoDB for your database. There are many tutorials out there on how to use these technologies together. Look up javascript events for a list of the different things you can watch for on the frontend.
These are the building blocks you need. Now you just have to work on defining the data you want and using these technologies to get it.

Java script date object

Does the date object get the values from the operating system locally ? what if someone changes his time value , in my project I need to implement a system for reserving food, in my case the user can't make request for food before 10 am , but what if one of the users change his current time ?
I think that the best choice is to get time value form backed side.
any suggestions ?
Everything you do in javascript is client side, it's executed in the browser of the user, so your date object will be created depending on the client's browser.
Moreover, all the validation about the time has to be server side to prevent any kind of alteration. You have to perform ajax requests and make sure on your server that the client is allowed to buy food.

a Method to Updating REST API data in periodic time?

i dunno how to put it. Hope the title is right for my problem or scenario.
I want to build a REST API, with a data coming from many rssfeed web. Right now, i'm able to fetch the data using a script javascript and saving it in my database. To be able fetch that data, i have to open a page so the script will be able to run and reload every 1 minute. The Rest Api is still in localhost by the way.
The Question is, what if i want to host it, should i have 1 PC to
always running 24 hours which only open a browser and access a REST
API address so the script will keep running and the data will always
be up to date?
Right now this the only method in my head, is there any method that i shouldn't have 1 pc to running 24hours a day seven days a week.
The best solution of your problem is to setup a scheduler that will be running on a predefined period, and fetch the data and store it in DB internally and you don't need to open a page to do that if you are not modifying the response returned from rssfeed.
You can go through this, Post , Tutorial, Node-Schedule, Parse. These are some of the example which you can use based on your requirements

Passing values from one page to another page in JS

I have one query on JavaScript.
How we can pass values from one page to another page?
I am working with ASP.NET. My requirement is, I need to validate the user, whether his session expired or not. If the session expired then I need to show a pop up with two textboxes to enter his credentials.
In which case I was unable to do that in ASP.NET. So though of doing with the help of JS. But not getting ideas.
I know we can pass values from one page to another using querystring. But as per the security purpose that is not to be used in my app.
Please help me out.
Thanks in Advance.
Don't do that on the javascript side. Remember that you can't trust the client side.
Use ASP.NET to do this.
See this tutorial to get some help about using sessions: http://www.beansoftware.com/ASP.NET-Tutorials/Managing-Sessions.aspx
You can save the users info in a session, for example his id and current request time. Then you can compare the previous request time, which you saved while processing the previous request, with the current time. You save the current request time in the session again. If it's been to long ago you show him the login popup. If you need a more secure way of passing the login credentials I recommend using a ssl certificate.
You can set cookies. That's also not really secure, but it's obviously a lot more secure than query strings, though if you're dealing with something that requires more security than what cookies offer, then I would suggest that you're doing something really wrong. (Welcome to Stack)

Categories