PHP – Do Until Certain Date
UPDATE: Since I often use this bit of code to do things like display rel=”nofollow” on a link after a certain date, I’ve written a shorter, inline snippett to do the same thing. Keep in mind when copy-n-pasting the code below you may have to change the fancy quotes to regular quotes:
<?php if (date(“Ym”) > 201101) { echo ‘rel=”nofollow”‘;} ?>
I’m not
deep into PHP, so I wrote this ‘hack’ to allow HTML or whatever until a certain date. The sample below will do whatever HTML is until a certain date…
<?php
$mymonth = date(“m”);
$myyear = date(“Y”);
$mycompare = $myyear . $mymonth;
// if its before Jan 2010
if ($mycompare < 201001) {
?>
<p>Before 2010!</p>
<?php } else { ?>
<p>Its 2010 or later!</p>
<?php } ?>
ABOUT COMMENTING ON THIS BLOG
Comments are moderated by a human and will be approved if they bring value to the discussion. This means comments are on topic, relevant and useful. Here are some ways to insure your comment is rejected, marked as spam or will be edited (at my discretion):
- Using keywords, business names or website names in the Name field
- Putting a spammy site/page in the Website field
- Foul, abusive or discriminatory language
- Comments for SEO only purposes
No trackbacks yet.
about 1 year ago - No comments
Sometimes PHP_SELF doesn’t do what I need when I’m trying to programmatically find the name of a web page on-the-fly on certain dynamic sites I’ve worked on. for example, I might want to show or hide Adsense, or banners or something based on the page’s name. In these case sometimes this PHP $_SERVER variable works
about 1 year ago - No comments
Using PHP to redirect to another page is a common task, especially when you are working with email forms. Fill the form out, process it, then redirect to a “thank you” page: <?php header( “Location: http://www.example.com” ) ; exit; ?> You can also use variables for the URL like so: <?php $destURL = “http://www.example.com”; header(
about 1 year ago - No comments
You can use PHP to track how someone got to a specific page by grabbing the referring page, called the referer. Use this code to get that info: <?php $myReferer = $_SERVER['HTTP_REFERER']; ?> NOTE: Watch the code above, depending upon my current CSS in my current theme the single quotes or even double quote may
about 1 year ago - No comments
For building sites that can more easily be moved from one server to another, and allows simpler updating of common information like email address and phone number of the client. Here’s some PHP to generate paths: both server paths and domain paths good for use in all sorts of ways for include and require statements.
about 1 year ago - No comments
The PHP Do While, just a quick post so I can find this later without Googling… <? $i = 0; do { // do something } while ($i > 0); i++; ?> MORE PHP Do While on PHP.net
about 2 years ago - 2 comments
UPDATE: Better code. Creds for this updated code to my buddy Seth Furchgott who did the googling and grabbed the following from PHP.net, much better than what I originally posted below. <?php date_default_timezone_set(‘America/New_York’); echo date(‘g:i A’); ?> Documentation for timezones: http://us3.php.net/manual/en/timezones.php (get time zones here by Continent…and Ocean) http://us3.php.net/manual/en/timezones.america.php (US timezones) OLD PHP TIME POSTS