Solved

Expiration date

Posted on 2014-01-07
17
326 Views
Last Modified: 2014-01-07
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.
0
Comment
Question by:Angha110
  • 5
  • 4
  • 3
  • +2
17 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
<?php
if (time() > strtotime("07/01/2014 12:00AM"))
{
	header("HTTP/1.1 404 Not Found");
	header("Location: http://www.mysite.com/404.html"); 
	exit;
}
?>
<!DOCTYPE html>
...
,..

Open in new window


It's PHP so cannot be seen in the browser
0
 

Author Comment

by:Angha110
Comment Utility
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
0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
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.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
It won't work in an HTML page, it needs to be a .php page so the php can be processed.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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

0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Dave - They don't want the date to be viewable
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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...
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28332787.html#a39763536
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:yodercm
Comment Utility
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.
0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
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.";
}
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
@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 <=
0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
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 :)
0
 

Author Comment

by:Angha110
Comment Utility
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?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
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
0
 

Author Closing Comment

by:Angha110
Comment Utility
Thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now