[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP question

Posted on 2011-10-04
7
Medium Priority
?
367 Views
Last Modified: 2013-11-10
I have a very basic question - just started using cakephp and i am having trouble getting my index page to render.

I have two pages: 1 is the index page and one is the expiration page. I have a date set, and if the current date does not exceed the $expiration_date, the index page is supposed to render. I keep getting a 404 error - am I doing anything obviously wrong?
<?php

class ftaf2Controller extends AppController {
	/**
	 * @access	public
	 * @var		string
	 */
	public $name = 'ftaf2';

	/**
	 * @access	public
	 * @var		array
	 */
	public $uses = array(
		'Coupon'
	);
	
	/**
	 * @access	public
	 * @var		array
	 */
	public $components = array(
        'Session',
		'EmailDeployment'
	);

	/**
	 * beforeFilter callback
	 *
	 * @since	0.3
	 * @access  public
	 * @return  void
	 */
	public function beforeFilter() {

		$expiration_date = '2011-12-06 00:00:00';

		if (date('Y-m-d H:i:s') > $expiration_date) {
			$this->render('expired');
			exit;
		}

 public function index() {
		 } 
	
	}

?>

Open in new window

0
Comment
Question by:lvollmer
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:seanmccully
ID: 36910483
First you are not comparing dates  correctly, use the strtotime function to compare dates.
0
 

Author Comment

by:lvollmer
ID: 36910494
can you show me an example of what should be done?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
Chris Harte earned 1000 total points
ID: 36910658
You cannot compare date strings like that, convert them to timestamps

$expiration_date = '2011-12-06 00:00:00';

$ex_date = strtotime($expiration_date);

$now = strtotime(date('Y-m-d H:i:s'));

if ($now > $ex_date)
{
    $this->render('expired');
    exit;
}
0
 
LVL 13

Assisted Solution

by:Hugh McCurdy
Hugh McCurdy earned 1000 total points
ID: 36910706
MunterMan makes a good point.  I also think it would help you to learn if you saw what was going on.

Put these printf commands before your if statement.

printf ( "Raw now = %s<br />\n", date ( 'Y-m-d H:i:s'));

(If you are running PHP from the command prompt instead of using a web server, you can leave out the <br />)

printf ( "Cooked now = %s<br />\n", now );
printf ( "ex_date = %s<br />\n", $ex_date );
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36910707
Oh, remove the printf statements after you understand what is happening.
0
 

Author Closing Comment

by:lvollmer
ID: 36911033
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

872 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