php-general Digest 21 Aug 2009 11:26:19 -0000 Issue 6297

Topics (messages 297042 through 297053):

Re: Displaying 2 digit minutes/seconds
        297042 by: Ashley Sheridan
        297043 by: sono-io.fannullone.us
        297044 by: sono-io.fannullone.us
        297046 by: Daevid Vincent

Submit login form using HTTP AUTH
        297045 by: LinuxManMikeC

Tidy on a shared host
        297047 by: Al

Re: PHP/Ajax Framework - Call for Developers & Testers
        297048 by: Raymond Irving

Is there limitation for switch case: argument's value?
        297049 by: Keith
        297050 by: Adam Randall
        297051 by: Lars Torben Wilson

Re: SESSION VARIABLES ACROSS DIFFERENT WINDOWS/TABS
        297052 by: Leon du Plessis

Invoking functions stored in a separate directory?
        297053 by: Clancy

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Thu, 2009-08-20 at 14:27 -0700, [email protected] wrote:
> Hi all,
> 
>       I'm using this code to display the current time for our location on  
> our website:
> 
> <?php
>       date_default_timezone_set('America/Los_Angeles');
>          $theTimeIs = getdate(time());
>              $theHour = $theTimeIs['hours'];
>              $theMinute = $theTimeIs['minutes'];  // make minutes  
> under 10 show two digits
>              $theSecond = $theTimeIs['seconds'];
>          if($theHour > 12){
>              $theHour = $theHour - 12;
>              $dn = "PM";
>          } else {
>              $dn = "AM";
>          }
> 
> echo "$theHour:$theMinute:$theSecond $dn";
> ?>
> 
>       It works great except for one small detail.  If the time is 3:04:02,  
> it is displayed as 3:4:2 which, of course, is very odd looking.  So I  
> corrected it as follows:
> 
> <?php
>       date_default_timezone_set('America/Los_Angeles');
>          $theTimeIs = getdate(time());
>              $theHour = $theTimeIs['hours'];
>              if (strlen ($theTimeIs['minutes']) < 2) {
>                               $theMinute = "0" . $theTimeIs['minutes'];
>                               } else {
>                               $theMinute = $theTimeIs['minutes'];
>                               }
>              if (strlen ($theTimeIs['seconds']) < 2) {
>                               $theSecond = "0" . $theTimeIs['seconds'];
>                               } else {
>                               $theSecond = $theTimeIs['seconds'];
>                               }
>          if($theHour > 12){
>              $theHour = $theHour - 12;
>              $dn = "PM";
>          } else {
>              $dn = "AM";
>          }
> 
> echo "$theHour:$theMinute:$theSecond $dn";
> ?>
> 
>       It works, but is there a better way to do it?
> 
> Thanks,
> Frank
> 

What's wrong with using the date() function? You can have it output any
sort of format you wish. So, getting a 2 digit time in
hours:minutes:seconds you would put:

date("H:i:s");

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---

On Aug 20, 2009, at 2:38 PM, Ashley Sheridan wrote:

What's wrong with using the date() function? You can have it output any
sort of format you wish. So, getting a 2 digit time in
hours:minutes:seconds you would put:

date("H:i:s");

Thanks, Ash. I had tried that before but I couldn't find a way to make it display in 12 hour time, so I went with the other method. I guess I didn't look hard enough. =;)

This works:

echo (date("g:i A"));

Frank

--- End Message ---
--- Begin Message ---

On Aug 20, 2009, at 2:34 PM, Jonathan Tapicer wrote:

You can use sprintf or str_pad to fill in with zeros, with sprintf you can do this:

echo sprintf('%02d', 5);

Thanks, Jonathan! I learned two new functions today! Both work great but I think I like sprintf for this application better since it's more succinct.

echo sprintf('%02d', $theMinute);

echo (str_pad($theMinute,2,"0",STR_PAD_LEFT));

Frank

--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: [email protected] [mailto:[email protected]] 
> Sent: Thursday, August 20, 2009 3:53 PM
> To: Jonathan Tapicer; PHP General List
> Subject: Re: [PHP] Displaying 2 digit minutes/seconds
> 
> 
> On Aug 20, 2009, at 2:34 PM, Jonathan Tapicer wrote:
> 
> > You can use sprintf or str_pad to fill in with zeros, with sprintf  
> > you can do this:
> >
> > echo sprintf('%02d', 5);
> 
>       Thanks, Jonathan!  I learned two new functions today!  
> Both work  
> great but I think I like sprintf for this application better since  
> it's more succinct.
> 
> echo sprintf('%02d', $theMinute);

