php-general Digest 28 May 2008 18:27:21 -0000 Issue 5484

Topics (messages 274758 through 274779):

Re: Restricting access to a file
        274758 by: Adam Richardson
        274765 by: Bastien Koert

Re: PEAR_Exception & PEAR_Error
        274759 by: Chris
        274761 by: Richard Heyes
        274778 by: Al

Re: looking a regular expresion
        274760 by: Robin Vickery
        274776 by: Boyd, Todd M.

strcmp($var1, $var2) versus if ($var1 < $var2)
        274762 by: C.R.Vegelin
        274763 by: David Otton
        274764 by: C.R.Vegelin

Re: A Little Something.
        274766 by: Philip Thompson
        274767 by: Thiago Melo de Paula

Re: Header Redirect
        274768 by: Robert Cummings

OT Smarty problem
        274769 by: George Pitcher
        274771 by: Gabriel Sosa
        274773 by: Iv Ray
        274774 by: Iv Ray
        274777 by: George Pitcher

use of static methods after namespaces arrive
        274770 by: Iv Ray
        274772 by: Adam Richardson
        274775 by: Iv Ray

Calendar Date Help
        274779 by: Mark Weaver

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 --- I usually set up what amounts to a quick controller page. The page accepts a GET variable that identifies the download, and it also delegates to a helper object that determines the access level.

If the delegate determines that the person should be able to download/ view the content, the controller sets the headers, retrieves the file, and then outputs the file contents to the output stream.

Otherwise, the controller redirects the visitor to a page that let's them know they don't have access, but prompts them to pay/sign up to get the access for the product.

Adam

On May 28, 2008, at 2:16 AM, John Comerford wrote:

Hi Folks,

This may not be strictly a PHP question but there may be something in PHP to do what I want. I am in the process of putting together a pretty basic website using MySql and PHP on a third party host. One of the function is to allow known stockist download a catalogue (.pdf). I am fine to do login etc. but I am not sure how to approach restricting the catalogue. I can do it so that the link is only visible if the user logins in, but that doesn't stop the link being downloadable even if it is not visible. I was thinking I could put it in a location not visible to the public and transfer it to a location that is when the user logs in, something with a cryptic name etc... but that doesn't really sit right with me and at very least gives me some house keeping issues....

Anybody got a suggestion as to the best way to handle this ?

TIA,
JC

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


Adam Richardson
Envision Internet Consulting, LLC
Phone: (517)623-0485

Services and insight for building effective, user-oriented websites.




--- End Message ---
--- Begin Message ---
On Wed, May 28, 2008 at 2:23 AM, Adam Richardson <[EMAIL PROTECTED]>
wrote:

> I usually set up what amounts to a quick controller page.  The page accepts
> a GET variable that identifies the download, and it also delegates to a
> helper object that determines the access level.
>
> If the delegate determines that the person should be able to download/view
> the content, the controller sets the headers, retrieves the file, and then
> outputs the file contents to the output stream.
>
> Otherwise, the controller redirects the visitor to a page that let's them
> know they don't have access, but prompts them to pay/sign up to get the
> access for the product.
>
> Adam
>
>
> On May 28, 2008, at 2:16 AM, John Comerford wrote:
>
>  Hi Folks,
>>
>> This may not be strictly a PHP question but there may be something in PHP
>> to do what I want.  I am in the process of putting together a pretty basic
>> website using MySql and PHP on a third party host.  One of the function is
>> to allow known stockist download a catalogue (.pdf).  I am fine to do login
>>   etc.  but I am not sure how to approach restricting the catalogue.  I can
>> do it so that the link is only visible if the user logins in, but that
>> doesn't stop the link being downloadable even if it is not visible.  I was
>> thinking I could put it in a location not visible to the public and transfer
>> it to a location that is when the user logs in, something with a cryptic
>> name etc...  but that doesn't really sit right with me and at very least
>> gives me some house keeping issues....
>>
>> Anybody got a suggestion as to the best way to handle this ?
>>
>> TIA,
>> JC
>>
>> --
>>
>>
-- I usually place the documents in a folder above the web root so that it
can not be acccessed directly through a url, then as Adam suggested, create
a controller that will validate the user, read in the file and send it out
to the user.

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
Al wrote:
> I'm using the pear class Mail_RFC822::parseAddressList() which
> apparently only throws an error_object for PEAR_Error.
> 
> The manual says that PEAR_Error is deprecated, so I'd like to use
> PEAR_Exception; but; am having trouble getting it to recognize the error.

