Need Help with PHP

I was playing around with the php coding that allows a page to bring up the date and time from your web server. I was not able to get it to work. Help???

This is the code used:
<?php
echo date(‘1, F dS Y.’)’
?>

Is this correct?

Also, not sure if php is active on my web server. It has been installed. Just need some help with php.

Thanks

wfjones55

You’re pretty close. Take a look at http://php.net/manual/en/function.date.php when you get a chance and you’ll see the different date parameters you can use. By changing the values within the parentheses you’ll change the way the date is formatted.

<?php
$date = date("m/d/Y");
echo("$date");
?>

This will output 02/10/2010 (assuming that today is really the 10th). If you used a lowercase y instead it would output 02/10/10. You can change these parameter values and experiment how you’d like your date to appear.

You may also need to set your timezone. If you can’t change the server timezone you can always set it with PHP.

date_default_timezone_set('America/Los_Angeles');

Not quite there yet.

You can also use a timestamp to set you time:

echo date(‘D F j, Y’, strtotime(‘now’));

would output Wed February 10, 2010

You can also feed the strtotime function any valid time stamp, like from a database

Jeff,

Not sure but that didn’t work either. Perhaps there is something that I am not doing or doing. PHP 5.3.1 is running on my web server. However, when I run the code on the web server nothing happens within a html file. What am I doing wrong? HELP

Willie

Willie,

What is the PHP code you’re using? Please paste it here. That’ll help us out. :slight_smile:

Jeff,

<?php $date = date(“m/d/Y”); echo(“$date”); ?>

This is the code that you posted for me within your next to last post.

Again, once I ran it on the web site within an html doc nothing happened.

Willie

Willie,

Something’s up with your server or the page itself. I’ve pasted this code into a blank PHP file and it works just fine.

http://www.waldenwebsites.com/date.php

Have you named your file .php?
If you place phpinfo(); in your PHP file what do you see?
Does the file have the appropriate permissions set? (Needs view access)

If you’re trying this in a page with existing code then instead try creating a blank PHP file and pasting the code in there. This will remove any chance that the other code is horking things up.

Jeff,

I have placed the code into a blank file named time.php and ran it on the server an nothing.

I would have have the code displayed on the page.

Just do not know what’s taking place.

Not sure what you mean about permissions set??
All files have the same permissions on the server.

The server is a Window 2003, if that helps.

Willie

Forget about the permissions if you’re running Windows. The file system has permissions but you’re most likely okay. I was assuming you were running Linux. I should never ever assume… :rolleyes:

So when you pull up the time.php file in your browser it’s completely blank? Try pasting this into your PHP file and let me know if you see a big long screen telling you all about your PHP installation:

<?php
phpinfo();
?>

Jeff,

Nothing shows in the browser… Completely blank, running Firefox.

Bugger. That means you’ve got larger problems. Essentially your code isn’t being passed through the PHP engine (probably wrong terminology) before being sent to the browser so you’re not seeing any cool PHP functions.

I assumed once and was wrong so I’m going to go try and ask everything. :slight_smile: Are you administrating this server yourself? If not, it sounds like you need to go back to the server administrator and find out why PHP isn’t running for your server.

If this is a local server that you’re just trying to get setup then it’s time to go back to your PHP installation and configuration. Something went wrong there and needs to be fixed.

Jeff,

The servers are all mine, I am the administrator with full security and permissions. Server has been operating and active for 5 years.

I decide to attempt to add some enhancements with php and here we are. Php is not new to me and I to it, I would say that something with the configuration is the issue.

It will not run no php cool things. Either the version or configuration, so back to the drawing board.

Oye. Well, Willie, at least it sounds like you know your way around your servers. Could be worse. :slight_smile:

Gotta be something with the configuration. If all else fails, check to make sure that the services are started. I know all the “experts” get cranky when I suggest that they make sure the computer is plugged in before trying to turn it on but I’m always surprised at how often that fixes the problem.

Jeff,

You know you really have a point there. How can I confirm that the services are running with php?

On a command line I can run php.exe and log into it. After that be my guest.

Which version of php would you recommend?

Thanks

Willie

Willie,

I’m not a Windows guy and I’m definitely not a server administrator of any kind, so take what I say with a grain of salt.

http://www.visualwin.com/PHP/

That article seems to be pretty comprehensive in terms of installing PHP on Windows 2003. It appears that there’s actually no service for PHP. Oops. I’m trying to remember years ago when I was running a local installation and I must have been thinking about the Apache service. Sorry.

http://www.peterguy.com/php/install_IIS6.html
http://php.net/manual/en/install.windows.php

Both of those sites are pretty good as well if you’re still having trouble. If you had it working before, I would go back and ask what you changed? If it worked before and doesn’t work now it would stand to reason that whatever you changed broke it.

Sorry, wish I could be more help in this department but servers aren’t my thing. I just write code. :slight_smile:

This might be a good post in the Server Management forum. The folks over there are pretty smart and they can probably help you a lot more than I can.

Jeff,

You have been very helpful. Thanks for everything.

Willie

Willie,

My pleasure. Good luck with the other half of this battle. :slight_smile:

Jeff

We have smart folks here too.
how do you “run” this file? by clicking it in explorer window or by querying it in the browser?
What do you see in the browser’s address bar? there must be something like http://localhost/yourfile.php
Do you have web server installed?
is there PHP installed?

Hey Jeff.
About code you write.
There was nothing wrong with Willie’s very first code and you made it bad.

echo(“$date”);

Brackets are unnecessary here and quotes are just wrong.
When you address a variable, never use quotes. Or you’ll have an error someday.
That’s simple:

echo $var not echo "$var";
some_function($var) not some_function("$var");

Shrapnel_N5,

Thanks for looking in. I am attempting to run php on my present Web server which is a Window 2003 server that is a .net and web files are .aspx. I have installed php 5.3.1 and MySQL in an attempt to setup a php/mysql database. At this point just trying to get php to talk to mysql is an issue. I just not one for open source appls. If you could help it would deeply appreciated.

Willie