Jump to content

how to expire php page after 7 days from page load on server in php ?


reutorah

Recommended Posts

I want to make a page expire after 7 days from page loaded on the server without giving date and time, i mean auto expire php page after 7 days from page load, how can i do that, with what code. After 7 days page redirects to a url.

 

I already tried and know some code in php which can expire php page on given day and time but i need a code which will expire php page after 7 days of time it is loaded on server.

 

Can you please post with the code.

Link to comment
Share on other sites

Whatever do you mean by "expire a page"? What does that mean to you? A "php page" is merely a script. It sits on the server and does something for you when called. That said, I find your question difficult to comprehend. Do you mean you want the script to no longer run when someone types in its url, as if the script had been deleted from the server?

Edited by ginerjm
Link to comment
Share on other sites

Not sure why are making a php script expire, usually what is done is the url has parameters and is a dynamic script with different values. Something like using a database and checking a datetime for the value for insertion date would determine how old it was created.

 

If you still want to make many php files and block access you would need to either include a script with code to all created pages or use dynamic page values that the script then includes. Use filetime, compare to see if modified date is older than last 7 days.

 

 

If you stored all these files in a single folder, you can create a php script and create a cron job to run every day. The script would glob a folder and delete any files older than 7 days. Have your 404 error handling set up to either home page or a custom error page.

This method would help keep your server cleaner and not have piles of files no longer needed.

<?php
$files = glob("/path/to/directory/*.php");//change to path you need

$now = time();

foreach ($files as $file) {
    if (is_file($file)) {
        if ($now - filemtime($file) >= 60 * 60 * 24 * 7) {
            unlink($file);
        }
    }
}
?>  
Link to comment
Share on other sites

i have a php script that i want to provide my visitors for free trial and i want to simply add php code encrypted in php page where my visitors will upload my script on there server and since the first time the page has been run i want it to expire exactly after 7 days. I mean i want the page to redirect to my website purchase page.

 

What is the exact process ?

 

is there a way i can test the code working with 5 seconds of expire ? 

Link to comment
Share on other sites

I can think of many people NOT wanting to upload any script of yours (or anyone's) to THEIR server. Thatis if they even HAVE a server of their own. I know I wouldn't and it's a good guess that those in the know on this very forum would not do it either.

 

I'm thinking that you have some kind of registration process that would then lead to this "uploading" scheme of yours. Why not use that registration as an access method to the script on your server? When the registration occurs you save the date of it. When that date reaches an age that you wish to expire the user at, mark the user's reg record as expired and do your re-direct thing.

 

You may argue that the registration can be cheated by a user who creates a fictitious second or third userid. Sure that can occur, but so can the process you envision where the user would be uploading the script to their server.

  • Like 2
Link to comment
Share on other sites

You want to destroy code on somebody else's server? This is, thankfully, impossible. Once it's on their server, it's under their control, and there's nothing you could do about that.

 

If you don't want people to actually use your code, don't give it to them. Put it onto your own server and make it available after some registration procedure. Then you can easily block access after a certain trial period.

  • Like 1
Link to comment
Share on other sites

You want to let them upload your script their server and expires?

 

One thing have to understand is that anything you write the person can edit their php file.

You can try obfuscation to make it harder, all it will take is one determined person to reverse it and share with the world for free.

http://www.zend.com/en/products/zend-guard

http://www.phpprotect.info/

 

You want something that has to check a domain or key, alternately a required snippet of code from your own server for their script to work.

 

Let me say a few possible ways can do it.

 

Creating an api system, you allow domain or private key usage for the script.

 

Tracking domains your server, they download a copy of the same script(only one version needed), the script connects to your server to determine if allowed.

 

Write into the code a key, when the script is accessed it looks for that key.

The way it would find the key is connecting to your server and check for it a list however you wanted to save such keys.

Link to comment
Share on other sites

my script is phpsunchat www.phpsunchat.com its a instant messaging chat script i want to offer my chat script for free 7 day trial or possible 15 days trial.

 

So what i want to do is i want my visitor to download my script from my website for free and when he uploads the php pages from the ftp software and when anyone from browser opens any page of the script it records the date and time the page loaded the first time and expires the page exactly after 7 days and redirects the pages to my website www.phpsunchat.com 

 

The time needs to be set on first load page bases and i just want to add few lines or php code in my pages and if they edit my code they cheat and i can any time complain there host so i am not worried on my chat script to be edited.

 

I am concerned for those websites who have large chat traffic and optimize for public.

 

Any code suggestions ? 

Link to comment
Share on other sites

You have already been told many reasons why you can't or shouldn't do this thing. #1 - if you give them your code you're done. They should send you a thank-note before they take your hard work and change it to suit them. (This would be very generous of you!).

 

Do what others here have said. Sign people up for a free trial and record their individual start date and user id. Be sure to store your main code outside of your webtree so they can't steal it and let them play until their time runs out. Put the entry page in the web tree and get their login creds there.

 

Anything else is just not gonna be good for you.

Link to comment
Share on other sites

Besides that, why on earth would anybody upload trial software to a public webserver? What are they supposed to do with it? Tell all their users about it and then take it offline 7 days later?

 

I'm sorry, but your business model makes no sense.

 

Also, why should I pay $50 per month when I can get an entire entry-level dedicated server plus a free(!) chat script for the same price? What makes your code so incredibly special compared to the thousands of open-source chat scripts on GitHub?

Edited by Jacques1
Link to comment
Share on other sites

It's not a waste. You got very good advice. You have just chose to ignore it in your anger at being told what was wrong with your design. Don't feel bad - we all make mistakes when starting out. Of course your choice is going to cost you money. I'm pretty sure that your choice of developer is going to also agree with what you have been told here. If you pay him/her enough money he just may do what you want. But then when you eventually see the problems with your design, you'll have to pay him/her to correct it.

Link to comment
Share on other sites

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.