php posting messages with future date - php

i am implementing a forum in php. I Would like to add a feature in which user can add a post by setting some future date so that on that date in future the post will be displayed. Could anyone give me an idea how to implement that(logic).

Submit the post to the database with a future time and, when you query it to find the posts, limit the results to those whose time is less or equal than the current time.
If you still want to distinguish time of publication from time of submission, you can have one column for each and display the post based on the time of publication.

Related

Executing a script at an exact time in future

I work on a PHP project where users place advertising posts. When advertising post is placed online it is given a "hide date" (stored in database), when it will no longer be shown to the users. When "hide date" (e.g. next Monday at 10:00am) occurres I need to fire a script that makes changes in the database (not related to hiding the ad).
Question:
How do I run a script at the exact time in future(at "hide date").
I google'd a lot and didn't find any good solution.
Found possible solutions:
Cron isn't considered any more because of its lack of accuracy (for my task even seconds matter).
Write a daemon which will check every second if there is a record with a "hide date" but it can be very consuming.
Another way as I was told that message queues could be of help, but after reading some of the documentation I didn't find a way of setting date and time of processing the message in queue.
Can anyone point out where to look? Any tool/language is considered.
Let's suppose that ads show until a week after
Create a field in your ads table called expiry_date (timestamp)
When a new ad is inserted, do the following
$expiry_date = strtotime("+ 7 days");
Then insert the expiry date along with the record
Next, in the page that displays the ads, select only ads whose expiry date did not pass yet, so
SELECT * FROM ads WHERE expiry_date >= NOW()
This will only show ads that didn't expire yet.
If your site is running on a linux server, you can add a cron job to trigger your update script.
If your site is running Windows, use Task Scheduler instead.
However, it doesn't really sound like your best solution. You could store the "hide date" in the database along with the rest of the post's data. Then you can simply filter the posts in your display code.

how to add expiration date to a member?

I have a Log in and register form connected to my database, I want that when someone registers as a member for the membership to last three months and then expire.
In order to do this I want to assign the value "1" to the member in the "membership_level" field in the "user" table inside my database, then once the membership expires I want the value in the "membership_level" field to go to "0".
How can I code this in php?
I have being looking for a good tutorial but I can't find any.
I won't be going into detail, however as no one has actually answered the question, here you go:
(I will not be providing code)
Create a "register_date" table in your database or similiar and populate it with the time() of register.
With that you can, as Jon stated in the comments, compare it to the current time upon successful login and depending on if the time was greater or less than three months, create the session.
If you didn't create the session, then header() it out to the index, or use another method such as a flash message class.
Hope this helps you.
As Mike stated, this isn't a free coding service, please next time provide what you have tried and show your research.

How to prevent adding twice on booking system

I have an booking system time, where the user can book a time let say an hour within a specifik date. My question is i cant handle the case when for ex i open in two tabs the site and i try to book a time from one tab and then it displays on the calendar that the booking is done, but since in the other tab the page is not being refreshed and it shows still avaibale the time to be booked and i can book it, so then it shows me two, i mean i can open as much tabs as i can and do the same, how could i prevent this to be able only one time in a specific date to be booked???
You can write some script which will returns aviability of any period by request. Than, in your booking page make a simple Ajax query to check if selected period is still available and run it by setTimeout(). If request will shows you that period is already booked you can notify user by showing him relevant message and disable form submition until valid period will be chosen.
this will also helps you in case when someone will book selected date while other user is thinking of it :)

Get dynamic time and timeout after certain amount of time

I am implementing an online exam portal, so that a user can start the mockup test(exam) and choose the anwsers for each question and proceed to the next question.
Rules for the exam is to give 100question to complete in 75mins.
So I need my back-end code to check each bit of time and track if the current_time not exceed 75min from the Exam_Start_time
How is this possible.
I made it like this for time being
$Start_time
$Current_time
and then check the difference on each page refresh and redirect if 75min limit exceed
But I think its not the better way and if we can trace it dynamically and redirect when the 75min mark reaches to the process the exam result it would be great.
Can any one help me in this context,
Is there a way if its not possible with PHP, HTML to use Javascript to achieve this
Hope to hear from you stacker.....thanks in advances
Store in your database time and some unique id for each user. While user take a test send ajax request with some interval (i.e per minute) to the server with user unique id and check is everything ok with time if not redirect him to another page or block old one with javascript. But think about security, some user can guess and send another's id :)
If user disable javascript there is another scenario. Server closes tests which hasn't been updated for some interval. And also about local time and javascript you haven't to send user's time to server because you have start time in database.
#trejder and #Wiz if think as you do it's better to do not use javascript at all as it can be turned off and request variables can be falsified by user.

Tracking Users - Custom PHP/MySQL Website Analytics

I run a local directory website (think yelp/yell.com etc) and need to provide analytical data to the businesses listed on the site.
I need to track the following:
1) Number of visitors to specific pages (ie: Jim's widgets was viewed 65 times)
2) Number of times a user clicks a link (ie: 25 users clicked to visit your website)
I am able to do this by simply adding one to the relevant number every time an action occurs.
What I would like to be able to do is split this into date ranges, for example, last 30 days, last 12 months, all time.
How do I store this data in the database? I only need the theory, not the code! If someone can explain the best way to store this information, I would be extremely grateful.
For example, do I use one table for dates, one for the pages/links and another for the user data (links clicked/pages visited)? The only solution I have so far is to add a new row to the DB every time one of these actions happens, which isn't going to scale very well.
Thanks to anyone that can help.
I would not reinvent the wheel and use an already available solutions such as Piwik. It can actually read your normal weblogs to provide all the information you asked for.
If for some reason you still need a custom solution, I would not save the tracking data in ranges, but rather use exact time and url-data for each individual page call (what your normal weblog provides). The cumulated data should be generated on-the-fly in your logic section, e.g. through a SQL-view:
SELECT count(url),url
FROM calllog
WHERE calldate > NOW()-30days

Categories