Link to home
Start Free TrialLog in
Avatar of Angha110
Angha110

asked on

Expiration date

I wanted to have an expiration date on one webpage which I made with Adobe Muse. I could use PHP or Javascript to achieve this. I can also have the expiration date in mysql as well.

My question is how to setup an expiration date for my webpage, so it does not show after the expiration date. Also, next question is how can I have this hiden, so the user can't check the view source and see the expiration date at all.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Angha110
Angha110

ASKER

I just did a test and it did not work,
Here is what I did,

I opened my myPage.html and add the php part on top of the page. and uploaded it to my server.

Please advice
Whatever you do, as long as the date is NOT coded in the HTML, it will not be visible to the user.  Put it in the php directly (as Angha110 shows), or in a database where you retrieve it with php, either would work.
It won't work in an HTML page, it needs to be a .php page so the php can be processed.
You have to name the page "myPage.php" so the PHP interpreter will be run.  You can also something similar in javascript.  Like this.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Javascript Date check</title>
<script type="text/javascript">
<!--
var today = new Date();
var d1 = new Date("January 4, 2014 11:13:00");
if(today > d1) {
	alert("This is expired.");
}
window.location.assign("http://www.google.com");
// -->
</script>
</head>
<body>
<h1>Javascript Date check</h1>

</body>
</html>

Open in new window

Dave - They don't want the date to be viewable
Then load it from an external file.  If it's "expired" and you get rid of the alert, no one will see it when it redirects.  And only developer will think to look in the external file.

Of course, they could just actually delete the file...
You can use PHP on an HTML page (one with the .html suffix) if you parse the .html files through PHP.  I do this with this line in my .htaccess file

AddType application/x-httpd-php5 .html .htm .php

If you use something like this, you can choose a solution like the one here:
https://www.experts-exchange.com/questions/28332787/Expiration-date.html?anchorAnswerId=39763536#a39763536
If you don't care that the user sees a 404 or similar, just use php and this:

<?php
if (time() <= strtotime("07/01/2014 12:00AM"))
{
?>

Put your whole HTML code here

<?
}


That will simply show a white page after the expiration date.
Or even this:

<?php
if (time() <= strtotime("07/01/2014 12:00AM"))
{
?>

Put your whole HTML code here

<?
}
else
{
  echo "This page intentionally left blank.";
}
As I think about this a little bit, it sounds like a "loaded question" with a subtext we may not understand.  Can you please step back from the technical details a little bit and just describe why you want to do this?  Why do you want the pages to expire?  Why do you want to keep the expiration date a secret?  If we understand the business reasons for this, we may be able to offer a more mainstream solution.
@yodercm
Why are you posting multiple solutions which are just a rehash of my initial solution with the only difference being you have changed > to <=
The only difference is that in mine, the result after the expiration date is a blank page, or a message, rather than a redirect to an error page.

Please note, Angha, that if you like my idea, be sure to share some of the points with cathal :)
I changed the html to php and it worked fine. (Thank you Cathal).

The reason I want this is to have an expiration date when I make demo pages for my clients. I want it to expire after certain date.

Also it would be nice to prevent them to copy the code from the demo which I believe need another ticket and conversation.

I think the php works fine, but maybe having the expiration in the database be another option.

What would you advice in these case?
It is not possible to prevent someone from copying HTML and images from a web page.  Every web browser that they would use to view it allows you to Save the page and images to their computer.
For that scenario you are just adding an unnecessary step by using a database to hold a date for a single page.  It would be easier to just hardcode a set date as and when you create the pages.

There would be nothing stopping them copying the HTML and there is nothing you can do about that
Thank you