Uh. If you MUST do this nonsense, then at least do this instead and not
"echo sprintf":

printf('%02d', $theMinute);


--- End Message ---
--- Begin Message ---
Anybody know of any tricks to make an HTML login form that sends the
credentials via HTTP AUTH?

--- End Message ---
--- Begin Message --- I've written an application that depends heavily on Tidy for cleaning up user inputed text.

Unfortunately, some shared hosts won't install the extension for my clients.

Is there a way I can install a stand alone version using FTP with access only in a directory where my program resides. The hosts have given me restricted FTP to the dir.

Or, does anyone know of a stand-alone php class that emulates the tidy extension. I've looked; but, not found any.

Al..........



--- End Message ---
--- Begin Message ---
Hi Nathan,

I agree with you, and I believe that there are many persons who don't like the 
idea of hosting all their applications on a third party server. IMO there are 
some advantages and disadvantages to doing so but that's a discussion in itself.

The good thing about Raxan's Embeddable Apps is that you have control over the 
source code.  With the ShoutBox example you can download the framwork along 
with the application and copy it to your own servers. No need to host the apps 
on third party servers.

Some benefits of Raxan Embeddable Apps:
----------------------------------------------------------------
1. Works in just about any web page 
2. Easy to deploy and configure
3. Reusable and Shareable

I believe that one day we will see apps like Photo Galleries, Media players, 
File Managers, Catalogs, etc that users can easily download and add to the 
their web pages.

PS. I would like to invite everyone to download the framework, try the examples 
and take a look at the source code. You will be amaze at what you can do with 
Raxan PDI. - You can download it here: 
http://code.google.com/p/raxan/downloads/detail?name=raxan-pdi.1.0.0b2.zip&can=2&q=


Best regards
__
Raymond Irving



--- On Thu, 8/20/09, Nathan Nobbe <[email protected]> wrote:

From: Nathan Nobbe <[email protected]>
Subject: Re: [PHP] PHP/Ajax Framework - Call for Developers & Testers
To: "Raymond Irving" <[email protected]>
Cc: [email protected]
Date: Thursday, August 20, 2009, 1:31 PM

ive seen lots of third parties selling components in this manor.  now that ajax 
has hit the scene there are some really weird things going on.

i was just on a call yesterday where this company told us about their service, 
which is delivered as one of these 'embedded' applications.  this thing would 
have its own navigation and display of content on our site in order to keep 
folks clicking.

if you ask me, that just feels weird; having some other company like own a 
piece of your app...  however, it would be foolish not to admit that this is 
the way things are trending and that there will only be more of it to come.

-nathan

--- End Message ---
--- Begin Message ---
Hi,
I encounter a funny limitation here with switch case as below:
The value for $sum is worked as expected for 1 to 8, but not for 0.
When the $sum=0, the first case will be return, which is "sum=8".
Is there any limitation / rules for switch case? Thanks for advice!

Keith

$sum=0; 
switch($sum)
{
   case ($sum==8):
   echo "sum=8";
   break;
       case ($sum==7 || $sum==6):
       echo "sum=7 or 6";
       break;
   case ($sum==2 || $sum==1):
   echo "sum=2 or 1";
   break;
       case 0:
       echo "sum=0";
       break;
   default:
   echo "sum=3/4/5";
   break;                                       
}
--- End Message ---
--- Begin Message ---
I've never understood why people use switch statements like this as in
reality you are using it more like an if/else block, but anyway.

The reason why your code is not working is that you are passing into
the switch the value of 0, or false, which means that when any of
those $sum == N conditionals comes up as false (say $sum == 8 ), then
that is what is returned because they match up. In PHP's eyes, 0 ==
false in switch statements.

To fix your code, change the switch( $sum ) to switch( true ):

