Joshua Z.
Joshua Z.

Reputation: 17

Banner expiration variable, how to grab across pages?

I've got a page displaying multiple banners on large-format displays. The banners are placed by hand into an array on one page (main index page per display), and then an include is done on the content-rotation code.

I recently jury rigged code to incorporate an expiration on the banners for when our web designer isn't around to change them after the event on the banner has passed. I made a 2nd array on the index pages and filled it with "mktime(0,0,0,0,0,2020)" (don't expire anytime soon) as dates in the same array spots as the banners from the first array ([1] from the first array would correspond to [1] from the 2nd array) and then added code to the content-rotation page to only display the banner page if the date minus today (time()) was greater than 0.

This is my execution as a java programmer... Obviously I'd want to embed the expiration times into the individual pages but I don't know enough PHP to know how to pull a $expire variable from each page, unless I'm thinking too much like a java programmer. In any case is there a better way of executing this in php?

Upvotes: 0

Views: 114

Answers (2)

Emil Vikström
Emil Vikström

Reputation: 91922

  1. Place all code relating to the banners in a separate file. Let's call it banner.php
  2. Use require to automatically include this file on all pages

I would also consider having everything about the banners in the same array. Let each array element be a new array with the banner address and the expiration date. Or even better (this should be familiar to you as a Java programmer): create a class for banners and let each element in the array be an object of the banner class. Let the object have the expiration date as a property!

Upvotes: 2

Phil Young
Phil Young

Reputation: 1354

Maybe try using sessions & session variables? http://php.net/manual/en/features.sessions.php

Upvotes: 0

Related Questions