Forum Moderators: coopster
The following code worked fine when it was right on the page, and is now working with the include statement written like this:
<td id="footer"><?php include "somefile.php";?></td>
This is what's in the include file:
<p> Copyright ©
<?php
$startYear = 2005;
$thisYear = date('Y');
if ($startYear == $thisYear)
{echo $startYear; }
else
{echo "{$startYear}-{$thisYear}"; }
?>
SomeSite. All rights reserved.<br>
<a href="http://www.example.com/">This disaster</a> has been created by me, no one else is to blame.<p><a href="http://www.example.com/sitemap.html">Site Map</a></p>
<p><?php echo "Last modified: ",date ("l, F d, Y", getlastmod());?></p>
All my includes always work perfectly using exactly this for the include:
<?php include ("../includes/somefile.php");?>
But: they have not ever included any code or functions in the included file before. This time, when I used the parenthesis for including {"somefile.php") for the above inclusion, I got a parsing error and it didn't work until I removed the parenthesis, and then it did.
Same server, same site: the difference was from including some code and a function instead of just plain text as usual, so it was a different syntax that waa needed.
Incidentally, what the above does, in addition to the outbound link for credit,
1) It automatically updates the copyright date from the beginning year to the current year automatically, without having to update it when a year rolls around. Like Copyright 2002-2007 will automatically change to 2002-2008 January 1st of 2008.
2) Last updated doesn't have to be tinkered with or typed in manually; when a file is updated and uploaded by FTP to the server, it will automatically pick up the new date for when it was last modified.
Less work for Mother: the footer section can stay the same, maintenance free, and still always be up to date.
I'm just learning and trying everything "technically challenging" (just simple stuff), and THIS is why I read this forum (and the Apache forum) regularly. I'd never spot things like this otherwise, and now I know how to use this and have it work. So thank you!
[edited by: Marcia at 1:36 am (utc) on Dec. 28, 2007]
These all work fine for me using PHP 5, what version of PHP are you using? Also what errors are you getting (please quote them minus exact file locations please). Your PHP script to keep the current year for the copyright is awesome!
- John
<?php
include "test-includes.php";
include ("test-includes.php");
include realpath(dirname(__FILE__) . "/test-includes.php");
?>
[edited by: JAB_Creations at 7:24 am (utc) on Dec. 28, 2007]
My PHP errors are always that a comma or semi-colon is either missing (expected) or unexpected - but this one didn't give a clue, it just said "Syntax error."
I redid it, and it's now working both ways at three different hosting companies on 4 different servers with different versions of PHP, including PHP 4.4.6, 4.4.7 and 5.25. The one with 5.25 also has a completely different setup requirement for using PHP on .html or .htm pages, which wasn't at all a syntax error - it was a configuration difference that had to be adjusted for (in .htaccess), and was.
Your PHP script to keep the current year for the copyright is awesome!
All the syntax for date() I found included the minutes and seconds, which I didn't want, but with a little cobbling together, it works fine without.
What's so endearing about PHP is that with just a basic going_through the syntax and a halfway decent idea of what the "symbols" mean, and a few dynamic things implemented on pages, you can get a "modular" system incorporated within a static HTML site without being a programmer and without implementing an entire CMS or template system.
Added:
It was the "Last modified" that was wrong at the university site. It had ".date (period/full stop) instead of ",date" (comma). The idea for the automatic copyright update I got out of a book I bought, and that idea alone was worth the price of the book, it'll save so much work and time in the future.
[edited by: Marcia at 11:27 am (utc) on Dec. 28, 2007]
Copyright
<?php
echo date('Y') == 2007? date('Y').' ' : '2007-'.date('Y').' ' ;
?>
MySiteName. All rights reserved.
<?php
/* ternary operator:
a shorter type of comparison operator
first: a simple "if"
then using the ternary
Let's set a value for color*/
$color="blue";
if( $color == "blue" )
{
$str = "the sky is blue";
}
else
{
$str = "Help: The sky's falling on our heads!";
}
// using ternary
$str = ( $color == "blue" )? "the ski is blue" : "Help: The sky's falling on our heads!";
echo $str;
/* using it in a form
if you want to keep a value back and forth */
<input type="checkbox" name="contactmethod[]" id="email_contact"
value="Email" <?php echo (isset($_POST['contactmethod']) && in_array('Email',$_POST['contactmethod']))? 'checked':'';?> />Email
?>
My PHP errors are always that a comma or semi-colon is either missing (expected) or unexpected - but this one didn't give a clue, it just said "Syntax error."
hehe, don't mean to laugh Marcia, but we've all been there! As you have also likely heard or read before, get yourself a good text editor with syntax checking and highlighting. Loads of options available -- I'm using Eclipse now personally and absolutely love it. It is open source so it is free but it does have a bit of a learning curve, but well worth the investment of time.
BTW, the last modified trick here works great for sending the appropriate headers in dynamically generated pages too ;)
We seem to get a spate of threads around the first of the year from two groups -- Those in a panic to find a fast/easy way to update the copyright notice on all pages of huge static sites, and those who are waiting to 'pounce upon' and copy sites that don't update their copyright notices; The former generally need not bother, and the latter should be looking for a good attorney... :)
Because some works change infrequently, you may find copyright notices for changed content that read something like, "Copyright (C) 1997, 1999, 2003-2005, 2007 The Widget Corporation." But unless your content has changed, it is not necessary to "renew" your copyright notice.
Jim
Like if a person is claiming copyright for a site that they were never given rights to by written transmission, in which case the creator retains copyright - but they've removed credit and said Copyright = them.
Internet archive and screenshots showing the "originator" with Copyright 2002-2006 documents that the usurper did not, indeed, display it for their name (or business) during the entire time period (until the change, which is also documented), and unless they can come up with documentation that written transmission was made (which they can't), they don't have a leg to stand on when DMCA complaints are sent to the host and the search engines.
I've had people pull dirty stuff more than once, one just recently. So if it's easy enough to do, it can pay to.