7 replies [Last post]
Francesco
Offline
Regular
Last seen: 16 years 37 weeks ago
Timezone: GMT+7
Joined: 2004-03-23
Posts: 19
Points: 0

Hey There,

I'm trying to get todays date to show up in a fixed position on my site using PHP but I can't seem to get it working quite right.

I have the following CSS to keep the text in where I want it to be which I think is ok:

div.date {
	position : absolute;
	top: 85px;
	left : 0;
}

Then I have the following PHP code for the date which is in a file by itslef called date.php:

<?php
$date_array = getdate(); // no argument passed so today's date will be used
foreach ( $date_array as $key => $val )
?>
<?
print "Today's date: ";
print $date_array['mday']."/".$date_array['mon']."/".$date_array['year'];
?>

And then I have the following in my htm file to call up the PHP file:

<div class="date"><src=date.php></DIV> However, it just won't seem to work can anyone help me out please...?

Francesco

MalphasWats
Offline
Regular
Last seen: 14 years 5 weeks ago
Joined: 2004-03-22
Posts: 45
Points: 0

Fixed Date Position

In what way doesn't work? What does it do?

http//www.michael-watts.com

"Never put your face in a bag of angry squirrels"

Francesco
Offline
Regular
Last seen: 16 years 37 weeks ago
Timezone: GMT+7
Joined: 2004-03-23
Posts: 19
Points: 0

Fixed Date Position

It's suppsed to show todays date in this format, D/M/Year but it doesn't seem to be doing anything.

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 2 years 4 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

Fixed Date Position

Hi Francesco

I thought you had to have your html file as a php file (ie ending in php).

My files have this in for the date:

<div class="datetoday"><?php print(Date("D, j F Y"));?></div>

No need for arrays or fancy work, this particular date format gives something like

Monday, 14 June 2004

But you can change the parameters to display it how you like.

Trevor

co2
co2's picture
Offline
Leader
UK
Last seen: 12 years 33 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

Fixed Date Position

Yep, I second that... here's my date code Wink

<?php print date("H:ia D, d F Y."); ?>

The next sentence is true. The previous sentence is false. Discuss...

Francesco
Offline
Regular
Last seen: 16 years 37 weeks ago
Timezone: GMT+7
Joined: 2004-03-23
Posts: 19
Points: 0

Fixed Date Position

That would all probably work if I wanted to change my html files to php files but I don't want to do that. In a random background topic that I started a week ago Trevor helped me find a way to call on a PHP file from the html file and that's what I'd like to do with this date script PHP as well. Unfortunately it's not called upon quite the same way because we're not dealing with images anymore we're dealing with text. I just think I messed up calling it from within the html file...

Anybody have any ideas?

Thanks,

Francesco

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 2 years 4 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

Fixed Date Position

Hi Francesco

What co2 and I are saying is that you can't do it the way you want. You must call php from within a php file.

However, if you have admin control over the apache installation on your server, all is not lost (you might even persuade your host admin to help you anyway).

In the apache httpd.conf file is a line like this:

AddType application/x-httpd-php .php .php3 .php4 .phtml

This determines which files php will parse.

You can add .html .htm to the end and then they will be treated as php files.

There is also a way to do this in your .htaccess file, but this requires access to the httpd.conf file again to allow .htaccess to do this.

There is no other way of doing this. The gd library is a special library that can be called as a source file. Normal php cannot be called this way.

Trevor

Francesco
Offline
Regular
Last seen: 16 years 37 weeks ago
Timezone: GMT+7
Joined: 2004-03-23
Posts: 19
Points: 0

Fixed Date Position

Alright cool thanks for clearing that up Trevor.

And thanks to you other guy's for the code it worked great.

If you guys wanna check out the web site I've been working on click on the link below.

frantech69.com

Trevor you'll also notice that I'm playing around with an idea for a forum. Check it out if you want, not even sure if it's working properly at this point.

Thanks again,

Francesco