Log in

View Full Version : Swap image on a certain date? +rep



Jamesy
16-11-2007, 07:54 PM
I was wondering if there was a script or something to swap an image on a certain date, because I won't be online until after the new year in a few weeks because we have to move the computer to fit everyone in for christmas.

The header is defined in the CSS though so I'm thinking it may not be possible to do it.

+rep to any help!

Beau
16-11-2007, 07:59 PM
It can be done, you'll just have to set up a class in your CSS exactly like a normal header, except with the new image.

Then, where the class is defined in your document, add code like this...



if(date('d M Y') == '25 Dec 2007') {

echo '<div class="christmas_header"></div>';

}

else {

echo '<div class="normal_header"></div>';

}


Replacing the '25 Dec 2007' with whatever date you want to use, and changing the echos to reflect what your class names are in the CSS.

Jamesy
16-11-2007, 08:28 PM
It doesn't change.


<div id="header">
<h1>i<span>Rant</span></h1>
<?PHP if(date('d M Y') == '16 Nov 2007') {

echo '<div class="header2008"></div>';

}

else {

echo '<div class="header"></div>';

}
?>

</div>

Beau
16-11-2007, 08:36 PM
Where is your server located? It might be the 17th according to where it is. Try changing the date to the 17th and see what happens.

kk.
16-11-2007, 08:38 PM
if it is the date then jsut try like one random day int he past such as 5 oct 2006 then one in the future and see if it changes

gtavc1210
16-11-2007, 08:40 PM
<?
$timer_date = date("d,M,Y");
if($timer_date == "16,Nov,2007")
{

echo '<div class="header2008"></div>';

}
else
{

echo '<div class="header"></div>';

}
?>


hopefully that will work for you although i havet tested it :)

EDIT IT WORKS

Jamesy
16-11-2007, 08:41 PM
Where is your server located? It might be the 17th according to where it is. Try changing the date to the 17th and see what happens.

I did an IP search and it's in the netherlands.
195.242.99.204

So 17th does nothing...

Post above did not work either :( +rep anyway

Beau
16-11-2007, 08:43 PM
Try forcing your server to use GMT.



putenv ('TZ=Europe/London');
Add that in <?PHP tags to the very top of your page. See whether that does anything.

gtavc1210
16-11-2007, 08:44 PM
<?
$timer_date = date("d,M,Y");
if($timer_date == "16,Dec,2007")
{

echo 'xD';

}
else
{

echo ':P';

}
?>

this works fine for me :)

http://www.parkerweblogic.co.uk/testdate.php = Dec 07
http://www.parkerweblogic.co.uk/testdate1.php = Nov 07


Putting <?PHP is pointless! just put <?

Jamesy
16-11-2007, 08:47 PM
Neither worked :(

Sorry for the trouble...

Beau
16-11-2007, 08:49 PM
<?
$timer_date = date("d,M,Y");
if($timer_date == "16,Dec,2007")
{

echo 'xD';

}
else
{

echo ':P';

}
?>

this works fine for me :)

http://www.parkerweblogic.co.uk/testdate.php = Dec 07
http://www.parkerweblogic.co.uk/testdate1.php = Nov 07


Putting <?PHP is pointless! just put <?

<? is not preferred syntax, and is being considered by the PHP group to be removed from the software, along with other variants (<script type="php">, <% etc). Use <?PHP, it's frowned on otherwise.

If forcing GMT doesn't work, check what your server is outputting for date().



<?PHP

echo date('d M Y');

?>


Upload that, and see what it outputs.

Jamesy
16-11-2007, 08:50 PM
16 Nov 2007

Dammit.

Beau
16-11-2007, 08:53 PM
That's good, at least your PHP config is set up correctly.

Don't include this into the file, upload it to your server seperately.



<?PHP

if(date('d M Y') == '16 Nov 2007') {

echo '<div class="header2008"></div>';

}

else {

echo '<div class="header"></div>';

}
?>


If that works, then it's probably just a caching issue. Clear your cache, restart browser, try again.

Jamesy
16-11-2007, 08:59 PM
Nothing appears when I do that. Only the background. Don't worry about it, I'll just do it manually before I have to go :)

Beau
16-11-2007, 09:01 PM
Did you try uploading the code above to a seperate file? I'm sure it's just a caching issue, everything else seems to be working correctly :P

Jamesy
16-11-2007, 09:02 PM
I did,

http://jamesy155.8888mb.com/test.php

You can check the source if I'm doing it wrong.

Beau
16-11-2007, 09:05 PM
Rofl...



<div id="header">
<h1>i<span>Rant</span></h1>
<?PHP if(date('d M Y') == '16 Nov 2007') {

echo '<div id="header2008"></div>';

}

else {

echo '<div id="header"></div>';

}
?>

</div>
Changed the <div class to <div id in both circumstances. Try that :P

EDIT: Also, you're declaring your normal header at the top, before the iRant text. Might wanna fix that :P

EDIT2: ALSO, you've put the PHP in the <head> of the document.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

<title>Untitled Document</title>

</head>
<div class="header2008"></div>

<body>
</body>
</html>


Move it to body :P

Jamesy
16-11-2007, 09:10 PM
div id= works, But the headers are now stacked on top of each other =/

At least we are getting somewhere :D

Beau
16-11-2007, 09:10 PM
Read my first edit ^

Jamesy
16-11-2007, 09:14 PM
Ok, fixed that But now the
<h1>i<span>Rant</span></h1>
Won't appear right without the first <div id="header">

Any way I can put this into the php?

Beau
16-11-2007, 09:17 PM
Can you upload your current PHP document so I can see what's going on in the HTML source? ;)