switch( true )
{
        case ($sum == 8):
                echo "sum=8\n";
                break;
        case ($sum == 7 || $sum == 6):
                echo "sum=7 or 6\n";
                break;
        case ($sum == 2 || $sum == 1):
                echo "sum=2 or 1\n";
                break;
        case ($sum == 0):
                echo "sum=0\n";
                break;
        default:
                echo "sum=3/4/5\n";
                break;
}

Or, write your switch like this:

switch( $sum )
{
        case 8:
                echo "sum=8\n";
                break;
        case 6:
        case 7:
                echo "sum=7 or 6\n";
                break;
        case 1:
        case 2:
                echo "sum=2 or 1\n";
                break;
        case 0:
                echo "sum=0\n";
                break;
        default:
                echo "sum=3/4/5\n";
                break;
}

Regards,

Adam.

On Thu, Aug 20, 2009 at 8:40 PM, Keith<[email protected]> wrote:
> Hi,
> I encounter a funny limitation here with switch case as below:
> The value for $sum is worked as expected for 1 to 8, but not for 0.
> When the $sum=0, the first case will be return, which is "sum=8".
> Is there any limitation / rules for switch case? Thanks for advice!
>
> Keith
>
> $sum=0;
> switch($sum)
> {
>   case ($sum==8):
>   echo "sum=8";
>   break;
>       case ($sum==7 || $sum==6):
>       echo "sum=7 or 6";
>       break;
>   case ($sum==2 || $sum==1):
>   echo "sum=2 or 1";
>   break;
>       case 0:
>       echo "sum=0";
>       break;
>   default:
>   echo "sum=3/4/5";
>   break;
> }
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Adam Randall
http://www.xaren.net
AIM: blitz574

--- End Message ---
--- Begin Message ---
2009/8/20 Keith <[email protected]>:
> Hi,
> I encounter a funny limitation here with switch case as below:
> The value for $sum is worked as expected for 1 to 8, but not for 0.
> When the $sum=0, the first case will be return, which is "sum=8".
> Is there any limitation / rules for switch case? Thanks for advice!
>
> Keith

Hi Keith,

Try replacing 'switch($sum)' with 'switch(true)'.

Note that unless you have very good reasons for using a switch
statement like this, and know exactly why you're doing it, it's often
better just to use it in the normal fashion. i.e.:

       switch ($sum)
        {
        case 8:
            break;
        case 7:
        case 6:
            break;
        case 2:
        case 1:
            break;
        case 0:
            break;
        default:
            break;
        }

Some people like the syntax you've presented but honestly, there's
usually a better way to do it.

This is also somewhat faster too, although you may only notice the
difference in very tight loops where you're counting every nanosecond.


Regards,

Torben

> $sum=0;
> switch($sum)
> {
>   case ($sum==8):
>   echo "sum=8";
>   break;
>       case ($sum==7 || $sum==6):
>       echo "sum=7 or 6";
>       break;
>   case ($sum==2 || $sum==1):
>   echo "sum=2 or 1";
>   break;
>       case 0:
>       echo "sum=0";
>       break;
>   default:
>   echo "sum=3/4/5";
>   break;
> }
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hi Jamie. 

Thanks. Good info. I knew something changed somewhere. This works like a
charm in IE8..never saw the New Session option under file...me bad !!

Greetings.


-----Original Message-----
From: Jaime Bozza [mailto:[email protected]] 
Sent: 20 August 2009 09:49 PM
To: Leon du Plessis; 'Floyd Resler'
Cc: [email protected]; [email protected]
Subject: RE: [PHP] SESSION VARIABLES ACROSS DIFFERENT WINDOWS/TABS

Leon,

This is really just a function of the browser.   When a session cookie is
created, if the browser is setup for a single instance, that's the session
cookie it'll use for *any* request to that domain.  This functions
differently depending on what browser you're using.

For example:
Firefox - All windows, tabs, etc, under the same profile will use the same
session.   If you create profiles, you can have different sessions.
IE7, IE6 - All tabs or windows opened from clicks will share the same
instance/session.  Starting IE from the icon will open up a "new"
instance/session.  This worked great if you wanted to run two different
sessions at the same site/domain.  Just start IE up from the icon again and
you'd have a new session.
IE8 - IE8 model changed, so that all browser windows, tabs, etc., run under
the same frame/session, much like Firefox.  Clicking the IE icon again now
just keeps the same frame and thus the same session.  Originally, this
sounded like a big problem, but IE8 introduced a new feature - File Menu ->
New Session.   This will open up a new window that will be a separate frame
that will not use current session cookies.