Probably better to ask the pear mailing list:

http://pear.php.net/support/lists.php

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
I'm using the pear class Mail_RFC822::parseAddressList() which apparently only throws an error_object for PEAR_Error.


You might want to consider the filter_var() function if you can - it will be much faster.

The manual says that PEAR_Error is deprecated, so I'd like to use PEAR_Exception; but; am having trouble getting it to recognize the error.

Can anyone help me with this?

You could use your own version of RFC822.php and use the wonderful search and replace. Don't worry about updates, Mail_RFC822 is quite stable, and has been for some years.

--
              Richard Heyes

         In Cambridge? Employ me
        http://www.phpguru.org/cv

+----------------------------------------+
| Access SSH with a Windows mapped drive |
|    http://www.phpguru.org/sftpdrive    |
+----------------------------------------+

--- End Message ---
--- Begin Message ---
filter_var() is an excellent suggestion and works great.

Richard Heyes wrote:
I'm using the pear class Mail_RFC822::parseAddressList() which apparently only throws an error_object for PEAR_Error.


You might want to consider the filter_var() function if you can - it will be much faster.

The manual says that PEAR_Error is deprecated, so I'd like to use PEAR_Exception; but; am having trouble getting it to recognize the error.

Can anyone help me with this?

You could use your own version of RFC822.php and use the wonderful search and replace. Don't worry about updates, Mail_RFC822 is quite stable, and has been for some years.


--- End Message ---
--- Begin Message ---
2008/5/27 Manuel Pérez López <[EMAIL PROTECTED]>:
> Hello:
>
> I need to include a pair of negations with two complete word into a regular
> expresion for preg_replace. How to do this?
> I want to replace "I want to be a SUN and a SIR" with "FRIKI FRIKI FRIKI
> FRIKI FRIKI SUN FRIKI FRIKI SIR"
>
> ie. the words are: SUN and SIR. And the replacement word is: FRIKI
>
> $st = preg_replace ("\b([^S][^U][^N])|([^S][^I][^R]\b)", "FRIKI",$st);

with a negative lookahead assertion:

$st = preg_replace('/\b(?!SUN\b|SIR\b)\w+/', 'FRIKI', $st);

-robin

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Manuel Pérez López [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 27, 2008 2:06 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] looking a regular expresion
> 
> Hello:
> 
> I need to include a pair of negations with two complete word into a
> regular
> expresion for preg_replace. How to do this?
> I want to replace "I want to be a SUN and a SIR" with "FRIKI FRIKI
> FRIKI
> FRIKI FRIKI SUN FRIKI FRIKI SIR"
> 
> ie. the words are: SUN and SIR. And the replacement word is: FRIKI
> 
> $st = preg_replace ("\b([^S][^U][^N])|([^S][^I][^R]\b)", "FRIKI",$st);
> 
> This does not  match
> 
> Anyone hep me?
> 
> Thanks

Man... this is really irritating the heck out of me. I have recently been 
learning regular expressions, and thought I was "fresh" enough to fix this with 
new eyes. However, I've been running into all kinds of trouble, and I now 
impatiently anticipate an expert's answer, much the same as you. :)

It's interesting to me that ``$st = preg_replace("(SUN)", "FRIKI", $st);`` 
replaces the word "SUN" with the word "FRIKI", but ``$st = 
preg_replace("(^SUN)", "FRIKI", $st);`` does the same thing (when it should be 
replacing everything BUT the word "SUN").

Annoying behavior. Is this particular to PHP's regular expression engine? I 
should try this in VB.NET and see what the results are, as that's what I'm used 
to playing with (for the time being).


Todd Boyd
Web Programmer



--- End Message ---
--- Begin Message ---
Hi All,

I must be overlooking something here ...