Jamesy
16-11-2007, 09:19 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Bright Blue by christopher robinson
http://www.edg3.co.uk/
hope you enjoy it and find it usefull :)

-->
<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<title>iRant | Home</title>
<link rel="shortcut icon" href="image/favicon.ico" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="en-gb" />
<meta http-equiv="imagetoolbar" content="false" />
<meta name="author" content="Christopher Robinson" />
<meta name="copyright" content="Copyright (c) Christopher Robinson 2005 - 2007" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="last-modified" content="Sat, 01 Jan 2007 00:00:00 GMT" />
<meta name="mssmarttagspreventparsing" content="true" />
<meta name="robots" content="index, follow, noarchive" />
<meta name="revisit-after" content="7 days" />
<style type="text/css">
<!--
body {
overflow-x: hidden;
}
-->
</style>
</head>

<body>


<?PHP if(date('d M Y') == '27 Dec 2007') {

echo '<div id="header2008"></div>';

}

else {

echo '<div id="header"></div>';

}
?>
<h1>i<span>Rant</span></h1>




<div id="sidebar">

<div align="right">
<ul>
<li><a href="http://jamesy155.8888mb.com/index.html" > Home</a> <a href="http://jamesy155.8888mb.com/rants/index.php">Rants</a> <a href="http://jamesy155.8888mb.com/archives">Archives</a> <a href="http://jamesy155.8888mb.com/forum/index.php">Forums</a> <a href="mailto:[email protected]">Contact Me</a></li>
<li>
</ul>

</li>
</ul>
</div>
</div>
<div id="content">
<div id="main">
<h1>News <?PHP

echo date('d M Y');

?> </h1>
<h2>Get the latest info here!</h2>
<iframe frameborder="1" id="iframe" src="news.php" height="400" width="600" scrolling="yes" allowtransparency="yes"> </iframe>
<br />

<h1>Welcome!</h1>
<p>Welcome to the official iRant website, the new rant column in <i>Waffle</i>, the new Sprowston Highschool Magazine!</p> <p>You may not agree with me on my many rantings about whatever the hell has ****** me off in the month between magazines being released. Stop off here to see past rants in the archives and new rants. Think if this as a blog, except this isn't some stupid thing where I tell you about how good my day was and things like that, I tell you stuff that I have found to be pretty bloody annoying!</p>
<h1>I'm Offended!</h1>
<p><b>Well...Then what the hell are you doing on a site like this?</b></p>
<p>That's right, you heard, well read, but that's besides the point. I don't want to have to waste my time pushing my delete key getting rid of a bunch of <i>"waa waa I read your article and it offended me because I'm [insert Lame excuse here]"</i> Because as I said, they will get deleted. My rants are uncensored and rely totally on my in-built filter. Luckly I'm not going to start shouting the N word everywhere because that <i>is</i> way beyond anything I would even think of. </p>
<h1>What about us?</h1>
<p>Oh fine, so you want to disagree with me in person? Well if you don't know me at school fat chance, I don't arrange meetings with strangers. However, you may post comments under my rants or go make a thread <a href="http://jamesy155.8888mb.com/forum/index.php" target="_self">HERE</a>. Registration is not even compulsory in the Agree and Disagree forums, but you will for any others. Not that it makes much difference to me as I am a tight *** using free-hosting for this.</p>
<p>Infact I'm using a free template as well, which I have simply edited to my own desires because I can't actually code/make an attractive layout myself. But that's enough waffle for now So I shall bid your welcome over, now you may continue browsing my site or the world wide web in general.</p>
<p>- Jamesy</p>
</div>

</div>
<div id="footer">
<p><span class="navigation"><a href="http://en.www.mozilla.com/products/download.html?product=firefox-2.0.0.9&os=win&lang=en-US" target="_blank"><img src="image/foxkeh-fx2-180x60.png" longdesc="image/foxkeh-fx2-180x60.png" alt="" /></a>
<br />
</span>Copyright &copy; <a href="#">iRant</a> 2007 | Designed by <a href="http://www.edg3.co.uk/">edg3.co.uk</a></p>
<p><br />
</p>
</div>
</body>

</html>


The CSS says that the header <h1> is one colour and that the <span> is another colour.

Beau
16-11-2007, 09:27 PM
This is your current code for the span in CSS:



#header h1 span {
color:#01a5ec;
}

Trouble is, it isn't being declared inside header.

I'd reccomend making an extra class, like this:



#title {
color:#01a5ec;
}


And then, when you want the title to appear:



<h1>i<span id="title">Rant</span></h1>

Jamesy
16-11-2007, 09:27 PM
So I put that where it is now right?

Beau
16-11-2007, 09:29 PM
Add the #title code to your CSS, and replace the old span code with the new one, yes :)

Jamesy
16-11-2007, 09:33 PM
http://jamesy155.8888mb.com/index.php

Still stuck to the side :(

Beau
16-11-2007, 09:37 PM
Change the #title code to this:



#title {
color:#01a5ec;
margin-left: 275px;
}


Change the margin until you're happy with where it is.

Jamesy
16-11-2007, 09:44 PM
I've thought of a simpler way. Why not just put the title on the image, as in part of the image. Would make all this extra code irrelevant.

Beau
16-11-2007, 09:45 PM
Good idea! Margins are messy, so if you can do it without them, go for it (y)

Jamesy
16-11-2007, 09:48 PM
Well I really have to thank you for all of this, I would rep again but I need to spread so remind me any time :)

Thread closed!

<3

Want to hide these adverts? Register an account for free!