PDA

View Full Version : PHP Tutorial 1: Grab Local Date And Time



T0X!C-uk
25-06-2005, 06:16 PM
Ok over the next week or so i will be adding some php tutorials as i have been asked a few times to help people learn.
As i dont have the time i cannot go around teaching people individually it wouldnt be possible. So i have a wrote a few tutorials that you can all use. If you read though them properly it will give you the basic idea of how php works and hopefully you will be able to learn bigger things in the future.

Hopefully all these will get moved and stickied into the websites tutorials thread :8

Tutorial 1: Grab Local Date And Time.

OK, just run this as filename.php?timezone_local=8 to get the local time
this could be handy if your host changes their local time on the server then you wont have any problems when they do.

If you are going to use this in a cms you will need to set $timezone_local to your timezone instead of the $_GET[] variable.

If your timezone is something like +9:30 you will need to set $timezone_local to 9.5


<?
$timezone_local = $_GET['timezone_local'];
$time = time();
$timezone_offset = date("Z");
$timezone_add = round($timezone_local*60*60);
$time = round($time-$timezone_offset+$timezone_add);
$date = date("l dS of F Y h:i:s A", $time);
echo $date;
?>

Mentor
25-06-2005, 07:55 PM
Is it just me or have you gone in to a tutoiral makeing frenzy since the new tutorials forum came in.

Also none of these are tutorials, there good scripts, but there still justs scripts, no tutorilas "/

T0X!C-uk
25-06-2005, 07:59 PM
LOL ye i just want to get some tutorials on the new forum :p

And they are tutorials just not for beginners. Im currently writing one now that explains the basics of php like opening and closing tags, variables etc etc so then people will understand the others more :)

Rix
26-06-2005, 02:43 AM
does any1 have the ip code of the user and how many people are online

Mentor
26-06-2005, 02:52 AM
Ip is just $_SERVER['REMOTE_ADDR']

so to display it



echo $_SERVER['REMOTE_ADDR'] ;


Athogh users online is a little more complex, so its easyer just to download a script for it form somewhere

Tomm
26-06-2005, 07:53 AM
w00t thx mentor i have been looking around for that code for PHP for ages - i cant give u rep as it says i have to spread a bit more around before i can give it to u again :S

Rix
26-06-2005, 08:08 AM
mine does shows this
<?
echo $_SERVER['REMOTE_ADDR'] ;<br>
$timezone_local = $_GET['timezone_local'];<br>
$time = time();<br>
$timezone_offset = date(&quot;Z&quot;);<br>
$timezone_add = round($timezone_local*60*60);<br>
$time = round($time-$timezone_offset+$timezone_add);<br>
$date = date(&quot;l dS of F Y h:i:s A&quot;, $time);<br>

echo $date;?>

T0X!C-uk
26-06-2005, 12:46 PM
mine does shows this
<?
echo $_SERVER['REMOTE_ADDR'] ;<br>
$timezone_local = $_GET['timezone_local'];<br>
$time = time();<br>
$timezone_offset = date(&quot;Z&quot;);<br>
$timezone_add = round($timezone_local*60*60);<br>
$time = round($time-$timezone_offset+$timezone_add);<br>
$date = date(&quot;l dS of F Y h:i:s A&quot;, $time);<br>

echo $date;?>

Yours? i think you will find thats the code i wrote above......

Also about mentors help you will need to write the code like this


<? echo $_SERVER['REMOTE_ADDR'] ; ?>


If you have not already opened a PHP tag

Rix
26-06-2005, 09:58 PM
but then the page is all blank

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