Here's just one of many links, but gives some helpful hints on the IE side:
http://blogs.msdn.com/ie/archive/2009/05/06/session-cookies-sessionstorage-a
nd-ie8.aspx

And another:
http://blogs.msdn.com/askie/archive/2009/05/08/session-management-within-int
ernet-explorer-8-0.aspx

One of the issues now is that if you close IE, your session does not
disappear.  In the past (IE7/IE6), your session would disappear if you
closed a browser window that you opened yourself, but it *wouldn't*
disappear if you closed a browser window that was opened by a click from
Outlook or another program.  This was a bit inconsistent.  I won't argue
whether or not their "fix" was the best way to go, but now it's at least
consistent.

Note - In Firefox, not even "Private Browsing" separates the session
cookies.  If you start Private Browsing (Firefox 3.5), log into a site, then
start a new browser window from the icon (that isn't in Private Browsing
mode), it shares the session cookies. (Before you ask, I just checked this
to be sure.)

IE8 "InPrivate Mode" is a totally separate session, cookies and all.  This
could possibly be another way for you to run multiple sessions against the
same domain.  OTOH, multiple InPrivate sessions running at the same time
share the same frame, so they share the same session, so it would only be
good for a single new session.  If you need more, just use File - New
Session.

Jaime 


> -----Original Message-----
> From: Leon du Plessis [mailto:[email protected]]
> Sent: Thursday, August 20, 2009 8:16 AM
> To: 'Floyd Resler'
> Cc: [email protected]; [email protected]
> Subject: [PHP] SESSION VARIABLES ACROSS DIFFERENT WINDOWS/TABS
> 
> It is just strange that I have this "condition" now...maybe I missed it
> a
> year ago ?
> 
> >> "Having a different session start up for each window for tab would
> be a
> major pain."
> 
> Why?
> 
> People must please try and understand what I mean by NEW. It does not
> apply
> to windows/tabs being opened from a link or request.
> 
> Imho, keeping the session per domain "sounds" wrong, it does not mean
> it is.
> It would have been nice if:
> 
> Browser/tab one -> my login detail container A.
> Browser/tab two -> my admin login container B.
> (tabs/windows opened from browser one, then inherits container A
> naturally)
> (Closing browser one, then destroys container A then naturally only)
> 
> NOT
> 
> Domain.com -> one session container only.
> 
> Heck, I am surprised it works that way at all cause it "sounds" like
> the
> domain can then only handle one user a time if arrays are not used or
> profiles not created on FF no matter where the request come from, but,
> then
> I am obviously missing something in this respect as stated. When I have
> time
> I will reconstruct this concept again.
> 
> Thanks anyway guys. I received some helpful advise for future
> reference.
> 
> But please..I do not, like many others, want to start a war. I am ok
> with
> things how they are. We can put this thing to rest.
> 
> -----Original Message-----
> From: Floyd Resler [mailto:[email protected]]
> Sent: 20 August 2009 02:25 PM
> To: Leon du Plessis
> Cc: [email protected]; [email protected]
> Subject: Re: [PHP] SESSIONS lost sometimes
> 
> Leon,
>       Sessions are used on a per-domain basis.  So, no matter how many
> windows or tabs you have open for mydomain.com it will be the same
> session for all.  Having a different session start up for each window
> or tab would be a major pain.  If you needed to keep track of a user
> ID, for example, you wouldn't be able to.  As already mentioned you
> can use different browsers.  You can also set up sub-domains which
> would each have their own sessions.
> 
> Take care,
> Floyd
> 
> On Aug 20, 2009, at 4:26 AM, Leon du Plessis wrote:
> 
> > ">> It's not an issue, it's a feature."
> >
> > Thanks Arno...but it is a pain also.
> > If I work with user A in Tab1 (window1), I want to work with user B
> > separately in Tab2. When user in Tab2 logs off, I still want user A
> > to work,
> > and not suddenly have to re-login. Same with bank. If I work with my
> > company
> > account, then my personal account must not become an issue because I
> > am on
> > the same machine and site.
> >
> > I have no issue with using FF and IE to do testing as that takes
> > care of
> > browser compatibility testing at the same time :-), but I think when
> > you
> > start a new session with new values, it should be kept under that
> > window/tab
> > alone. Cookies can take care of more details, but my opinion is data
> > should
> > never be affected across windows/tabs unless the same user is logged
> > in on
> > both....even then I would expect PHP to keep data per session. Maybe
> > it goes
> > beyond being an IE or FF issue..the questiojn is...will PHP allow
> > variables
> > from session A become corrupted when session B is in progress when
> > they
> > should actually be handled seperately?
> >
> > In the end I think it is something I do wrong in PHP with the SESSION
> > variables and how I clear them....if so...I don't think PHP should
> > allow
> > clearing SESSION variables from other sessions.
> >
> > -----Original Message-----
> > From: Arno Kuhl [mailto:[email protected]]
> > Sent: 20 August 2009 10:03 AM
> > To: 'Leon du Plessis'; [email protected]
> > Subject: RE: [PHP] SESSIONS lost sometimes
> >
> > -----Original Message-----
> > From: Leon du Plessis [mailto:[email protected]]
> > Sent: 20 August 2009 09:44 AM
> > To: [email protected]
> > Subject: RE: [PHP] SESSIONS lost sometimes
> >
> > Since we are on the subject: I have the following similar problem:
> >
> > When testing page on internet explorer, I find that one tab's
> > variables can
> > affect another tab's variables. Thus when having the same web-site
> > open and
> > using SESSION variables but for different users, Internet explorer
> can
> > become "disorientated". This also "sometimes" happen when I have two
> > separate browsing windows open with Internet Explorer for the same
> > site.
> >
> > I have yet to determine if this is an internet explorer, or PHP or
> > combination of the two that is causing this condition.
> >
> > To my understanding _SESSION variables should be maintained per
> > session, tab
> > or window. If this has been addressed already, my apologies, but
> > thought it
> > worthwhile to mention.
> >
> > If someone perhaps have a solution or can confirm this as a known
> > issue and
> > maybe is the same or related to Angelo's problem?
> >
> > --------------------
> >
> > If different browser windows/tabs on the same client-side computer
> > didn't
> > share session info then you'd get the effect of being able to log
> > onto a
> > site with one browser window, but find in a second browser window
> > that you
> > were not yet logged on. Experience will tell you that you're logged
> > on in
> > both browser windows (try it with your online bank). It's not an
> > issue, it's
> > a feature. If you want to be able to use different browser windows
> > as though
> > they were different users then use different browsers e.g. IE and FF
> > on the
> > same client-side computer will look like two separate end users to
> the
> > server, and they don't share session info or cookies.
> >
> > Cheers
> > Arno
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
I am developing an idea for a website engine which can be shared between 
several different
websites. Each website would have its own directory under a common root 
directory, and the
engine would be in a separate directory Engine:

Root
Website_1.com, Website_2.com, Engine

The website directories would each contain the design data for that website, 
consisting
basically of a mixture of text files and images. The various pages would be 
loaded by
loading index.php from the website root directory, and specifying a number of 
parameters
e.g.

http://www.corybas.com/index.php?path=Holidays&level=0&item=0

I have the minimum amount of code in index.php -- just enough to set some 
parameters to
identify the website, and then include ../Engine/Main_prog.php.  This in turn 
can include
any of a large number of other include files to carry out particular functions. 

I have the prototype working nicely on my PC, and on a stand-alone basis on a 
server, but
now I am trying to upload the multi-website version to a public host, and am 
encountering
a number of problems, mainly because I have never done any serious work with 
UNIX, and the
host support staff don't understand what I am trying to do.

The problems mainly relate to setting permissions to allow the website to 
access the
engine code. I only have a rough idea of how the permissions work, but I think 
that to
include engine code the website has to have read and execute rights to it, and 
I also
think that so far as the engine is concerned the website will count as 'other'. 
 (I can
easily arrange that all temporary files are written in the website directory.)

I suspect that rather than including the engine code in index.php, it would be 
better to
call functions in it, so that the website only required 'execute' rights, but I 
don't know
of any way to do this without having anything running permanently on the 
server. Can
anyone suggest how it can be done?



--- End Message ---

Reply via email to