$var1 = "01011090"; $var2 = "010190"; // 2 strings
if ($var1 < $var2) ECHO "var1 < var2"; else ECHO "var1 >= var2"; echo "<br />";
$r = strcmp ( $var1 , $var2 );
if ($r < 0) ECHO "var1 < var2", "<br />";

2nd line says: $var1 >= $var2
4th line says: $var1 < $var2

TIA, Cor

--- End Message ---
--- Begin Message ---
2008/5/28 C.R.Vegelin <[EMAIL PROTECTED]>:

> $var1 = "01011090"; $var2 = "010190"; // 2 strings
> if ($var1 < $var2) ECHO "var1 < var2"; else ECHO "var1 >= var2"; echo "<br 
> />";
> $r = strcmp ( $var1 , $var2 );
> if ($r < 0) ECHO "var1 < var2", "<br />";
>
> 2nd line says: $var1 >= $var2
> 4th line says: $var1 < $var2

Implicit type conversion. "<" is a numeric operator, so your strings
are silently promoted to integers, where (1011090 > 10190).

strcmp() treats the strings as strings, and orders them in something
close to ASCII order (which isn't the same as alphabetical ordering,
BTW, and see the comments at www.php.net/strcmp for locale-specific
gotchas).

PHP's implicit conversions can bite you if you don't understand them.
Try this one:

$a = 'string';
$b = 0;
if ($a==true && $b==false && $a==$b)
{
    echo ('universe broken');
}

--- End Message ---
--- Begin Message --- ----- Original Message ----- From: "David Otton" <[EMAIL PROTECTED]>
To: "C.R.Vegelin" <[EMAIL PROTECTED]>
Cc: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
Sent: Wednesday, May 28, 2008 12:11 PM
Subject: Re: [PHP] strcmp($var1, $var2) versus if ($var1 < $var2)


2008/5/28 C.R.Vegelin <[EMAIL PROTECTED]>:

$var1 = "01011090"; $var2 = "010190"; // 2 strings
if ($var1 < $var2) ECHO "var1 < var2"; else ECHO "var1 >= var2"; echo "<br />";
$r = strcmp ( $var1 , $var2 );
if ($r < 0) ECHO "var1 < var2", "<br />";

2nd line says: $var1 >= $var2
4th line says: $var1 < $var2

Implicit type conversion. "<" is a numeric operator, so your strings
are silently promoted to integers, where (1011090 > 10190).

strcmp() treats the strings as strings, and orders them in something
close to ASCII order (which isn't the same as alphabetical ordering,
BTW, and see the comments at www.php.net/strcmp for locale-specific
gotchas).

PHP's implicit conversions can bite you if you don't understand them.
Try this one:

$a = 'string';
$b = 0;
if ($a==true && $b==false && $a==$b)
{
   echo ('universe broken');
}


Hi David,
I already suspected that the > operator forced a numeric comparison.
Even if I use: if ((string) $var1 < (string) $var2) ...
So I have to use strcmp()
Thanks, Cor





--- End Message ---
--- Begin Message ---
On May 24, 2008, at 5:06 PM, Michelle Konzack wrote:

Thanks, Greetings and nice Day
   Michelle Konzack
   Systemadministrator
   24V Electronic Engineer
   Tamay Dogan Network
   Debian GNU/Linux Consultant


-- Linux-User #280138 with the Linux Counter, http://counter.li.org/ ##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
+49/177/9351947    50, rue de Soultz         MSN LinuxMichi
+33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)

It's amazing how someone so involved in security would provide any of this information. Name, job, location, phone numbers, Internet contact. You might as well have given the name of your children as well. Nevermind, I'll go find that out on Google. =P

~PT


"Personally, most of my web applications do not have to factor 13.7 billion years of space drift in to the calculations, so PHP's rand function has been great for me..." ~S. Johnson


--- End Message ---
--- Begin Message ---
What a endless boring off topic thread...
I'm wondering if some day this one will finish and we will talk about
serious and relevant stuffs.
Some of you will tell me to simply don't read the thread... but what is
making me seek is the fact of this message always appear on top my email
list!
Ok, that's all folks, I'm gone!

Regards,

Thiago

On Wed, May 28, 2008 at 8:40 AM, Philip Thompson <[EMAIL PROTECTED]>
wrote:

> On May 24, 2008, at 5:06 PM, Michelle Konzack wrote:
>
>  Thanks, Greetings and nice Day
>>   Michelle Konzack
>>   Systemadministrator
>>   24V Electronic Engineer
>>   Tamay Dogan Network
>>   Debian GNU/Linux Consultant
>>
>>
>> -- Linux-User #280138 with the Linux Counter, http://counter.li.org/
>> ##################### Debian GNU/Linux Consultant #####################
>> Michelle Konzack   Apt. 917                  ICQ #328449886
>> +49/177/9351947    50, rue de Soultz         MSN LinuxMichi
>> +33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)
>>
>
> It's amazing how someone so involved in security would provide any of this
> information. Name, job, location, phone numbers, Internet contact. You might
> as well have given the name of your children as well. Nevermind, I'll go
> find that out on Google. =P
>
> ~PT
>
>
> "Personally, most of my web applications do not have to factor 13.7 billion
> years of space drift in to the calculations, so PHP's rand function has been
> great for me..." ~S. Johnson
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Tue, 2008-05-27 at 20:50 +0100, Stut wrote:
> On 27 May 2008, at 19:18, Robert Cummings wrote:
> > On Tue, 2008-05-27 at 18:04 +0100, Stut wrote:
> >> On 27 May 2008, at 17:54, Robert Cummings wrote:
> >>> On Tue, 2008-05-27 at 17:10 +0100, Stut wrote:
> >>>> On 27 May 2008, at 17:06, Yui Hiroaki wrote:
> >>>>> I would like to have some question.
> >>>>>
> >>>>> For example,
> >>>>> I am in http://example.com/?12324242
> >>>>>
> >>>>> I would like to REDIRECT from  http://example.com/?1312323232
> >>>>> to  http://example.com/
> >>>>>
> >>>>> I can REDIRECT from http://example.com/index.php to http://example.com
> >>>>>
> >>>>>
> >>>>> Please do tell me how I can redirect!
> >>>>>
> >>>>>
> >>>>> This is the sample what I test below!
> >>>>>
> >>>>> <?php
> >>>>> if ($_SERVER['REQUEST_URI'] == '/index.php') {
> >>>>> header("HTTP/1.1 301 Moved Permanently");
> >>>>> header("Location: http:///example.com/";);
> >>>>> exit();
> >>>>> }
> >>>>> ?>
> >>>>
> >>>> 1) Why? Redirects should be avoided where possible for performance
> >>>> reasons.
> >>>
> >>> Didn't this topic get covered several months back. I always do
> >>> redirects
> >>> so as not to bugger browser history, titles, indexing, etc. If  
> >>> someone
> >>> requests a page and they need to be logged in, I redirect to the  
> >>> login
> >>> page, I never just present the login page... that's just incorrect
> >>> from
> >>
> >> Personally I tend to only use redirects when a form handler has done
> >> it's job to avoid evil messages when the user hits back. However, I
> >> have used both redirected and non-redirected login workflows in the
> >> past for various reasons, and I don't believe there is a "standard"
> >> way to do it. It depends on how the site will be used and by whom.
> >>
> >>> a hierarchical and semantic point of view. Similarly, if I'm doing  
> >>> 404
> >>> handling with fuzzy request sniffing to determine what was actually
> >>> requested, I again perform a redirect once I've ascertained what was
> >>> probably desired. If you don't, then Google and other search engines
> >>> will index these malformed URLs instead of the correct URL.
> >>
> >> The correct response to a 404 page is 404. No arguments. If you
> >> redirect missing pages then your site effectively contains an  
> >> infinite
> >> number of pages. By all means display a useful page when you return
> >> your 404 but not marking it as a missing page does little if anything
> >> for your SEO rank and absolutely nothing for your users.
> >
> > 404 "Not Found", but it was found, but it's not where you asked for  
> > it,
> > it's over there... we've permanently moved it from here to there (even
> > if only virtually)... let's redirect you to the correct location.  
> > Since
> > you perform a redirect to the correct location, the content is
> > appropriately indexed where it actually exists. If you return a 404
> > status I'm pretty sure Google discards the content.
> 
> If you can successfully fulfil the request then it's not a 404, but I  
> would question why you're getting requests for URLs that don't exist  
> but that you can accurately service. If you're using the URL as a  
> search field then your site truly has no missing pages.
> 
> However, in that case it's unlikely you'll be redirecting since for a  
> lot of queries you'll end up with multiple results meaning you're not  
> accurately fulfilling the request unless there's only one result from  
> the search. In that case I would agree that a redirect is the done  
> thing - except where the user got there by doing a search, which is  
> where things get cloudy as some would say it's appropriate to show  
> search results since that's the reasonable user expectation, and  
> others would say it should redirect to the single result - where I'd  
> come down on that would depend on the content and average user profile.
> 
> *breath!*
> 
> If you return a 404 Google does indeed discard the content - that's  
> the logical thing for it to do.  301's allow it to reduce the URLs  
> used to access your site to a core set of "real" content. Given that,  
> I agree to your premise that if you can successfully fulfil the  
> request by redirecting then you should, but only if it's an accurate  
> response to the request and not a "best guess". Best guesses should be  
> presented to the user (and Google) as a page suggesting content and  
> providing other ways to find it if your suggestion is not correct.
> 
> I'm starting to ramble so I'll stop here. I hope the point I'm making  
> is clear in there somewhere.
> 
> >> IMHO if you're going to use a semantic argument to defend one point
> >> you need to carry that attitude throughout.
> >
> > My semantic argument is still intact. If I found it, then it's not
> > deserving of "404 Not Found" status. Sure it may not be at the  
> > requested
> > location, but that's what the moved status is for.
> 
> The 301 status code was created so web developers can re-organise  
> their websites without adversely affecting the user experience. A side  
> effect of this is that search engines also use them to keep their  
> index up to date without affecting the sites ranking.
> 
> > Here's a physical world analogy. Walk into a hardware store ask for
> > object X. If they have it they will tell you. If they don't then  
> > either
> > they will say, "Sorry, we don't have that. I don't have a clue where  
> > you
> > can get it", or if they do know (and want to help) they'll say "It's
> > over there at Rob's Hardware Store". What they almost certainly won't
> > say is hang on, then run over to Rob's hardware Store, buy item X,  
> > come
> > back and try to sell it to you. Almost certainly, but who knows,  
> > people
> > do weird things sometimes :)
> 
> Taking that analogy a step further, the original hardware store is  
> unlikely to pick you up and physically take you to Rob's Hardware  
> Store. In fact you said it... [they'll say "It's over there]... which  
> in web terms would be a page saying "we couldn't find what you were  
> looking for where you were looking, but we found it over there".  
> That's what I'm advocating.

But, that's what the 301 does... it's say it's over there. Your browser
is what actually takes you over there. And I know in Opera you can
disable automatic redirects so that you actually have to say... hey I
wanna go where I was told to go.

> > So here's something else since you played the performance card.  
> > Click on
> > the following link and tell me where you end up when not already  
> > logged
> > in:
> >
> >    http://mail.google.com/mail/
> >
> > I'm sure Google had a good reason for that behaviour, as in it's  
> > follows
> > more correctly the standard expected request behaviour, and I'm sure
> > they get a LOT of hits ;)
> 
> First off I really do wish people would get it out of their heads that  
> just because a company such as Google does something it's the best or  
> right way to do it. Secondly there are two separate scenario's that  
> are being mixed up.

*lol* I didn't use Google because they are obviously correct, my primary
reason for using Google was because they chose to redirect despite that
high probably they would have concerns about performance.

I'll let this die here. I know it wasn't really resolved the last time
either. My hackles just go up when someone argues performance as a
reason to present information in the wrong location :) For instance,
let's have Google start an index for the following page:

    http://www.php.net/sha5

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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

Apologies for posting this here but coudn't find a decent Smarty list.

I've been using Smarty for 4 years without much problem. I'm adding some
extra functionality to a page used by 2 members of staff. My snippets of
relevant code are:

$smarty->assign('clearance',      $clearbits['clearance_alt']);

<td align="right" class="s9">Clearance&nbsp;{$clearance}</td>
<td class="s9">&nbsp;</td>
<td bgcolor="aliceblue"><select class="formInputText" id="clearance_alt"
name="clearance_alt">
      <option value=0{if $clearance==0} selected{/if}>Select</option>
      <option value=1{if $clearance==1} selected{/if}>Yes</option>
      <option value=2{if $clearance==2} selected{/if}>No</option>
      <option value=3{if $clearance==3} selected{/if}>Failed</option>
</select></td>

You will see that I have called the variable in the first column. On the web
page, this displays as "Clearance 1". I would then expect 'Yes' to appear
selected in the column three drop-down box. Unfortunately, this displays as
'Select'.

I have tried deleting all the cached template files as well as single and
double quotes around the 0,1,2,3 values, all to no avail.

All the other Smarty stuff seems to be working on the site.

Can anyone point me in the right direction?
Cheers

George in wet and windy Edinburgh


--- End Message ---
--- Begin Message ---
try doing this..

{if $clearance eq 0}

instead use ==

i saw that some version of smarty has a bug related to this issue

BTW .. you could use the options helper [1]

saludos
gabriel




[1] http://www.smarty.net/manual/en/language.function.html.options.php




On Wed, May 28, 2008 at 11:46 AM, George Pitcher
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> Apologies for posting this here but coudn't find a decent Smarty list.
>
> I've been using Smarty for 4 years without much problem. I'm adding some
> extra functionality to a page used by 2 members of staff. My snippets of
> relevant code are:
>
> $smarty->assign('clearance',      $clearbits['clearance_alt']);
>
> <td align="right" class="s9">Clearance&nbsp;{$clearance}</td>
> <td class="s9">&nbsp;</td>
> <td bgcolor="aliceblue"><select class="formInputText" id="clearance_alt"
> name="clearance_alt">
>      <option value=0{if $clearance==0} selected{/if}>Select</option>
>      <option value=1{if $clearance==1} selected{/if}>Yes</option>
>      <option value=2{if $clearance==2} selected{/if}>No</option>
>      <option value=3{if $clearance==3} selected{/if}>Failed</option>
> </select></td>
>
> You will see that I have called the variable in the first column. On the web
> page, this displays as "Clearance 1". I would then expect 'Yes' to appear
> selected in the column three drop-down box. Unfortunately, this displays as
> 'Select'.
>
> I have tried deleting all the cached template files as well as single and
> double quotes around the 0,1,2,3 values, all to no avail.
>
> All the other Smarty stuff seems to be working on the site.
>
> Can anyone point me in the right direction?
> Cheers
>
> George in wet and windy Edinburgh
>
>



-- 
Los sabios buscan la sabiduría; los necios creen haberla encontrado.
Gabriel Sosa

--- End Message ---
--- Begin Message ---
Hi George,

I tried your code and it works.

If you have some way of remote assistance I can have a look "on-site", if you like.

But it could be that you just need a good sleep, and then look again ;)

Iv

--- End Message ---
--- Begin Message ---
Gabriel Sosa wrote:
> try doing this..
>
> {if $clearance eq 0}
>
> instead use ==
>
> i saw that some version of smarty has a bug related to this issue
>
> BTW .. you could use the options helper [1]
>
> saludos
> gabriel

Right... I forgot to ask which Smarty version you have. I tried it with the last.

Iv

--- End Message ---
--- Begin Message ---
Iv,

Thanks, but its Firefox to blame. Apparently it holds previously stored values 
in form fields. These are released when the user holds shift while reloading.

Cheers

George

>| -----Original Message-----
>| From: Iv Ray [mailto:[EMAIL PROTECTED]
>| Sent: 28 May 2008 4:55 pm
>| To: George Pitcher
>| Cc: [EMAIL PROTECTED]
>| Subject: Re: [PHP] OT Smarty problem
>| 
>| 
>| Hi George,
>| 
>| I tried your code and it works.
>| 
>| If you have some way of remote assistance I can have a look "on-site", 
>| if you like.
>| 
>| But it could be that you just need a good sleep, and then look again ;)
>| 
>| Iv
>| 


--- End Message ---
--- Begin Message --- In which situation would somebody use a static method, instead of a function in a namespace, after the namespaces arrive with 5.3?

Iv

--- End Message ---
--- Begin Message ---
If the functionality doesn't conceptually promote the inclusion of the
variables it works on (i.e., no class variables), doesn't conceptually fit a
scheme where instances can exist, and likely won't benefit from refactoring
into component methods, then I could see using a namespaced function.
Most of the time, though, I'd probably start out with a class method instead
of a namespaced function so I could more readily adapt to OOP practices if
desired as the implementation evolves.

Adam

On Wed, May 28, 2008 at 11:33 AM, Iv Ray <[EMAIL PROTECTED]> wrote:

> In which situation would somebody use a static method, instead of a
> function in a namespace, after the namespaces arrive with 5.3?
>
> Iv
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Adam Richardson wrote:
If the functionality doesn't conceptually promote the inclusion of the variables it works on (i.e., no class variables), doesn't conceptually fit a scheme where instances can exist, and likely won't benefit from refactoring into component methods, then I could see using a namespaced function.

Here I would do the same.

Most of the time, though, I'd probably start out with a class method instead of a namespaced function so I could more readily adapt to OOP practices if desired as the implementation evolves.

Hm...

Would you consider it safer to convert a static method into an instance method, than implementing a namespaced function into a (new) class and redirecting the calls?

I am not starting a fight, I am really interested in what you think.

Iv

--- End Message ---
--- Begin Message ---
Hi all,

I've put this off as long as possible, however I think I've reached an impasse.

I've got an application that I've been writing. One of the modules for this app is an event calendar. I've got the calendar to the place where it displays the current month as well as previous and future months. The place I'm stuck is it will only show months in the past or the future that are months in the current year.

Basically the method I'm using to move backward and forward is with Unix timestamps.

1. When the calendar first loads the "what" is checked for;
        // passed in via $_GET
        $what == current, prev, or next
  a. "current" is the default
        $now = time()
        $prev = date('n',$now)-1
        $next = date('n',$now)+1
  b. Timestamp values are then stored in an array and then
        sent to client in session cookie which is then accessed
        upon each subsequent request to display the event calendar.

My question/boggle is why, when the calendar advances to December(current year) it will display January, but of the current year. The same happens in reverse.

Once I reach the end of the year either in the past or future the month increases or decreases accordingly, but the year doesn't change. Since the year value isn't changing the month calendar days that are displayed simply repeat themselves.

I know there's something I'm missing, but I am definitely not seeing what it is...

/********************** code below ************************/

$cal = new Calendar;
$calpos = array();
                        
// check incoming values
if ($what === "current"){
        $cal->setCal(0,0,0,date('n'),1);
        $now = time();
        $prev = $cal->getStamp(date('n',$now)-1,1);
        $next = $cal->getStamp(date('n',$now)+1,1);
        $calpos['curr'] = $now;
        $calpos['prev'] = $prev;
        $calpos['next'] = $next;
        $_SESSION['calendar'] = $calpos;
}       
elseif($what === "prev"){
        $peek = $_SESSION['calendar'];
        $now = $peek['prev'];
        $cal->setCal(0,0,0,date('n',$now),1);
        $prev = $cal->getStamp(date('n',$now)-1,1);
        $next = $cal->getStamp(date('n',$now)+1,1);
        $calpos['curr'] = $now;
        $calpos['prev'] = $prev;
        $calpos['next'] = $next;
        $_SESSION['calendar'] = $calpos;
}
elseif($what === "next"){
        $peek = $_SESSION['calendar'];
        $now = $peek['next'];
        $cal->setCal(0,0,0,date('n',$now),1);
        $prev = $cal->getStamp(date('n',$now)-1,1);
        $next = $cal->getStamp(date('n',$now)+1,1);
        $calpos['curr'] = $now;
        $calpos['prev'] = $prev;
        $calpos['next'] = $next;
        $_SESSION['calendar'] = $calpos;
}

<================================================================>
function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){              
  $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y')));
  // Using the stamp the various necessary properties are set for the
  // object

function getStamp($dateStr,$dayVal=1){
  return date('U',mktime(0,0,0, $dateStr,$dayVal,date('Y')));
}

--

Mark
-------------------------
the rule of law is good, however the rule of tyrants just plain sucks!
Real Tax Reform begins with getting rid of the IRS.
==============================================
Powered by CentOS5 (RHEL5)

--- End Message ---

Reply via email to