RE: Re: Link a file that does a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,
Including common routines in this way is ok.  To break things up a bit
more I use PHP classes, which give us the opportunity to retain state,
or have, say, a Utils class which just contains static functions.  Each
class is placed in its own file and then I use a 'standardIncludes.php'
file which contains them all in one place, has them in a particular
order so that interdependencies are supported, and which results in just
a single includes in the referring file: the 'main.php' or wherever the
application starts.
 
However, a more interesting issue in this thread is the example that has
been used as an illustratation: 'getLocalTime', because, of course, this
is local SERVER time.  I have written a number of systems which sell
goods online and have shopping baskets, orders, order management, etc.
These sites are hosted on my US web space.  As anyone who has done this
will probably know, this causes problems because local SERVER time is
between 5 and 8 hours behind GMT and will be incorrect, confusing and
unsatisfactory.  So what's the best way - I don't know:
 
1.  Use javascript to set a hidden field in the HTML form and post it
back to the server.
2.  Use the SERVER time and add or subtract the required number of hours
to derive the local CLIENT time of the transaction.
3.  Use locale settings on the server to obtain the client time.
 
Option 3 would seem to be the best way to go, but I am considerably put
off by the apparent unreliability of this method.
 
Any good ideas out there?
 
Brian
________________________________

From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx]
On Behalf Of brian21160
Sent: 14 January 2008 03:13
To: php-objects@xxxxxxxxxxxxxxx
Subject:  Re: Link a file that does a function



A method that I use that has worked quite well for me is to create a 
file called "functions.php" that includes scripts that get called by 
more that 1 page in my applications. The way you just write the code 
once and if you make a change here it changes site wide.
Then in each page that requires access to one or more of these 
functions I just put an <?php include('functions.php');?> line near 
the top of each page.
eg:
In the "functions.php" page, create a function like:
function getLocalTime()
{
$timestamp=time( );
$seconds = 6*60*60;
$timestamp-= $seconds;
$tz = "CST";

$localtime= date("m/d/Y H:i:s",$timestamp) ;
$localdate = substr($localtime, 0,10);
$localtime = substr($localtime, 11,8); 

return $localtime;
}

Then in one of my web pages, I would do something like:
<?php
include('functions.php');
echo getLocalTime();
?>

--- In php-objects@xxxxxxxxxxxxxxx
<mailto:php-objects%40yahoogroups.com> , JIM NEELY <jimneely@...> wrote:
>
> I setup an "include" file....
> 
> Ken <ken.poyser@...> wrote: I have a file that gets the 
local time (not GMT) 
> 
> $timestamp=time();
> $seconds = 6*60*60;
> $timestamp-=$seconds;
> $tz = "CST";
> 
> $localtime= date("m/d/Y H:i:s",$timestamp);
> $localdate = substr($localtime,0,10);
> $localtime = substr($localtime,11,8); 
> 
> Currently I have the code above in about 13 files
> and wondering how to have this one file
> and then in the 13 files to go to this file to
> do the date/time conversion
> 
> I am wondering how to call this file to do this from
> within these 13 php files
> 
> Any assistance would be appreciated
> 
> Thanks
> Ken
> 
> 
> 
> 
> 
> 
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
> 
> [Non-text portions of this message have been removed]
>



 


[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux