Re: [PHP] Random 404 screens

2013-02-09 Thread Geoff Shang

On Sat, 9 Feb 2013, Jim Giner wrote:

Lately, my web pages are giving me some problems.  Once a day or so one or 
more of my pages/scripts will give me a 404 error page saying my web page has 
timed out.  Problem is that the page was just displayed.  I click on a link, 
the page shows up, I click on a button on it to trigger some activity and 
voila!  An error.  I hit refresh and my page is back and things work ok.


Since someone mentioned network issues, I will ask this question.

Is it actually a 404 page?  That is to say, does the string 404 
actually appear in the error document?


If it does, then this would rule out your home network, as 404 is a 
response code returned by the webserver.


Geoff.


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



Re: [PHP] Some date() oddities

2013-01-08 Thread Geoff Shang

On Tue, 8 Jan 2013, Arno Kuhl wrote:


Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
1356952332) I calculate a week number:

$ux_date = 1356952332;

$weeknumber = date(W, $ux_date);   // returns 01 instead of 52


I'm not that familiar with date, I tend to use strftime myself (no idea 
why there's both).  Sounds like date's W is equivalent to strftime's %V 
which does indeed return 01 for this date as there's at least 4 days of 
the new year in that particular week.


Both %U and %W seem to return what you want, using strftime.  I'd guess 
that date would also have flags for these.


Cheers,
Geoff.


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



Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Geoff Shang

On Thu, 3 Jan 2013, Jim Giner wrote:

The only time I use a single '=' symbol in an if statement is when I forget 
to use two of them!  Must be my old school, old languages habits but this 
style of programming reminds me of the days when we used to pack empty spaces 
in assembler code with constants or byte-size vars in order to save memory 
back when memory was the most precious resource one had.


The only time I'd consider doing it is if the next thing I was going to do 
would be check to see if the assignment itself worked.  for example:


if (file_handle = fopen(foo, r)) {
...
}

Geoff.


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



Re: [PHP] Wrong time being displayed by PHP!

2012-10-17 Thread Geoff Shang

On Wed, 17 Oct 2012, Richard S. Crawford wrote:


I've confirmed that the server is set to PDT. The value of date.timezone in
php.ini is America/Los_Angeles, which should be (currently) -8 hours from
UTC, but it looks like the PDT offset is only set to -4. Does that even
make sense?


Actually, PDT is UTC minus 7, not 8.  But that's not the point.

I know people are pointing at a configuration issue, and it may well be. 
But the fact that PHP seems to have the correct idea for what UTC is 
suggests that perhaps either PHP or the (presumably) C routines that it 
uses may be at least contributing to this.


This is not the first time I've seen strangeness with default timezones, 
and I guess there's a reason why using them generates a warning.  Best to 
deliberately set your timezone.  Now if it still does it when you actually 
set it to America/Los_Angeles then we've got a bigger problem.


Geoff.


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



Re: [PHP] PHP Time

2012-07-02 Thread Geoff Shang

On Mon, 2 Jul 2012, Rob Weissenburger wrote:


 I know php time() gives the current unix time which you can format out to
a normal date and time. Is there a way to format a specific date and time
back to unix time?


mktime() and strtotime() will do it, depending on the form your time is 
in.  There's probably others.


Geoff.


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



Re: [PHP] slicing and dicing strings

2012-06-28 Thread Geoff Shang

On Wed, 27 Jun 2012, tamouse mailing lists wrote:


RTFM with no hint of where to look is a problem. But the dictum of
Read here in the manual will surely be the best thing. You will then
know where to look for future questions.


Personally, I've got better things to do with my time than spend it 
committing the syntax and semantics of every single PHP function to 
memory.  I nearly always have the php.net front page with its function 
search open in a browser whenever I'm writing something more than a few 
lines.  The function search seriously rocks.  Even if I can't remember 
which string function I want, I can search for *any* string function and 
I'll get the list of all of them, along with a quick summary to help me 
find the one I want.


Geoff.


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



Re: [PHP] regexp novice

2012-05-20 Thread Geoff Shang

Stuart Dallas stu...@3ft9.com wrote:


On 18 May 2012, at 14:50, Jim Giner wrote:


Daft is a little harsh.  :)  00:40 is just not a time value that is
generally accepted.



It may appear harsh, but as far as I'm concerned it is daft to make
assumptions like that. You've essentially disallowed 12:nn am, but allowed
1:nn am, 2:nn am, 3:nn am, etc, because you're not validating the data in a
non-ambiguous way. I have no idea what you're developing, but you're making
a big assumption about the data that you're getting, which may appear
reasonable to you, but to me it's daft. Nothing personal, just my opinion,
which is all I have to offer.


Unless I've missed something, he hasn't disallowed 12:nn am, only 00:nn. 
If you're going to only accept 12-hour input, this is the right thing to 
do.  00:nn is not a valid 12-hour representation - only times from 1:nn to 
12:nn are acceptable.  If you were to accept 00:nn, you'd have to also 
accept 13:nn-23:nn as well, for consistancy.


Granted, not specifying am or pm adds a layer of ambiguity, but maybe 
that's not relevant for this query.  For example, maybe there's also a 
select field that has am and pm as options.


As it appears that accepting only 12-hour input is part of the brief, Jim 
is IMHO doing the right thing.


Geoff.


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



Re: [PHP] strftime silliness

2012-04-10 Thread Geoff Shang

On Wed, 10 Apr 2012, Tim Streater wrote:

I want to format a date/time using a 12 hour representation of the time 
part. I can do this with, say, %d %b %Y %l:%M %p, where the first time 
format specifier is the lower-case L. But, this gives me a leading space 
in the case that the hour is less than 12. I don't want this space. 
Anyone know of an simple way to avoid it? There appears to be no 
specifier to do this. Of course, I can call strftime twice, once for the 
date portion and once for the time portion, trimming the latter, but 
that seems clumsy.


You can use %-l to achieve this.  You could also use %-I as this will also 
drop leading zeros if present.


I forget where I read about this.  I'm almost certain that it was *not* in 
any PHP documentation.


HTH,
Geoff.


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



Re: [PHP] basic captcha

2012-02-17 Thread Geoff Shang

On Fri, 17 Feb 2012, Ashley Sheridan wrote:

I would avoid making a user type in something they see in a picture, as 
you've just succeeded in pissing off a bunch of blind people.


Thank you!  Glad someone pointed this out so I didn't have to.

And if you use a system like Recaptcha which has an audio option, you've 
still locked out deafblind users.


Also, avoid relying on javascript. It can be turned off, disabled, 
blocked and sometimes isn't available at all, such as with some 
speech/Braille browsers.


Or lynx.  Yes I'm a blind person, but even a person who isn't may want to 
use it quickly from a shell to get something done.


One popular route is to ask a question that only a human could answer. I 
use this method on the contact page of my site. I just ask a question 
such as


Multiply the number of heads a person has by the number of legs on 2 dogs.

It's easy for a human, but requires context, something a bot can't do 
effectively.


Since the person was looking for a ready-made solution, I'd like to 
recommend TextCaptcha.com.  It claims to have 180,243,205 easy questions, 
and even has an article on ways to avoid needing a CAPTCHA in the first 
place.


I once (and only once) struck a test like this on a New Zealand government 
website.  I nearly died of shock.  And I was able to use it with lynx 
with no problems at all.


Geoff.


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



Re: [PHP] Update mailing list docs - How to unsubscribe?

2012-01-23 Thread Geoff Shang

On Mon, 23 Jan 2012, Matty Sarro wrote:


I have been trying to unsubscribe from this list. I've gone through the
directions at http://www.ezmlm.org/ezman/ezman1.html as suggested by
http://us.php.net/mailing-lists.php. They don't seem to apply for these
lists as written (the method listed for unsubscribing involves sending an
email to mailinglist-unsubscr...@example.org, which in this case would be
mailinglist-unsubscr...@lists.php.net which sends back a lovely invalid
email address response).


list-unsubscribe: mailto:php-general-unsubscr...@lists.php.net

Geoff.


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



Re: [PHP] Sniping on the List

2011-11-22 Thread Geoff Shang

Hi,

Apologies if this has moved on, I've not read all my mail from the last 
day and a half.


On Mon, 21 Nov 2011, Tedd Sperling wrote:

Let's consider this -- you are in a different time zone than me, right? 
You said UTC and mine is America New York. As such you claim is that 
your strtotime() function will return a different result for you as 
compared to me because of the time zone differences, right?


Only some of the time.  It depends on the input.

If so, then tell me why I can take both sites (your and mine) and click 
the Submit buttons at the same time and the forms will report back the 
exact same number of elapsed seconds. Try it (you got to be quick):


The timezone affects two things, the input and the output.  If your input 
is absolute and not timezone dependent, both scripts will output the same 
seconds calculation.  But if it is affected by timezone, then the seconds 
count will be different.


Here's an example from a previous message.  The string 1 January 1970 
00:00:00 is timezone dependent, as it is midnight according to the 
particular timezone.


Output from your copy:

String Given: 1 January 1970 00:00:00

Seconds Computed from String: 18000

Output from my copy:

String Given: 1 January 1970 00:00:00

Seconds Computed from String: 0

This is because the number of seconds (aka the Unix Timestamp) is *not* 
affected by timezones - it's the number of seconds since 1 January 1970 
00:00:00 UTC.  This is why it's 0 on my server and 18000 on yours, as 
midnight was 5 hours later in New York.


But if you enter a string like now, you'll get the current time with the 
same timestamp from both scripts.


String Given: now

Seconds Computed from String: 1322033486

Here's where the output side comes in.  The various date display 
functions will output according to the selected timezone, or the system 
default if none is selected.  So this will display differently on your 
server and on mine.


Lets use the value of 'now' above to demonstrate:

$ php -r 'date_default_timezone_set (America/New_York); echo date (r, 
1322033486);'

Wed, 23 Nov 2011 02:31:26 -0500

php -r 'date_default_timezone_set (UTC); echo date (r, 1322033486);'
Wed, 23 Nov 2011 07:31:26 +

Same input, different output.

Now if you combine these two factors, it explains all the results you see. 
If you use strings like today or 1 January 1970 00:00:00, the scripts 
will print the same date (and time if you asked it to), but they aren't 
actually the same, as one is 5 hours behind the other.   But if you use an 
absolute time like now or 1 January 1970 00:00:00 + (which 
specifies the timezone), the scripts will print different times based on 
the timezone.


Now, to the point under debate.  Since values like 0 and null are absolute 
rather than relative, the output will vary depending on which timezone is 
in use.


$ php -r 'date_default_timezone_set (UTC); echo date (r, null);'
Thu, 01 Jan 1970 00:00:00 +

$ php -r 'date_default_timezone_set (America/New_York); echo date (r, 
null);'

Wed, 31 Dec 1969 19:00:00 -0500

Geoff.


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



Re: [PHP] Sniping on the List

2011-11-20 Thread Geoff Shang

On Sat, 19 Nov 2011, Tedd Sperling wrote:


My observations are demonstrated here:

http://www.webbytedd.com//strtotime/index.php


this code would IMHO be more useful if it also displayed time, not just 
date.  It's also not clear what timezone you're using, as it's not set as 
far as I can see.


Please note that regardless of time zone, the strtotime() function works 
(or at least it does for me) such that:


If you enter '-1', the function will report back Todays Date with 
current seconds. Note there is no difference between entering 'Today' or 
'-1'.


This is not what your code shows.

String Given: -1

Seconds Computed from String: 1321805103

Date from Seconds Computed: 20 November, 2011 : Sunday

___

Current Time (seconds): 1321819503

Current Date: 20 November, 2011 : Sunday

This is a difference of 14400 seconds or 4 hours.

String Given: today

Seconds Computed from String: 1321765200

Date from Seconds Computed: 20 November, 2011 : Sunday

___

Current Time (seconds): 1321819877

Current Date: 20 November, 2011 : Sunday

This is a much larger difference.  'today' is meant to return the same as 
'today 00:00:00'.  I  know it used not to, it was a PHP bug awhile back... 
which begs the question, which PHP version are you using?



If you enter '0', the function will report back December, 31, 1969.


You'll also notice that the value of seconds computed from string is 
blank (i.e. not 0).  This is because strtotime() doesn't know what to do 
with a value of '0'.  Whether it should or not is probably a 
phillosophical debate.



If you enter nothing (i.e., null), then it reports back December, 31, 1969.


It does, but we dont' know exactly when this is because your script 
doesn't show time.  It could be actually returning a 0 timestamp.


We can force your script to show us what 0 time is according to its 
timezone by entering an absolute date including UTC offset.


String Given: 1 January 1970 +

Seconds Computed from String: 0

Date from Seconds Computed: 31 December, 1969 : Wednesday

___

So your script shows 31/12/1969 for the epoch, so we dont' know if the 
null value is the epoch or before.


To further prove my point, witness the number of seconds calculated from 1 
January 1970 in your script's timezone:


String Given: 1 January 1970

Seconds Computed from String: 18000

Date from Seconds Computed: 1 January, 1970 : Thursday

___

This means your script is using a timezone of UTC -0500 (US Eastern).  So 
any time within the first 5 hours of the epoch will show as being in 1969.


To avoid this, explicitly set your script to use UTC.  Or use US Eastern 
but be up front about the fact that your'e doing this.



It's clear (and by definition) that unix zero time (i.e., 00:00:00) happened in 
1970.

It's also clear that time before unix zero happened before 1970 (i.e., 
'December 31, 1969').

As such, null (and not the string 'null' as stated my someone else, duh) should come back as 
undefined OR December, 31, 1969.


It doesn't for me, using either PHP 5.2.6 or 5.3.3.

php -r 'echo date (r, strtotime ());'
Thu, 01 Jan 1970 00:00:00 +


Furthermore, the string '-1' should default to '-1 second' instead of being the 
same as if I entered 'Today'.


Apart from the fact that for me at least, strtotime (today) returns 
today at midnight, whereas strtotime (-1) seems to return something else 
(time() + 3600 on boxes set to UTC, time() + 10800 on my box set to local 
time in Israel), strtotime is meant to turn textual representations of 
time into a unix timestamp.  Surely the meaning of -1 is at the very 
least ambiguous, and the fact that it returns anything is surprising.



Now, where are my observations wrong? The code is shown in the demo.


To summarise, your observations are wrong because they do not take 
timezone into account and do not show the time, only the date.  And some 
of your observations as given above do not match what your script outputs.


Geoff.

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



Re: [PHP] Parsing the From field

2011-11-20 Thread Geoff Shang

On Sat, 19 Nov 2011, Ron Piggott wrote:


Also the formatting of the from field changes in various e-mail programs:

From: Ron Piggott ron.pigg...@actsministries.org
From: Ron Piggott ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org
From: ron.pigg...@actsministries.org


I've also seen:

Piggott, Ron ron.pigg...@actsministries.org

And that's before you get to people who only use their first name and 
people who use some kind of alias.


I think you did well to abandon this.

Geoff.


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



Re: [PHP] Sniping on the List

2011-11-20 Thread Geoff Shang

On Sun, 20 Nov 2011, Tedd Sperling wrote:

I appreciate your time and comments. However, you missed the point I was 
trying to make, which does not have anything to do with timezones. If 
you copy my code and place it on any server in the world, you'll observe 
the same results as I did.


NO I won't, and timezones do matter.

I've copied your code to http://quitelikely.com/~geoff/strtotime/

Sorry if any of the visuals are mangled, I had to massage the script a 
little to pullin the header and footer, and I downloaded your logo, but I 
didn't go and dig out your CSS or javascript.


This server is set to UTC and uses PHP 5.2.6.

Lets skip right to your point.


From your script on your server:


String Given: null

Seconds Computed from String: null

Date from Seconds Computed: 31 December, 1969 : Wednesday
___


From the script on my server:


   String Given: null

   Seconds Computed from String: null

   Date from Seconds Computed: 1 January, 1970 : Thursday
 __


You touched on my point with:

You'll also notice that the value of seconds computed from string is 
blank (i.e. not 0).  This is because strtotime() doesn't know what to 
do with a value of '0'.  Whether it should or not is probably a 
phillosophical debate.


But you did not contribute to which side of the debate would you side.


I didn't, because the debate was on whether or not NULL == Wednesday, not 
whether or not strtotime(0) should return 0.  I agree there's a good 
case for it doing so, you could file a bug if you feel strongly about it.


My prior opinion was that 0 should return 'Jan 1, 1970'. However, Stuart 
pointed out a flaw in my code.  You see, I was assuming that using the 
return from strtotime(0) in the getdate() function would return the 
correct date, but this was a cascade error.


As I think I mentioned before, using strtotime at all is the problem, as 
we are talking about null as a concept, not null the alphabetical 
string.  Since null is nominally a numerical value, we can pass it 
directly as a timestamp.


php -r 'echo date(r, null);'
Thu, 01 Jan 1970 00:00:00 +

Geoff.

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



Re: [PHP] Sniping on the List

2011-11-17 Thread Geoff Shang

On Thu, 17 Nov 2011, Tedd Sperling wrote:


On Nov 17, 2011, at 11:58 AM, Stuart Dallas wrote:

The epoch specifies the exact time that 0 represents. It makes no claims as far 
as that being the start of anything...

defined as the number of seconds elapsed since midnight Coordinated Universal Time 
(UTC) of Thursday, January 1, 1970 (Unix times are defined, but negative, before that 
date) [http://en.wikipedia.org/wiki/Unix_time]


Good reference to support your point, but strtotime() doesn't qork that way.


Yes it does.

$ php -r 'echo strtotime (31 Dec 1969 23:59 +);'
-60


For example, if you push '-1' though strtotime(-1), you'll get Wednesday only 
one day a week -- whereas 'null' works every time.

Technically I see that as a bug. I believe strtotime(null) should return null, 
but due to the way type inference works, null is interpreted as 0. The point 
here being that you're not getting the time at null, you're getting the time at 
0.



Nope, zero time is absolutely January 1, 1970 00:00:00 -- which was a 
Thursday. If you pass zero through strtotime(), it reports December 
1969 and I claim that to be a bug.


Not here it doesn't.

$ php -r 'echo date (r, strtotime (zero));'
Thu, 01 Jan 1970 00:00:00 +

But it might for you (see below).


In addition, passing -1 through strtotime() simply returns today,


Here it returns a time an hour later than now.

$ date -R; php -r 'echo date (r, strtotime (-1));'
Thu, 17 Nov 2011 20:41:06 +
Thu, 17 Nov 2011 21:41:07 +

whereas 'null' returns a date prior to the start of everything and that 
makes more logical sense to me.


but here we hit the crux of the problem.  'strtotime(null)' isn't 
returning a null timestamp, it's simply returning the value for an 
inability to convert the string null to a timestamp.


Of course, now that I try to reproduce the null == Wednesday result, I 
find that I can't.  Everything comes up as Thu, 01 Jan 1970 00:00:00 + 
which probably invalidates much of what I've written above.  Maybe I'm not 
running a new enough PHP (latest I have access to is 5.3.3).  But if this 
is the case, this suggests this behaviour changed relatively recently.


Anyway, as I was going to say, the correct way to find out what null is is 
to do something like:


echo date (r, null);

But this thread has gone through so many twists now that I can't remember 
if this is where we began or not.


Geoff.


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



Re: [PHP] Think I found a PHP bug

2011-11-16 Thread Geoff Shang

On Tue, 15 Nov 2011, Jim Lucas wrote:


Also, I recalled something from the early 5.1.0 version that was related to the
introduction of the date_timezone_set() function.  So, from there I searched
Google for php changelog and found the changelog for php v5.  Then I searched
that document for 'date_' and found that under the 5.1.0 they added the above
function.  How it is stated, it makes me think that PHP now requires you to call
this function prior to any use of other date functions.  I cannot find anything
in the php manual confirming my last statement.  YMMV


If you don't use date_default_timezone_set(), it's supposed to use the 
server timezone.  I recalled reading that a notice/warning would be logged 
if you did this, but like you, I can't find any reference to this now. 
I've searched my apache error logs and can't find anything there either, 
which seems to suggest that this in fact is not the case.


In case it wasn't obvious in my original post, this worked just fine 
during UK summer time.  It's only since the clocks changed two weeks ago 
that PHP has been thinking that the server timezone is UTC rather than 
Europe/London.


Geoff.


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



Re: [PHP] Think I found a PHP bug

2011-11-16 Thread Geoff Shang

On Wed, 15 Nov 2011, Tim Streater wrote:


I find I need to do this:

 date_default_timezone_set (@date_default_timezone_get ());

in all my scripts since 5.x.x to avoid rude messages.


Apart from the fact that I've not seen the rude messages of which you 
speak, even though I expected to, this won't help in this case. 
date_default_timezone_get() is returning the wrong timezone.


Geoff.


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



[PHP] Think I found a PHP bug

2011-11-15 Thread Geoff Shang

Hi,

A couple of weeks ago, I discovered what I'm pretty sure is a PHP bug. 
In addition, I looked in the PHP changelog and I haven't seen any mention 
of a fix for it.


I'm writing here because I was wondering if anyone else can confirm it and 
what to do about it.


The bug is that if a server's timezone is set to Europe/London and you 
don't set an explicit timezone in your script, if it's winter time in 
the UK, PHP thinks the timezone is UTC instead of Europe/London.


Example:

First, lets confirm that the system time is in fact set to Europe/London.

$ cmp --verbose /etc/localtime /usr/share/zoneinfo/Europe/London
$ echo $?
0

Now lets see what PHP thinks it is.

$ php -r 'echo date_default_timezone_get();'
UTC

What about if we set it in the environment?

$ export TZ=Europe/London
$ php -r 'echo date_default_timezone_get();'
Europe/London

OK, so we appear to have an issue.  But is this just semantics?  Well no. 
consider the following (with TZ once again unset):


$ php -r 'echo date (r, strtotime (1 July 2011 12:00 pm'
Fri, 01 Jul 2011 12:00:00 +

But of course, Europe/London isn't on + in July.

$ export TZ=Europe/London
$ php -r 'echo date (r, strtotime (1 July 2011 12:00 pm));'
Fri, 01 Jul 2011 12:00:00 +0100

The problem comes in when we view times created in one and printed in 
the other:


$ unset TZ
$ php -r 'echo strtotime (1 July 2011 12:00 pm);'
1309521600
$ export TZ=Europe/London
$ php -r 'echo date (r, 1309521600);'
Fri, 01 Jul 2011 13:00:00 +0100

And the opposite:

$ export TZ=Europe/London
$ php -r 'echo strtotime (1 July 2011 12:00 pm);'
1309518000
$ unset TZ
$ php -r 'echo date (r, 1309518000);'
Fri, 01 Jul 2011 11:00:00 +

This last one is what led me to discover this bug.  We use automation 
software to run our Internet radio station.  The playout system is written 
in C and the web front-end is written in PHP, with the data they work on 
the only point of commonality between them.  The station was set up during 
the European summer.  When the clocks changed, the playout system coped 
but the PHP front-end was showing everything an hour out.


Now of course, I personally can force the front-end to use Europe/London 
and it will work for me.  And I guess ultimately it would make sense to 
program the system to allow the user to specify a timezone rather than 
relying on the server default.  But right now it doesn't, and any solution 
would need to take the playout system into account.


At any rate, none of this is the point.  If you're using the system 
default timezone, you expect it to (a) be correct and (b) be consistant.


Note that this bug may affect other timezones which are on UTC durin the 
winter or summer, but I've not tested any other timezones as this would 
mean changing the system timezone and I'm not real keen on doing that on 
any of my systems.


This bug was found on a Debian Squeeze system running the following 
version of PHP:


PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 
08:24:40)

Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

I realise this is 5.3.3 and that 5.3.8 is now out.  It's possible that 
this has been fixed but I could not find any traces of such a fix in the 
changelogs.


I'd be interested to know if anyone else can confirm this bug and, if 
confirmed, what I should do about it.


Thanks,
Geoff.


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



Re: [PHP] question about best practice for coding sql statements

2011-11-12 Thread Geoff Shang

On Sat, 12 Nov 2011, tamouse mailing lists wrote:


I'm curious how others feel about this. When I'm creating an SQL
string, either for a non-prepared or prepared execution, I build it in
a variable and then pass the variable to the query or prepare
function. This lets me easily add something to view the SQL statement,
and also if there's an error, emit the SQL statement.


I do this.  This means that when a user encounters an error, they can 
actually give you a meaningful error report which should reduce the time 
it takes to fix it by a considerable amount.


Geoff.


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



Re: [PHP] Execute permission question

2011-10-28 Thread Geoff Shang

On Thu, 27 Oct 2011, Tedd Sperling wrote:

You answered a question I wasn't prepared to ask, which was How can php 
scripts be executed when their execute permissions aren't set?


Because as far as the system is concerned, the thing which is being 
executed is either PHP itself or something in which PHP is being run (e.g. 
Apache).  The fact that PHP then loads a script and executes it is not 
really the point.


When used in websites, it's the webserver itself which loads the PHP 
interpreter which in turn loads the script.


So the webserver needs to be executable.  The Apache module, for example, 
does not because Apache loads it into Apache which is already running.


If you're not actually running programs on the host itself via a shell, 
then you probably won't need execute permissions most of the time.


Geoff.

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



Re: [PHP] Variable question

2011-10-01 Thread Geoff Shang

On Sat, 1 Oct 2011, Mike Mackintosh wrote:

Best bet would to toss this into either an object or array for 
simplification, otherwise that type of syntax would need the use of 
eval.



example:  eval('echo $trivia_answer_'.$correct_answer.';');


You could do:

$var = trivia_answer_.$correct_answer;
echo $$var;

But I agree that an array would be simpler.


best bet would be to..

$trivia_answer = array();

$trivia_answer[1] = 1000;
$trivia_answer[2] = 1250;
$trivia_answer[3] = 2500;
$trivia_answer[4] = 5000;

echo $trivia_answer[$correct_answer];


You can define this a bit more simply:

$trivia_answer = array (
  1 = 1000,
  2 = 1250,
  3 = 2500,
  4 = 5000
);

You can do it even more simply by just giving the values, but indexes wil 
start at 0:


?php
$trivia_answer = array (1000, 1250, 2500, 5000);
print_r ($trivia_answer);
?

Array
(
[0] = 1000
[1] = 1250
[2] = 2500
[3] = 5000
)

While manually defining an array like this is only slightly less tedius 
than using 4 numbered variables, it's a lot easier to do if you're getting 
data from somewhere else (e.g. a database of trivia questions).  To use 
the original way proposed, you'd have to keep constructing variable names, 
which arrays avoid quite nicely.


In my opinion, the only real usefulness for a syntax like $$var (above) is 
if you want to do something with a bunch of variables in one go.  For 
example:


foreach (array (title, artist, album, label) as $field)
  echo ucwords($field) . ': ' . $$field . 'BR';

The above comes from a function which manages only a single record, so no 
real need to use an array.  I could of course, e.g. record['title'] etc, 
but I don't see much could be gained unless I needed to be able to manage 
an entire record as a single unit.


Geoff.

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



Re: [PHP] scroll down list -visible, but not possible to choose

2011-08-31 Thread Geoff Shang

On Wed, 31 Aug 2011, rob...@myself.com wrote:


I have the below function with array for satus of issues where I need to have 
'Resolved/Closed' visible but not available for choice
This as closing is a separate function to ensure correct resolution code is 
selected

Already tried removing 'Resolved', and got everything working only to notice 
when testing that when viewing issues the Resolved
ones showed up as 'Support Working' even though closed in the system


There are two possible points of failure here, your code and browser 
behaviour.  Whenever I'm faced with this sort of problem, I look at the 
source code in my browser to see the HTML my code generates.  Then I can 
determine if my code is outputting what I'd intended.  If it is, then my 
code is right but the implementation is wrong, as the correct HTML 
produces the incorrect result.


If you'd done this, you'd have seen what the problem is.  The problem is 
that, having taken away Resolved as a possible option, all items marked 
Resolved are unable to be listed as selected.  Consequently no items are 
selected and the browser defaults to the first item in the list which is 
Support Working.


I've never had to do this, but 
http://www.w3schools.com/TAGS/tag_option.asp says you can use the 
disabled attribute to disable an option.   So your resulting HTML could 
look like this:


option value=Resolved disabledResolved/option

or

option value=Resolved disabled selectedResolved/option

as appropriate.  A simple if statement could be used to set the disabled 
attribute for the Resolved selection only.


IMHO this is vastly preferable to any trickery you may use with javascript 
to prevent the user from selecting Resolved.


I've never struck a select field like this and am now interested in coding 
one up just to see how it works in practice.


HTH,
Geoff.

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



Re: [PHP] Code should be selv-maintaining!

2011-08-29 Thread Geoff Shang

On Mon, 29 Aug 2011, Rico Secada wrote:


You go into your homemade library of code to re-use some piece that you
already are using 12 other places in production. Now, last time you
worked on the code you thought it was almost perfect. While working on
the code this time you find an undiscovered bug or some part of the
code that looks like you where on drugs when you made it.


This is why it's good to write this kind of thing as functions.  Then if 
you find some great problem with it later, you can drop in the replacement 
functions and the code that calls it (hopefully) won't need modification.


Of course, it's easier to be cleverer after the event.

Geoff.


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



Re: [PHP] Dreaded Premature end of script headers

2011-08-26 Thread Geoff Shang

On Fri, 26 Aug 2011, tamouse mailing lists wrote:


The log says what I said: Premature end of script headers filename


I put this into Google and got this: 
http://htmlfixit.com/cgi-tutes/tutorial_Common_Web_dev_error_messages_and_what_they_mean.php#premature


As I understand it, the webserver is complaining that it did not get all 
the headers it expected from the script before it terminated.


Given that you say this is for a cron job, the script may well be doing 
exactly what you want it to do, but it's not outputting anything which is 
why you get an error.


Presumably, you are calling this cron job with some process which runs the 
PHP script through a URL on your webserver.


To fix this, I'd suggest one of the following.  Either:

1.  Modify the script so that it does actually output something, thereby 
making the error go away.


or

2.  Run the script directly with PHP instead of via your webserver.  E.g.: 
php -f yourscriptname


IMHO, 2 would be the better way to go if you can do this.

HTH,
Geoff.


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



[PHP] Using stand-alone PHP scripts with Drupal

2011-08-24 Thread Geoff Shang

Hi,

I know this is probably more a Drupal question, but I'm guessing some here 
have probably had to deal with this.


I've written some PHP code which works just fine on its own.  Now someone 
wants to include it in their Drupal site, with the regular headers and 
footers for their site surrounding the output from my scripts.


Is there an easy way to include the PHP in a page on their site?

Not sure which version of Drupal they're running, trying to find out.

Geoff.


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



Re: [PHP] Login with Remember me Feature

2011-08-14 Thread Geoff Shang
 the admin area.br /*
*?php header(Location: index_admin.php); ?/div*
*?php*
*}*
* if($usr_level == newbie)*
*{*
*?*
*div class=messageYou have successfuly been logged in. You can now
access to the newbie area.br /*
*?php header(Location: index_newbe.php); ?/div*
*?php*
*}*
* if($usr_level == advanced)*
*{*
*?*
*div class=messageYou have successfuly been logged in. You can now
access the advanced area.br /*
*?php header(Location: index_advanced.php); ?/div*
*?php*
*}*
* *
*}*
*
*
*? *


There's a lot to say about this.

First and foremost, as mentioned by someone else, you can't send location 
headers once output has begun.  Moreover, there's no guarantee that the 
user's browser will display any messages contained in the page body, even 
if therre are any.


This is easy to get around, however, by using a page refresh.  This is 
demonstrated below.


Second, I'm assuming you've set up the various access levels as defined 
constants.  If you haven't, the above code isn't going to work.  I'm going 
to assume you have, but you've not shown us this.  You've also not shown 
us how $usr_level gets its value.


Third, you don't seem to have set up your HTML page.  I'm guessing that 
you've not actually done this and you need to.


Finaly, my belief is that if you need to cut and paste code, you're doing 
it wrong.  Instead of having all these separate tests and HTML blocks, we 
could do this much more simply with a switch statement and a couple of 
variables.


Note: I see you've used newbe in your newbie page redirect, instead of 
newbie.  I'm going to assume this was deliberate.  If not, you can get 
rid of $page_suffix entirely and just use $access_name instead.


Given all the above, here's how I'd rewrite this code:

 switch ($usr_level)
 {
  case admin:
   $access_name = admin;
   $page_suffix = admin;
   break;
  case newbie:
   $access_name = newbie;
   $page_suffix = newbe;
   break;
  case advanced:
   $access_name = advanced;
   $page_suffix = advanced;
   break;
 } // end switch on $usr_level
?

html
head
titleRedirecting.../title
meta http-equiv=REFRESH content=10;url=http://?php echo 
$_SERVER[HTTP_HOST] . /index_$page_suffix.html?

/head

body
div class=messageYou have successfully been logged in. You can now
access the ?php echo $access_name ? area.br //div
/body
/html

?php
 } // end if logged in
?

The above also assumes your index_* files are in the webroot, you can edit 
the refresh line if this is wrong.


HTH,
Geoff.


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



[PHP] Closing PHP tag best practice?

2011-07-24 Thread Geoff Lane
Hi All,

While watching one of Jeffrey Way's CodeIgniter tutorials, I was
gobsmacked when he noted that it was best practice not to have closing
PHP tags as closing tags might introduce whitespace issues. So I tried
syntax checking a few simple pages and, to my surprise, the syntax
checkers accepted the pages even though the closing ? was missing.

However, I suspect that there may be issues with this. For example,
what happens if you include or require something that has no closing
PHP tag? For example, consider two files:

File: test_inner.php 8--
?php
  echo This is the inner code\n;
---8

File: test_outer.php 8--
htmlhead/headbody
?php
  include ('test_inner.php');
  echo This is the outer code\n;
?
/body/html
---8

I thought that there might be an issue with the parser attemting to
parse the closing body and html tags as PHP, so I ran a check on one
of my development machines with the above files and there was no
error. It seems that, on my development machine at least, a PHP code
block can be closed either explicitly (with '?') or implicitly by the
EOF! However, experience has shown me that what works on one server
might not work on all of them as there are so many configuration
options and so many versions of PHP 'in the wild'.

So, is Jeffrey correct when he says that omitting the closing PHP tag
is best practice? Also, are there any 'gotchas' to doing this?

TIA,

-- 
Geoff


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



[PHP] Re: Escaping '

2011-07-22 Thread Geoff Lane
On Friday, July 22, 2011, Floyd Resler wrote:

 I did a fresh install of PHP on a new server.  I had gotten used to
 PHP automatically adding a backslash before single quotes when form
 data is submitted.  It seems that is shut off in my new install.
 How do I turn it back on?

Check the manual for 'Magic Quotes GPC':
http://php.net/manual/en/security.magicquotes.php

However, you may want to rething enabling this as it's deprecated and
judging by the discussions I've seen it will be removed in the not too
distant future.

HTH,

-- 
Geoff


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



Re: [PHP] using wget in shell for download(snort)

2011-07-10 Thread Geoff Shang

On Sun, 10 Jul 2011, Tamara Temple wrote:


On Jul 10, 2011, at 5:38 AM, Negin Nickparsa wrote:


I want to make a batch file and then exec it in php
I have a problem in batch file
wget have been installed in Yast I want to download a RuleFile from
snort.org

I used this on shell:

$ wget
http://www.snort.org/reg-rules/snortrules-snapshot-2900.tar.gz/c0e9480af637e53c7aae823a40a131edc1343db5\-O
snortrules-snapshot-2900.tar.gz

that string is an oinkcode from the site

this commandline has error and I don't know why


What is the error?

This: b5\-O at the end of URL looks suspicious.


That's the problem.  The \ should be a space.

Geoff.


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



Re: [PHP] What type of PHP5 shall I install to learn PHP5 together with Apache, Please specify the Apache type too Since There are Two Apache types also

2011-07-08 Thread Geoff Shang

On Fri, 8 Jul 2011, Varuna Seneviratna wrote:


I am Using Ubuntu 11.04 Desktop as my OS.Below are the two types of
PHP5 available for installation

php5 - server-side, HTML-embedded scripting language (metapackage)
php5-cgi - server-side, HTML-embedded scripting language (CGI binary)

I got the above by running the command apt-cache search PHP5
1 What is the difference between the two.


One is part of the other.

I'm running Debian (which Ubuntu is based on), and by looking at the php5 
package you can see that it depends on php5-cgi and a few other packages.



2 What shall I install to learn PHP with apache(Please specify the
apache version too since there are two types available for Ubuntu)


Can't really help you much there without more information, though again 
assuming the Debian packages are the same or similar, installing the 
apache2 package should pull in everything you need.


HTH,
Geoff.


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



[PHP] Re: Constants in strings

2011-07-06 Thread Geoff Lane
On Wednesday, July 6, 2011, Dave Wilson wrote:

 OK. We all know that constants cannot be accessed directly via their
 name in double-quoted or heredoc strings.

FWIW, this looked like it might be a right royal PITA for me ATM.
However, I've got a work-around.

With about a dozen scripts written using 'heredoc', I discover the
need to include extra information for which I required a constant. The
answer for me was to initialize a variable to have the same value as
the constant and to use that in the heredoc string. e.g:

define ('KONST', 100);

$konst = KONST;
echo END
Some sample text in which we need $konst
END;

A similar approach is to declare a 'pseudo-constant' variable instead
of defining the constant (e.g. $konst=100 instead of the first two
lines of code in the above sample).

HTH,

-- 
Geoff


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



Re: [PHP] I want to use POST when redirect via PHP Header function.

2011-06-30 Thread Geoff Lane
 On Thursday, June 30, 2011, Md Ashickur Rahman Noor wrote:

 I want to use POST when redirect via PHP Header function. Is it
 possible?

AFAICT, it isn't. You can use GET variables by passing them on the
querystring. These can then be accessed via $_REQUEST, which is an
amalgamation of $_POST, $_GET, and $_COOKIE. So if you have a script
that might take input from either $_POST or $_GET, you can usually
code fairly transparently by replacing both by $_REQUEST.

Alternatively, you can create a form on the page and use client-side
javascript to 'auto-submit' via the body onLoad event. However, this
does require JS on the client and so cannot be guaranteed.

HTH,

-- 
Geoff


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



[PHP] Re: I want to use POST when redirect via PHP Header function.

2011-06-30 Thread Geoff Lane
On Thursday, June 30, 2011, Jasper Mulder wrote:

 Personally, I think that incorrect spelling is far more annoying
 than the quoting; that is, if it does not originate from
 incapability due to English (whether it be British or American)
 being not the native language, as opposed to spelling errors because
 of vapidity.

Personally, I'm not sure that those who are lifeless, dull, or
unintersting are any more or less prone to spelling errors than the
rest of us; or that the more interesting members of this list are
immune!

 As for the readers of this list, I am sorry to go into this non-PHP subject, 
 but I couldn't really let this pass.

Au contraire! Typos are very much a PHP subject. Take this from
someone who spent nearly two hours yesterday debuggin PHP code with
imbalanced parentheses, parentheses that should have been braces - and
vice versa, ampersands in place of dollar signs, and other typos!

I think the moral is that one should never code when tired ;(

-- 
Geoff


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



Re: [PHP] Time zones are spinning my brain

2011-06-29 Thread Geoff Shang

On Wed, 29 Jun 2011, Brian Dunning wrote:


$start = gmdate('Y-m-d\TH:i:s.00\Z', strtotime(yesterday 00:00:00));
$end = gmdate('Y-m-d\TH:i:s.00\Z', strtotime(yesterday 23:59:59));


I think this is right, since it's 7 hours off California time, but I 
just need someone to double check my spinning head. Will this give me 
the PayPal transactions that arrived during California's yesterday, or 
do I need to change something?


Assuming your timezone is set to California time ( 
date_default_timezone_set ('America/Los_Angeles') ), then yes.


Geoff.


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



Re: [PHP] Time zones are spinning my brain

2011-06-29 Thread Geoff Shang

On Wed, 29 Jun 2011, Richard Quadling wrote:


And UTC is not the same as GMT. Ish.

GMT is only valid for 6 months of the year. Then, due to DST, it becomes BST.

UTC is just UTC.


This is incorrect.  For all practical purposes, GMT and UTC are the same. 
The fact that the time in Greenwich is not GMT/UTC for half the year is 
not relevant.


http://www.diffen.com/difference/GMT_vs_UTC

All the GM* functions (gmdate, gmstrftime, etc) are intended for dealing 
with Universal Co-ordinated Time.


As a side note, there is (or at least was) no gmstrtotime function.  I get 
around this by putting  + at the end of the string.


HTH,
Geoff.


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



Re: [PHP] Time zones are spinning my brain

2011-06-29 Thread Geoff Shang

On Wed, 29 Jun 2011, Brian Dunning wrote:

Thanks everyone. It seems to be working correctly. You gave me some 
extra peace of mind. I did set the 
date_default_timezone_set('America/Los_Angeles') but it looks like that 
was in the defaults anyway.  :-)


It probably is if this is where your site is hosted.  But all you need to 
do is change hosting providers to one somewhere else, or for someone who's 
not careful to mess something up on the system, and the script will break 
all because you assumed it would always be right.  So better to set it and 
know it's right.


Geoff.


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



[PHP] Re: URL Rewriting

2011-06-23 Thread Geoff Lane
On Thursday, June 23, 2011, Ashley Sheridan wrote:

 I've not yet seen any evidence yet that pretty URLs actually benefit
 SEO. I regularly search for answers to problems online, and mostly I
 get forums as the results, all of which have URLs like
 showthread.php?t=1234567

Anecdotal perhaps, but I see the opposite. Most of what I see 'above
the cut-line' in search results doesn't have a querystring and the
forums at the top of the list mostly seem to be rewritten. For
example, in a recent search on Google.co.uk for pusher aircraft, the
first page except for the last result were all 'SEO-friendly' URLs.
The last but one returned result was an obviously rewritten forum post
http://www.theaerodrome.com/forum/2001/11195-pusher-aircraft.html The
first returned result with a querystring was a YouTube video.

I also tried searching for something about which I'm fairly confident
that the majority of information 'out there' is contained in forum
posts and although the second result on the first page was a forum
post, all but three on the first two pages had no querystring.

That said, the reason I use rewriting is because it makes site
maintenance much easier for me rather than because of any SEO benefit
- real or imagined.

-- 
Geoff


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



[PHP] Re: URL Rewriting

2011-06-22 Thread Geoff Lane
On Wednesday, June 22, 2011, Daniel Brown wrote:

 RewriteEngine on RewriteRule ^theme([0-9]+).php$
  /index.php?theme=$1 [L]

 That's neither nginx nor PHP, so it's not really relevant to the
 OP's questions.

I guess that the answer should be that you can rewrite outside of PHP
and then make use of the rewrites within your PHP application.
However, you can't AFAICT rewrite within PHP itself.

FWIW, I'm using mod-rewrite in one of my applications. In my .htaccess
file, I have:

8---
RewriteEngine On
RewriteRule ^/$ master.php?url=index.html [L]
RewriteRule ^(.+\.html)$ master.php?url=$1 [QSA,L]
8---

So that all .html files get rewritten to master.php with the
originally requested file on the querystring. In master.php, I then
have something like:

  $content = str_replace(.html, , $_GET['url']) . .php;
  require ('header.php');
  if (file_exists($content)){
include ($content);
  }
  require ('footer.php');

This lets me have all the common content in required files with the
content that is unique to each page defined separately and without
needing to embed the top-level page structure in each page. It also
gives me 'search-engine-friendly' URIs.

HTH,

-- 
Geoff


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



[PHP] Re: Submit Using An Image Form Processing

2011-06-18 Thread Geoff Lane
On Saturday, June 18, 2011, Ron Piggott wrote:

 I am not getting anything.  Is there a correct way of passing a
 variable through an image?  The value in this above example is the
 auto_increment value of the product.  From this I could remove the
 item from the shopping cart.

An image causes two variables (name_x and name_y) to be set where
these give the coordinates of the point on the image where the user
clicked. So, the corresponding x and y $_GET or $_POST variables will
be set and using your example, if you had:

form action='adjust_cart.php' method='post'
INPUT TYPE=image 
SRC=http://www.theverseoftheday.info/store-images/trash_can.png;
  WIDTH=20  HEIGHT=20 style=float: right;border:0;
  alt=Remove Product From Shopping Cart name=remove_product /
/form

Then in the called script, you could use:

if (isset($_POST['remove_product_x'])){
  // do stuff to remove product from cart
}

HTH,

-- 
Geoff


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



[PHP] Re: What do you get for ...

2011-06-07 Thread Geoff Lane
On Tuesday, June 7, 2011, Richard Quadling wrote:

 What do you get for ...

 php -r var_dump(realpath(null));

PHP 5.3.5-1ubuntu7.2 on Ubuntu 11.04 kernel 2.6.18 returns the same
value as __DIR__

However, PHP 5.1.6 on CentOS 5.6 kernel 2.6.18 returns bool(false).
Doing php -r var_dump(__DIR__); on this machine shows that __DIR__
is undefined. Executing both commands in an intranet-visible, php
script shows the same thing.

HTH,

-- 
Geoff


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



[PHP] Re: What do you get for ...

2011-06-07 Thread Geoff Lane
On Tuesday, June 7, 2011, Richard Quadling wrote:

 But the surprising issue is that your 5.1.6 returns bool(false). So
 far, that's the only report I've got that shows inconsistent
 behaviour for PHP5+

I too was surprised, which is why I took the time to report. AFAICT,
I've got the standard LAMP stack for CentOS 5.6 from the time I
developed the first application on it. The output from
print_r($_SERVER) contains the expected script-related paths and I
don't get issues running PHP scripts on this server either via Apache
or via cron (as shell scripts).

If specific output from this server would help, I may be able to give
this to you off-list.

HTH,

-- 
Geoff


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



Re: Re: [PHP] phpsadness - P.C. shmee seee.

2011-06-05 Thread Geoff Shang

On Sun, 5 Jun 2011, Tim Streater wrote:


Anyone whose site says that sort of crap needs a good smack.


Don't get me started on Facebook.  If they don't like your browser, they 
redirect you to theirWe don't support your browser page.  They don't 
even let you try with your unsupported browser, which might well work if 
you're clicking on a link to a particular status update.


Geoff.


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



Re: [PHP] Re: phpsadness - P.C. shmee seee.

2011-06-05 Thread Geoff Shang

On Sun, 5 Jun 2011, Richard Riley wrote:


Why do you feel FB should support some antiquated browser that doesnt
support any of the newer technoogies which enable security and more
advanced client side rendering?


I don't.  I just don't want them to lock out my browser just because they 
don't support it.  Many pages which don't work optimally under Lynx can 
still be read, which is all I'm wanting to do anyway.


I can use the mobile site fine, but if someone posts a link to a status 
message or some other item on Facebook, it's to the main site and not the 
mobile one.  I don't even bother clicking because I know Facebook won't 
even try to send me the page I want.


Geoff.


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



Re: [PHP] Re: phpsadness - P.C. shmee seee.

2011-06-05 Thread Geoff Shang

On Sun, 5 Jun 2011, Richard Riley wrote:


I don't.  I just don't want them to lock out my browser just because they don't
support it.  Many pages which don't work optimally under Lynx can still be read,
which is all I'm wanting to do anyway.


They need to or there can be unintentional side affects that will
reflect badly on them and possibly you.


Rubbish.  All they need to do is what everyone else does and say This 
site may not work well on your browser, we recommend using Internet 
Explorer or firefox (or whatever they support).  Then if I choose to use 
it, it's on my own head, which is fine by me.



If you really want a half arsed user experience then set your browser
string ;) Would that not work for you?


It probably would.  But this tangent began with the principle of Use IE 
or Firefox and how we hated sites that said that.  It's the principle of 
the thing.


Geoff.


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



Re: [PHP] Re: phpsadness - P.C. shmee seee.

2011-06-05 Thread Geoff Shang

On Sun, 5 Jun 2011, Richard Riley wrote:


If they allowed incompatible browsers that caused havoc then before you
know it the great unwashed would be demanding more and better support or
complaining about lack of functionality. Doing what they do they make it
very clear from day one.


This would be a fair enough attitude if they only applied it to their 
member sections, but they don't.  They set themselves up as publishers of 
information, page hosts of sorts, then don't let anyone in who wants to 
*read* them.



Dont like it? The APIs are open. Write your own interfaces to their
authentication and graph API and target the parts that wont result in
your accuont being banned for chucking access tokens around and breaking
their security model.


Totally not the point.  Quite aside from the fact that Mobile Facebook 
works extremely well with Lynx, and so did Facebook Lite until they sadly 
took it away, it's not what I'm having trouble with.


An example of what I'm talking about is the following tweet:

ABCGrandStand: #nrl : NSW ORIGIN team game two.. Dugan, Hayne, Hopoate,
Gasnier, Uate, Soward, Pearce, Gallen, Ennis, Mannah,...
http://fb.me/uPHxKiFC

http://twitter.com/abcgrandstand/status/77271757383413760

Now, correct me if I'm wrong, but there's no need to log in or anything 
remotely 21st-century required to read the rest of this post.  All you 
need to do is click the URL and the appropriate Facebook status will come 
up, which you're free to read without any further clicking on your part.


But only if you're using a browser that's been blessed by the Facebook 
gods.  If you're not, you're sent to 
http://www.facebook.com/common/browser.php with no other course of action.


I hope you can appreciate my point.  The choice to use Facebook was a 
decision made by the person sending the tweet, not me.  It's not going to 
kill them to either let me see the page with appropriate functionality 
warnings, or to flick-pass me to the equivalent mobile Facebook page.  I 
can't view it on the mobile site myself without first resolving where the 
shortened URL points to, changing the www to m and hoping it works, or 
signing in and trying to find it myself.


Even Twitter, who don't let me login to the regular site without 
javascript, are quite happy to let me view tweets unauthenticated on their 
site with Lynx.  If I want to login, I need to use their mobile site.  Not 
a problem - if I try to use their main site and it doesn't work, it 
doesn't work.  At least they let me try.


Geoff.


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



Re: [PHP] Re: [PHP-WEBMASTER] encoding issue

2011-06-02 Thread Geoff Shang

On Thu, 2 Jun 2011, Richard Quadling wrote:


There are other possibilities, but they could have legal repercussions
- essentially reversing the encoding may be considered as an attempt
to bypass a copyright protection system which could contravene the
http://en.wikipedia.org/wiki/Digital_Millennium_Copyright_Act.


Note that the DMCA is United States legislation and may not be relevant. 
Copyright law is pretty universal though and you could get into trouble 
with this anyway.


Geoff.


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



Re: [PHP] smart auto download file

2011-05-31 Thread Geoff Shang

On Wed, 1 Jun 2011, Ali Asghar Toraby Parizy wrote:


I need to tell something to the user before starting download.
something like Your download will begin in a moment... . So header
couldn't help me. If I try to echo anything header doesn't work!


Couldn't you just do an HTML redirect?

  !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN
  html
  head
  titleFile Download/title
  meta http-equiv=REFRESH
  content=10;url=http://www.example.net/download;/HEAD

  BODY
  PYour download will start in a few seconds./P

  PIf your download fails to start automatically,
  A HREF=http://www.example.net/download;click here/A./P
  /BODY
  /HTML

Of course, this is the resulting HTML you want to produce (or something 
like it).  You'll obviously get PHP to echo the appropriate URL.


This approach has the benefit that it'll work on anything.  My prefered 
browser does not support javascript, so you look me out of your site if 
you use it.


Geoff.


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



Re: [PHP] iPhone sadness

2011-05-30 Thread Geoff Shang

On Mon, 30 May 2011, Andre Polykanine wrote:


most  of  you  post your messages *after* the quotes. It's
really  not  comfortable: I use screenreading software here and I need
to scroll with my down arrow key before I see the actual message.


I use screen reading software as well and prefer bottom-posting.  Of 
course, those who quote an entire message (or messages) before their post 
should be shot, but thankfully this is a minority of people.


Since we're all pitching in with our arguments for top/bottom posting, 
I'll briefly state mine:


1.  Bottom (or at least not top) posting allows you to interleave your 
responses amongst the quoted text.  This makes it a lot easier to know 
what is being responded to, and actually also makes it a lot more likely 
that all points that need answers will actually be answered.


2.  Particularly if #1 is followed, quoted material more often than not 
tends to be trimmed to what is relevant.  Top-posting not only usually 
results in the entire message being quoted, but often the entire thread 
right back to the beginning (or at least back to whoever bottom-posted 
last on it).  This can cause very large messages fairly quickly, 
especially if combined with HTML mail (don't get me started on *that* 
one).


Unfortunately, Outlook Express (and perhaps others) seem to actively 
discourage doing the right thing.  One reason is that at least in Outlook 
Express, it's impossible to set different quoting settings for replies and 
forwards.  So you either end up with forwards with all quoted lines (very 
annoying to listen to I assure you), or replies where it's impossible to 
tell what's quoting and what's new text (unless you're sending as HTML 
mail of course).


And of course, the single reason (IMHO) why it's likely more people 
top-post - it's less work.


Geoff.


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



Re: [PHP] iPhone sadness

2011-05-29 Thread Geoff Shang

On Sun, 29 May 2011, Richard Quadling wrote:


On 29 May 2011 01:36, TR Shaw ts...@oitc.com wrote:

(sorry for the top posting)

Sent from my iPad



Are you telling me that you can't scroll down the page on an iPad?

I refer back to my comment that the Sent from my iPad/iPhone is
inherently an apology.


Ironicly, it's on by default.  It can be turned off, however.

Geoff.


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



Re: [PHP] Detecting HTTPS connections under Apache

2011-05-28 Thread Geoff Shang

On Fri, 27 May 2011, Curtis Maurand wrote:


$_SERVER['HTTPS']


I don't see this at all.

I'm definitely connecting securely.  Here are the status lines from Lynx 
when surfing to https://MintFM.net/phpinfo.php:


1. Looking up mintfm.net
2. Making HTTPS connection to mintfm.net
3. Verified connection to mintfm.net (cert=mintfm.net)
4. Certificate issued by: /C=FR/O=GANDI SAS/CN=Gandi Standard SSL CA
5. Secure 128-bit TLS1.0 (DHE_RSA_AES_128_CBC_SHA1) HTTP connection
6. Sending HTTP request.
7. HTTP request sent; waiting for response.
8. HTTP/1.1 200 OK
9. Data transfer complete

So it's definitely secure, but I'm not seeing anything in $_SERVER that 
says so.  So I'm wondering if Apache is not exporting something properly.


Geoff.


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



RE: [PHP] Detecting HTTPS connections under Apache

2011-05-27 Thread Geoff Shang

On Thu, 26 May 2011, ad...@buskirkgraphics.com wrote:


So when you echo $_SERVER['SERVER_PORT'];
You get port 80 even if the url currently is https://www.yoursite.com ?


Yes.


If this is the case good luck. Because you have serious issues.


OK.  This on its own is not particularly helpful.  Surely I can't be the 
only person in the universe who has experienced this.  I'm running a 
minimally-altered stock Debian Apache and PHP setup.


Geoff.


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



[PHP] Detecting HTTPS connections under Apache

2011-05-26 Thread Geoff Shang

Hi,

Apologies if this is covered somewhere but I've searched fairly 
extensively and not found anything.


I'm working on an application which has a function for redirecting to a 
given URL.  This is generally used for redirecting after a form has been 
submitted.


Right now it sends an HTTP URL in the redirection, which means it can't 
work under a secure connection.


I'd like to be able to use it over HTTPS but don't want to force people to 
do this.   So ideally I'd like to be able to detect the protocol in use 
and send the appropriate protocol in the Location header.


The problem is that, at least on the system I'm working on, I can't see 
any way of detecting the protocol.  _SERVER[SERVER_SIGNATURE] and 
_SERVER[SERVER_ADDR] both give the port as 80, even if I specify port 
443 in the URL.  I've seen references to _SERVER[HTTPS] or something 
similar but it's not in the output I get from either print_r ($_SERVER) 
or phpinfo ().


I'm running PHP Version 5.3.3-7+squeeze1 on Apache/2.2.16 (Debian).  The 
machine is an x86-64 VPS running Debian Squeeze.


I have full access to the VPS, so if something needs tweeking in Apache 
(or anything else) then I can do this.


Thanks in advance,
Geoff.


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



RE: [PHP] Detecting HTTPS connections under Apache

2011-05-26 Thread Geoff Shang

On Thu, 26 May 2011, ad...@buskirkgraphics.com wrote:


The %{HTTPS} variable is not an Apache core variable. A more-portable
solution is to check %{SERVER_PORT} for port 80 or port 443 -- or for not
port 80 or not port 443.


ah but this doesn't actually work for me, I get 80 regardless of whether I 
use HTTP or HTTPS, even if I use https://example.com:443



Also, you're requiring an *exact* match on not /user or not /admin,
meaning that directory and file paths below these directories will not be
matched -- They will always be redirected by the second rule.


{snip other rewrite stuff}

uh... I didn't say anything about matching URL patterns or the like.  I 
just want my application to do whatever is already being done.  And 
hard-coding URL paths is a bad idea because someone else might want to 
install the code under some other path.


I don't really want to use rewrite rules to achieve this.  If I did, every 
time my code redirects the browser, it will cause a rewrite from an HTTP 
URL to an HTTPS URL, which surely is inefficient.


Surely it should be simple enough for me to detect whichever is being used 
and continue to use it.  This makes my code separate from whatever the 
webmaster decides to do regarding being secure or not.


Geoff.


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



[PHP] Re: Date validation

2011-05-21 Thread Geoff Lane
I'm posting here for completeness as I've now rolled my own date
validator (code follows my sig). It allows almost all valid 'English'
formats except ordinal day values (1st, 3rd, etc.) Because I'm in UK
and writing for a UK audience, I've parsed ambiguous dates as d/m/y.
Those writing for places where m/d/y is the convention will probably
want to alter the tests in the second if ... elseif construct. It's a
bit long-winded, but by all means use or modify if it's any use to
you.

Best regards,

Geoff

---8--

function is_date ($str){
$dateOK = TRUE;
if (stristr($str, /)){
$aryDate = explode (/, $str);
} elseif (stristr($str, -)){
$aryDate = explode (-, $str);
} elseif (stristr($str,  )){
$aryDate = explode ( , $str);
} else {
$dateOK = FALSE;
}
if (count($aryDate) != 3){
// we don't have the correct number of date parts
$dateOK = FALSE;
}
if ($dateOK) {
// trim any leading or trailing whitespace
for ($i = 0; $i  count($aryDate); $i++){
$aryDate[$i] = trim($aryDate[$i]);
}
// determine which value is month and which is day
if (!is_numeric($aryDate[0])){
$month = $aryDate[0];
$day = $aryDate[1];
} elseif (!is_numeric($aryDate[1])){
$day = $aryDate[0];
$month = $aryDate[1];
} elseif ($aryDate[1] = 12){
$day = $aryDate[0];
$month = $aryDate[1];
} else {
$month = $aryDate[0];
$day = $aryDate[1];
}
$year = $aryDate[2];
// Expand 2-digit years to 4 digits. Cut-off is current year + 10.
if (strlen($year) != 4){
$now = date('y') + 10;
$year = $year - $now  0 ? '20' . $year : '19' . $year;
// check for correct year length
if (strlen($year) != 4){
// we didn't start with two digits
$dateOK = FALSE;
}
}
// Convert month names to month numbers
if (!is_numeric($month)){
$aryMonth = array('nowt', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 
'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
$month = strtolower(substr($month, 0, 3));
foreach ($aryMonth AS $key = $value){
if ($value == $month){
$month = $key;
}
}
}
$dateOK = $dateOK  checkdate($month, $day, $year);
}
return ($dateOK);
}


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



[PHP] Date validation

2011-05-20 Thread Geoff Lane
Hi All,

I'm scratching my head trying to remember how I validated string
representation of dates 'the first time around' with PHP (before going
over to ASP/VBScript for almost a decade). I have a feeling that I
must have rolled my own validation function, because I can't find
anything other than strtotime() and checkdate() in PHP itself.

Although checkdate() seems fine, strtotime() appears to be 'broken'.
It seems where possible to return a timestamp that makes some sense
rather than return FALSE when handed an invalid date. For example,
strtotime('30 Feb 1999') returns 920332800, which is equivalent to
strtotime('02 Mar 1999'). When I ask a user to enter a date and they
make a typo, forget that September only has 30 days, etc., I want to
be able to detect the problem rather than post a date in the following
month!

It also seems that where the DateTime class uses string representation
of dates, times, or intervals that these must be 'in a format accepted
by strtotime()'; which implies that 'under the hood' strtotime() is
used to convert the string to a date/time value, which implies that
the Date/Time class cannot properly handle string input values.

This seems to be such a common requirement that I suspect I've missed
something basic. I'd thus be grateful for any pointers as to how to
properly validate user-input string representation of dates.

Cheers,

-- 
Geoff Lane


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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
 On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using this:

 $date = DateTime::createFromFormat(Y-m-d, 2011-05-20);

Hi João, and thanks for your help.

FWIW, I thought about that but it didn't work for me. On further
investigation, I'm now completely confused and suspect I've got a duff
PHP installation. Thankfully, it's a virtual machine so it should be
reasonable easy to 'vapourise' and start over (perhaps with CentOS
rather than Ubuntu as the OS).

Anyway, the following code produces the following result when the
variable $str = '7 feb 2010':

[code]
  echo pDate is $str/p\n;
  $date = DateTime::createFromFormat('d M Y', $str);
  echo pre;
  print_r($date);
  echo /pre\n;
  echo date('d M Y') . br / . date('d M Y', $date);
[/code]

[result]
  pDate is 7 feb 2010/p
  preDateTime Object
  (
  [date] = 2010-02-07 15:11:34
  [timezone_type] = 3
  [timezone] = Europe/London
  )
  /pre
  20 May 2011br /
[/result]

This is pretty much as expected except that the second call to date()
- i.e. date('d M Y', $date) - outputs nothing.

Also, AFAICT createFromFormat fails if the date is not formatted
according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
fails ... (at least, it does on my system :( )

-- 
Geoff


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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
 On Friday, May 20, 2011, Peter Lind wrote:

 This is pretty much as expected except that the second call to
 date() - i.e. date('d M Y', $date) - outputs nothing.

 date() takes an int as second parameter - a timestamp. Not an object.
 And from a quick test it doesn't look like DateTime has a __toString
 method.

Thanks - my misunderstanding. I'll have to look into that further.

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


 I'm sorry for asking but what did you expect?? You're specifically
 calling a method that parses a string according to a given format. If
 it parsed the string according to any other format, that would be a
 huge WTF.

Don't feel sorry to have asked, because it's exactly what I expected.
João suggested using createFromFormat. Since I need to validate dates
input in any valid form, I felt it wouldn't work and my comment was to
João to that effect. That said, I've seen some weird and unexpected
results from my development server recently (e.g. my post of 16 May re
weird cookie behaviour) which was why I added the proviso (at least,
it does on my system) just in case that method wasn't meant to behave
as I inferred.

With all that said, I still have no 'out of the box' method to
validate a user-input date string and I haven't been able to find the
code I used with PHP 3.something before my sojourn into the depths of
ASP to know how I used to do this!

-- 
Geoff


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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
On Friday, May 20, 2011, Peter Lind wrote:

 Try:

 $date = new DateTime($date_string_to_validate);
 echo $date-format('Y-m-d');

Many thanks. Unfortunately, as I mentioned in my OP, the DateTime
class seems to be 'broken' for my purposes because it uses strtotime()
to convert input strings to date/time. Rather than fail when presented
with an invalid date, strtotime() returns the 'best fit' if possible.
This can be seen from:

$date = new DateTime('30 Feb 1999');
echo $date-format('Y-m-d');

which results in 1999-03-02 even though 30 Feb is an invalid date.

-- 
Geoff


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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using regular expression to validate so using DateTime
 object to  parse it if it?s a valid date?

Again, thanks.

For info, I only need to know that it's a valid representation of a
date on this occasion as I intend to use the MySQL CAST function to do
the actual conversion within the INSERT or UPDATE SQL statement that
commits the value to the underlying database.

I strongly suspect that you're correct in that I should be able to use
a regexp to do the validation. This could well be the catalyst that
gets my sleeves rolled up, a large pot of strong, black coffee on the
hob, and me finally trying that little bit harder to get my head
around regular expressions!

I was hoping that PHP would have an equivalent to VBScript's IsDate()
function but it looks like I'll have to roll my own!

Thanks again,

-- 
Geoff


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



[PHP] Wierd cookie behaviour

2011-05-16 Thread Geoff Lane
Hi All,

I'm scratching my head a bit here. I have a form handling script that
branches dependent on whether a user has admin privileges over the
application. Here's the function that tests this:

function isAdmin($user){
global $chan;
$query = SELECT isadmin FROM csw_user WHERE username = ' . 
mysql_real_escape_string($user) . ';
// echo p$query/p\n;
$result_table = mysql_query ($query, $chan) or die (Error: Can't retrieve 
the data);
if ($result_row = mysql_fetch_array ($result_table)){
$canAdminister = $result_row['isadmin']  0;
} else {
$canAdminister = FALSE;
}
return ($canAdminister);
}

Note the commented echoing of the query, which I uncommented during
debugging.

This function was failing with the message from die() Error: Can't
retrieve the data. On uncommenting the echo statement, I got:

SELECT isadmin FROM csw_user WHERE username = ''

IOW, there was a blank string passed to the isAdmin function.

So I checked at a higher level and temporarily modified the code to
read:

echo pre;
print_r ($_COOKIE);
echo /pre\n;
$canAdministrate = isAdmin($_COOKIE['username']);

This showed that $_COOKIE['username'] contained the username of the
logged-on user as I expected, yet that username was not passed to the
isAdmin function 8-/

FWIW, I've resolved the issue in that it no longer happens. I'd
forgotten to put the opening and closing html, head, and body tags and
the issue went away as soon as I did that. However, I'd appreciate
info on why as I need to run some scripts within a validated user
session where those scripts do their processing and then use the
header function to redirect the browser to an appropriate page.

TIA,

-- 
Geoff


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



Re: [PHP] dynamic copyright in page footer?

2011-04-30 Thread Geoff Lane
On Saturday, April 30, 2011, Simon J Welsh wrote:

 I would use something simple like:
 if(date('Y') == '2011') {
 echo '2011';
 } else {
 echo '2011-', date('Y');
 }

... or in one line:

echo (date('Y') != '2011' ? '2011-' : '') . date('Y');

However, you might want to change that to:

echo '2011-' . date('Y');

at the first review after the start of 2012!

HTH,

-- 
Geoff


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



[PHP] Re: PHP delete confirmation

2011-04-29 Thread Geoff Lane
On Friday, April 29, 2011, ad...@buskirkgraphics.com wrote:

 Personally I would use the javascript page navigation is senseless if they
 miss click.
 
 Javascript: Small and simple javascript.

 onclick=return confirm('Are you sure you want to delete?')

Personally, I'd use Javascript and also check that the form was
submitted after the client-side check. So something like a hidden
field ('jstest') in the client-side form that is set to 1 by the
onClick event prior to showing the confirmation box. Then in the
handling PHP:

if ($_POST['jstest'] == 1){
  // the client called us via Javascript::confirm, so we know the
  // use really wants to delete
} else {
  // We weren't called via Javascript::confirm, so we need to
  // handle the confirmation in PHP
}

HTH,

-- 
Geoff


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



Re: [PHP] Javascript detection

2011-04-28 Thread Geoff Lane
 On Thursday, April 28, 2011, tedd wrote:
 
 To answer your question in a new thread.

 No, the $_SERVER super-global isn't going to give you anything nor is 
 anything else like it.

 You see, PHP has a difficult time detecting IF Javascript is turned 
 ON in the client's browser because PHP is history by the time the 
 browser does anything, including running Javascript.

Thanks, Tedd. That's how I suspected things to be. However, the list
was very quiet, I might have missed something, and so I felt it
couldn't hurt to ask. TBH I'd already done:

 echo pre;
 print_r ($_SERVER);
 echo /pre;

and didn't spot anything there that I thought would give me the info I
sought - but then I don't know the purpose of every element of that
array and $_SERVER is not the only superglobal!

 As Yogi Berra once said; It's always hard to predict things 
 especially when it deals with the future.

However, once the browser has requested a transfer via HTTP that
request is in the past and that request is where stuff that lets you
know some of the browser's capabilities (e.g. HTTP_ACCEPT) comes from.
So it would be possible by a similar mechanism for a browser to tell
your script whether or not Javascript (or any other language for that)
is available.

 However, there are two ways to kind-of doing it:

 Way 1 --  I place an element in html that is hidden from the user's 
 view via css (display:none) and if Javascript is ON then Javascript 
 changes the css so that the element is shown to the user 
 (display:block). Here's an example:

This is the reverse of part of what I've done for the page in
question. I had a tabbed interface similar to:

div id=sect01 style=display:block;
[stuff]
/div
div id=sect02 style=display:none;visibility:hidden;
[stuff]
/div
...

However, the second div must be visible if JS isn't available
otherwise the user can't access that section. So I've changed the
style of the second and subsequent divs to display:block and then used
an onLoad routine to change the .style.display and .style.visibility
attributes of the second and subsequent divs to none and hidden
respectively so that those who have JS get the full DHTML.

Now I also using AJAX on that page. However, I can use the fact that
the trigger events aren't handled if JS isn't available to just
retrieve what's actually needed at the time via AJAX if JS is
available or submit the full form if it's not. Of course, that
complicates things in the PHP on the server as the script then has to
handle both interim and final form submission.

FWIW, it's possible to detect whether or not Javascript is available,
but not AFAICT at 'first contact' because you need the 'first contact'
page to do something to prove that JS is available, from which you can
assume that JS is not should that something not be done. For example,
you can make the link to a page into a form submission - e.g:

  form name='jstest' action='myscript.php' method='post'
  input type='hidden' name='wehavejs' value=1
  /form
  a href='myscript.php' 
onClick=document.forms['jstest'].submit();return(false);
  Click Here/a

The form is submitted if the browser has JS and so the hidden input
field is posted. However, if the browser doesn't have JS the default
behaviour occurs when the link is clicked and so the field is not
posted. Hence we can use isset($_POST['wehavejs']) to determine
whether or not the browser has JS capability.

Thanks again,

-- 
Geoff


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



Re: [PHP] Destroying cookies... not working

2011-04-28 Thread Geoff Lane
On Thursday, April 28, 2011, Sean Greenslade wrote:

 On Wed, Apr 27, 2011 at 8:52 PM, Rick Dwyer rpdw...@earthlink.net
 wrote:

 The following did the trick... is there any reason I should not use it?

 $name=mysession;
 setcookie($name);

  --Rick


 Only if you're OCD, since the cookie is still technically there, just empty.
 Without setting the expire arg, the browser will keep it until closed.

What happens if you then use isset($_COOKIE['mysession'])? TBH, I
don't know and don't have the time to experiment just now. However,
this should return false if the cookie has been destroyed but if just
set to null or an empty string via Rick's code I suspect it'd return
true.

-- 
Geoff


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



Re: [PHP] Javascript detection

2011-04-28 Thread Geoff Lane
On Thursday, April 28, 2011, Ashley Sheridan wrote:

 I'm not sure if my earlier reply got through, but here it is again (or
 at least the general gist of it)

Many thanks. I got your info the first time around but didn't respond
directly to you as Tedd made similar comments and I'd responded to his
post.

 Like everyone has mentioned thus far, it's better to use progressive
 enhancement or try to avoid relying on Javascript at all. Even a website
 as complex as Facebook allows users to go on it without needing a
 browser that runs Javascript. Something as complex as Google Docs has a
 very clear need for Javascript though, so you wouldn't expect that to
 work without it.

In my case, one of the controls I'm considering is a tiled map with up
to 16 tiles. This is on a page with four tabbed sections that takes
several seconds to load at broadband speeds. Also, the nature of the
site means that people may need to access it and use this form while
connected via mobile broadband or even GSM; connection media that are
usually both slow and paid for per unit of data transfer. I need to
record in hidden input fields the location of where a user clicks on
the map and also echo that click back in the form of a marker overlaid
on the clicked tile. Using AJAX, I can update just the two fields plus
one image. Without Javascript, the extra bandwidth needed to
unnecessarily download the entire page multiple times will cost my
users both time and money. So while I must ensure the site works
without Javascript, I really need the optimisation that JS brings.

 Lastly, if you're creating the website for a government or business, you
 really need to make it work without Javascript, as a lot of countries
 make it illegal to discriminate against a disability, which you would be
 doing if you made a site that was unusable without Javascript. After
 all, there are many speech and Braille browsers out there that can't
 take advantage of Javascript, and a lot of Javascript apps which require
 mouse interaction to run (mouseover/hover events, etc)

AIUI, a lot of countries (mine included) make it unlawful to knowingly
discriminate against the disabled. However, The Disability
Discrimination Act requires only that reasonable steps be taken to
avoid discrimination ... and making stuff accessible to the disabled
at considerable inconvenience and/or expense to everyone else is not
considered reasonable. Now where I can, I'll produce stuff that is
enhanced by images, colour, JS etc. but will still be usable in Lynx.
However, some stuff (e.g. mapping) won't work without graphics and so
is inherently unavailable to the visually impaired. It makes no sense
whatever to try to make such content work in speech and Braille
browsers. Thus making a site that's unusable without Javascript
doesn't necessarily constitute unlawful discrimination!

-- 
Geoff


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



Re: [PHP] Re: What's faster using if else or arrays?

2011-04-28 Thread Geoff Lane
On Thursday, April 28, 2011, Jim Giner wrote:

 Arrays - using a  silly construct that probably still takes as much
 time to  evaluate machine-wise as anything else.  And as far as
 readability goes, it  is even sillier.   IMO.

I don't know so much about that ...

I'll use a global array to define an application-wide set and then use
in_array to branch dependent on whether some variable has a value that
is or is not a member of that set. Using a series of predicates in a
multiple OR, or using switch is a non-started for me for maintenance
reasons, and the alternative of storing the set of values in a
database is a lot slower. Here's an example:

FWIW, I've got a mapping application. Users can click on a map tile to
indicate a point of interest. However, they can also click on zoom
buttons, or pan buttons. These buttons are named 'plus', 'minus',
'left', 'right', 'up', and 'down' and I have these names in an
application-wide array:

$controls = array ('plus', 'minus', 'left', 'right', 'up', 'down');

The way that these map view controls are handled is very different to
the way a click on a map tile is handled. Somehow, the code is more
readable with:

if (in_array($clicked, $controls)){
 // ...
}

than with:

if ($clicked == 'plus' || $clicked == 'minus' || $clicked == 'left' || $clicked 
== 'right' || $clicked == 'up' || $clicked == 'down'){
 // ...
}

Even using switch isn't as clear IMO as that can intersperse the
options with several lines of code, which can make the logic harder to
spot.

However, the real benefit of using an array comes in making the code
easier to maintain. Drawing my map is a library routine, as is the
handler for the controls. However, the handling of clicks on map tiles
is different for each of the eight or nine contexts in which the
mapping is used. So the best way IMO of coding this is to test in each
page which element has been clicked and to either call a library
routine or a context-specific handler from there.

Now say, for example, that I want to augment the zoom functionality by
having a 'slider' that permits the user to go directly to a desired
zoom level. I can redefine the set of controls by simply changing the
global array. However, using the long if construct mandates that I
must amend the code of every page that uses the mapping, which makes
for a lot of extra work and is just plain silly IMO. IOW, using an
array can help avoid coding inconsistencies.

-- 
Geoff


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



[PHP] Detecting Javascript (was Re: Newsgroup status)

2011-04-27 Thread Geoff Lane
 On Wednesday, April 27, 2011, Ashley Sheridan wrote:

 Firstly, please do not hijack a thread, if you have a question, start
 your own. We won't bite if you create new threads, whereas we might a
 little if you hijack ;)

Ouch! My apologies - Hijacking was not intended and I've changed the
subject to reflect that this is a distinct 'branch'.

 There are ways to detect the general capabilities of the client machine,
 however they are generalisations, and may not be accurate. Try and grab
 an up-to-date browscap.ini file, and use this in conjunction with the
 user agent string found in the $_SERVER array. This should tell you
 whether the user agent is capable of running Javascript.

Thanks for your reply. As you wrote, identifying the 'alleged' user
agent in that way is not accurate. For example, I run Opera with JS
disabled to check what my work looks like without JS and I know some
who run without JS for security reasons.

My immediate concern is a large form where two data entry fields are
implemented as image maps. The easiest way of presenting this to the
user is as a DHTML tabbed page with AJAX to store x/y locations of the
image map clicks in hidden fields.

However, the page still has to work without JS. So my thought was that
if I could detect whether JS is available at the client, I could serve
different content dependent on JS status. AFAICT, there's nothing that
lets me know 'at first hit' although for pages that aren't directly
accessed (e.g. stuff for which you need to log in each session), it's
possible to use Javascript to write a hidden field. When the user logs
in, this is used to detect that JS is available and to set a session
cookie that you can use on subsequent pages to determine that JS is
there.

That said, I've done some sideways thinking. If JS is not available
then client-side scripts don't run. Clicking image maps or submit
buttons produce the default behaviour and onClick, onChange etc.
events aren't triggered. So I've laid out the page for no JS and then
used an onLoad function to hide the appropriate content. I've also
coded the form handling PHP script to refresh the form with the
appropriate values if one of the image maps is clicked. That way, the
onClick etc. events can be used to trigger AJAX if JS is available and
make an 'interim form submission' if it's not.

However, it would be so much simpler if I could tell straight off and
for sure whether JS was available; but if this isn't possible I guess
it'll be a limitation of HTTP rather than PHP.

Thanks again,

Geoff


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



Re: [PHP] Last Name extraction in query

2011-04-04 Thread Geoff Lane
 On Monday, April 4, 2011, Jim Giner wrote:

 Actually - I can't seem to find a mysql newsgroup anywhere.  The
 ones that  come up in google search are all dead and buried.

You could try http://forums.mysql.com/ or have a look around Yahoo
groups (e.g. php_my...@yahoogroups.com).

HTH,

-- 
Geoff


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



[PHP] Re: is there any syntax to save a file in mysql?

2011-03-28 Thread Geoff Lane
On Monday, March 28, 2011, Negin Nickparsa wrote:

 ... i want every user to have his/her own files in their account. (i
 used session for them) n now i want them to have their specific
 files then i think i must have db that store the files n user can
 retrieve his/hers not just details if i just save the details then
 how they download the files that they receive from another users?

One way is to create a directory for each user in which you store than
user's files. You can name each directory for the user's ID.

That strategy lets more than one user have the same filename, although
it doesn't let one user have more than one file with the same name
(which might be required for a CMS etc.)

Others can download files by clicking on hyperlinks to the target
files.

HTH,

-- 
Geoff


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



[PHP] Re: opening a new window from php script

2011-03-25 Thread Geoff Lane
On Friday, March 25, 2011, Grega Leskovšek wrote:

 Do I have to use target=_new - I can not do this - I am working
 this for my University seminar and it has to be valid HTML5.

I guess that this is an HTML issue rather than PHP. However:

Despite what the W3C validator might claim, I understand that the
target attribute of the anchor tag is still valid in HTML5. In any
case, HTML5 is a draft standard AFAICT, and so I have to question a
university's insistence on adhering to a 'moving target'.

http://www.w3.org/TR/2011/WD-html5-20110113/links.html#attr-hyperlink-target
should give you some ammunition to demonstrate to your tutor that
a href=somewhere.html target=_blank is valid. Quoting from
that W3C document:

  The target attribute, if present, must be a valid browsing context
  name or keyword. It gives the name of the browsing context that will
  be used. User agents use this name when following hyperlinks.

They also say:

  A valid browsing context name or keyword is any string that is
  either a valid browsing context name or that is an ASCII
  case-insensitive match for one of: _blank, _self, _parent, or _top.

FWIW, the 'target' attribute has been removed from 'link' elements,
which many have apparently wrongly taken to mean it's been removed
from hyperlinks (i.e. anchor tags). However, link and a are not
the same thing! An example of each:

  link rel=stylesheet type=text/css href=styles.css /
  a href=someplace.html target=_blankclick here/a

HTH,

-- 
Geoff


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



[PHP] Re: echo?

2011-03-23 Thread Geoff Lane
Hi Jim,

On Wednesday, March 23, 2011, 1:42:18 AM, you wrote:

 ok - here's the code in question.
 $q = 'select * from director_records ';
 $qrslt = mysql_query($q);
 $rows = mysql_num_rows($qrslt);
 for ($i=0; $i$rows; $i++)
 {
 $j = $i+1;
 $row = mysql_fetch_array($qrslt);
 echo $j.'-'.$row['userid'];
 if ($row['user_priv'] )
 echo ' ('.$row['user_priv'].')#13#10';
 else
 echo '#13#10';
 }


 The output I get is:


 1-smith5
 f-ginerjm (M)
 g-smith8

 While the alpha parts are valid, the index is only correct for the first one 
 (0) obviously.


I couldn't understand why you're getting characters, so I thought I'd
have a go myself. First, some DDL and DML to recreate your data:

  create table director_records (userid char(16), user_priv char(8));
  insert into director_records (userid, user_priv) values ('smith5', 
''),('ginerjm','M'),('smith8','');

Now when I ran your code I got:

1-smith5#13#102-ginerjm (M)#13#103-smith8#13#10

That is, all but the first result has #10x in front of it. These are
HTML entities that display as characters and it so happens that #102
is 'j' and #103 is 'g'. Strictly, these entities should be terminated
with a semi-colon (i.e. #102; and #103;), but your browser is
'obligingly' making sense of the 'bad formatting' and  this is why
you're getting characters.

BTW, an alternative to your for construct would be to use a while loop
to iterate through a data table. e.g. in your case, I'd have used:

  $q = 'select * from director_records ';
  $qrslt = mysql_query($q);
  $i = 1;
  while ($row = mysql_fetch_array($qrslt)){
  echo $i++ . '-' . $row['userid'];
  if ($row['user_priv']){
  echo  ( . $row['user_priv'] . );
  }
  echo br\n;
  }

HTH,

-- 
Geoff Lane
Cornwall, UK
ge...@gjctech.co.uk


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



[PHP] Re: $_POST variable

2011-03-11 Thread Geoff Lane
Hi Danny,

On Friday, March 11, 2011, 7:28:10 PM, you wrote:

 I have a form that has a long list of radio-bottons inside of it. The
 radio-buttons are dynamically created via php and MySQL.

 Here is an example of one of the radio buttons:

 input type=radio name=?php print (radio_.$result_from_mysql) ; ? 
 value=0
 input type=radio name=?php print (radio_.$result_from_mysql) ; ? 
 value=1

 Now, when I submit this form to another page for processing, how would I 
 catch
 the above radio-button's $_POST name since I do not know the name, only that 
 it

You could use foreach to iterate through the post variables until you
encounter a match:

foreach ($_POST as $key = $value){
if (substr($key, 0, 6) == radio_) {
   $buttonName = $key;
   $buttonValue = 4value;
   break 2;
}
}

I haven't tried the above code, but I hope someone will correct my
efforts if I'm wrong.

-- 
Geoff Lane
Cornwall, UK


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



Re: [PHP] Re: Which CAPTCHA is the besta?

2007-08-17 Thread Geoff Nicol
There are several PHP Captcha classes available as well.

A few examples are:
http://www.white-hat-web-design.co.uk/articles/php-captcha.php
http://milki.erphesfurt.de/captcha/
http://nogajski.de/horst/php/captcha/


Re: [PHP] Regular Expression just one step away from what I need....

2007-08-17 Thread Geoff Nicol
I am no regex expert but wouldn't
preg_match_all( /'([^']+)'/Ui, $theString, $matches);

Be more flexible?

On 8/17/07, Thijs Lensselink [EMAIL PROTECTED] wrote:


 If it's only real words this will do:

 $theString = 'foo''bar''glorp';
 preg_match_all( /'([a-z]+)'/Ui, $theString, $matches);

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




Re: [PHP] manual vs. meta refresh

2007-08-11 Thread Geoff Nicol
And if they do a manual refresh on the page you re-directed to, the
was_meta_refresh_before flag will be set.
How will you tell it from a meta-refresh redirect?

You need to use a cookie or session id. Regardless, by reading the whole
thread and 'cheating off the other students' this has been pretty beat to
death.

On 8/11/07, Richard Lynch [EMAIL PROTECTED] wrote:

 On Fri, August 10, 2007 6:51 pm, Geoff Nicol wrote:
  That was my first thought as well but you will still have to use a
  session
  variable or cookie for the page following redirect to know it was a
  meta-refresh.

 No.

 For the page following, you can use some other GET parameter, such as
 was_meta_refresh_before

 So long as you are not using the same GET parameter, you can bounce
 back and forth all day.

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?




Re: [PHP] manual vs. meta refresh

2007-08-11 Thread Geoff Nicol
Rob,

What you suggested, which matches the theory of what I and others suggested,
would certainly work as an ID that changes is involved.

If you read the specific posting by Richard Lynch, which is what I was
replying to, you will note he suggest refreshing to a static
'was_meta_refresh_before' link which of course won't work as refreshing
manually at that point will be indistinguishable from a true meta-refresh
after the redirect has occurred.

Anyways; this thread seems done, there are several solid suggestions on how
to do it properly.

I just didn't want it to close on an incomplete solution, as people
apparently don't read the thread history ;)

-Geoff

On 8/11/07, Robert Cummings [EMAIL PROTECTED] wrote:

 On Sat, 2007-08-11 at 18:26 -0700, Geoff Nicol wrote:
  And if they do a manual refresh on the page you re-directed to, the
  was_meta_refresh_before flag will be set.
  How will you tell it from a meta-refresh redirect?

 I already explained this in previous email. Go read the history of this
 thread.

 Cheers,
 Rob.
 --
 ...
 SwarmBuy.com - http://www.swarmbuy.com

 Leveraging the buying power of the masses!
 ...



Re: [PHP] audio recorder

2007-07-30 Thread Geoff Nicol
A service called AudioGenerator provides an online recording capability like
you are describing via Flash.

Their flash app is at:
http://upload.audiogenerator.com/audio_recorder.swf

Normally called with the code:

object classid=clsid:d27cdb6e-ae6d-11cf-96b8-44455354
codebase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0;
id=video_recorder viewastext= align=middle height=300
width=215
param name=allowScriptAccess value=sameDomain
param name=movie value=audio_recorder.swf
param name=FlashVars
value=imefajl=1055s4dfsd45amp;w=newrecordbymicrophone2.aspamp;popup=
param name=menu value=false
param name=quality value=high
param name=bgcolor value=#CC

/object


I don't know if this is a custom component they created or a purchasable
one. I provide the above link and info only as an example of one approach;
kindly confirm all proper licensing requirements prior to making any use of
this applet.

If you do find a solution with a viable license kindly update me (or the
list) as I too would be interested in this.

-Geoff

On 7/30/07, M. Sokolewicz [EMAIL PROTECTED] wrote:

 Tijnema wrote:
  On 7/31/07, John Pillion [EMAIL PROTECTED] wrote:
  Not exactly a php question. but I'm doing the project in php, so does
 that
  count? ;-)
 
 
 
  A client of mine wants a simple audio recorder for users to record a
 short
  clip/message for other users. anyone recommend any simple audio
 recorder
  applets or similar that can easily be integrated with php?
 
 
  Thanks!
 
 
  J
 
  How do you want to implement it? Where is the microphone connected?
  Server? Client? or is it a Stand Alone app (CLI)?
 
  If it's connected to the client PC (which I'm guessing), then you
  can't use PHP for recording it, it needs to be done in a client side
  language, and if you don't want the client to download an application,
  you have a few options, but there's only one I can recommend, and that
  is java. But really, you're not on the right list for that ;)
 
  If it's connected to the server, or if it's an Stand Alone app, then I
  would recommend you looking for some software that does record from
  the microphone, and use it through system, exec, ``, ... functions.
 
 
  Tijnema
 

 You could also implement it using Shockwave Flash, no idea how though,
 as I've never bothered looking into that stuff.

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




Re: [PHP] Beware of OS X PHP security update...

2006-03-03 Thread Geoff Martin


On 03/03/2006, at 11:15 PM, Marcus Bointon wrote:

The OS X security update issued yesterday includes a PHP 'fix', by  
which they mean that it installs PHP 4.4.1. If you have installed  
PHP 5 from elsewhere, it will get trashed along with your PEAR  
setup. PEAR is now completely confused or me and just crashes when  
I try to do anything.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



I installed the update successfully, no effect on PHP 5.

Perhaps you need to look elsewhere

Geoff

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



Re: [PHP] PHP mysql data result set compression

2006-02-06 Thread Geoff
On 6 Feb 2006 at 16:03, David Yee wrote:

 Hi all- is there a way have a large data result set from MySQL compressed?
 E.g. I have a table with over a million rows of data that I want to do a
 select * from  on and then take that result, do some field/data
 manpulation, and then insert row-by-row to another table.  The problem is
 the result of the query is so big that it's casuing PHP to swap to disk,
 causing things to slow to a crawl.  Doing a show processlist on the mysql
 console shows that Writing to net is the state of the running select *
 from  query.  I tried adding the flag MYSQL_CLIENT_COMPRESS to both
 mysql_pconnect() and mysql_connect() but it doesn't seem to do any
 compression (I can tell by the size of the running php memory process).  Any
 ideas would be appreciated- thanks.

You could try using the LIMIT keyword with an offset number to get 
records in more manageble chunks, then write out each chunk, freeing 
its resources before loading the next one.   

Geoff.  

 
 David
 
 -- 
 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] automating creation of thumbnails

2006-01-26 Thread Geoff
I remember the other day someone was asking for a way to easily 
create a bunch of thumbnails from image files. I just spotted this:
http://www.phpclasses.org/browse/package/2846.html

This is a simple class that can be used to generate thumbnails of 
image files. It can resize the images so they do not exceed a given 
width or height. The images are loaded as true color to preserve the 
quality as much as possible during the rescale operation. Currently, 
the images can be loaded and saved in the JPEG and GIF formats.

Geoff.

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



Re: [PHP] absolute vs relative path?

2006-01-25 Thread Geoff
On 25 Jan 2006 at 15:19, William Stokes wrote:

 Hello,
 
 I Have a web site on one server and a test site on another. How can I build 
 the hyperlinks so that they work on both servers without modification.
 
 For example build this link dynamically:
 http://www.domain.com/www/test.php
 
 In test server the same should be:
 http://internalserver/www/test.php

Non-php solution:

Use relative links. Instead of referring to a page as 
http://www.domain.com/www/test.php;, rather just use 
/www/test.php or even just /test.php, if the script containing 
that link is already in /www. Thus your links will look the same on 
both versions.

php-based solution:

If you must have absolute URLs (maybe to do redirects or SSL) use:
$_SERVER[SERVER_NAME]
it will return either www.domain.com or internalserver. So you 
can build your links as:

?php
$url = 'http://' . $_SERVER[SERVER_NAME] . '/www/test.php';
?

Geoff.

 
 Thanks
 -Will 
 
 -- 
 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



Re: [PHP] absolute vs relative path?

2006-01-25 Thread Geoff


On 25 Jan 2006 at 15:22, Barry wrote:

 Geoff wrote:
  On 25 Jan 2006 at 15:19, William Stokes wrote:
  
  
 Hello,
 
 I Have a web site on one server and a test site on another. How can I build 
 the hyperlinks so that they work on both servers without modification.
 
 For example build this link dynamically:
 http://www.domain.com/www/test.php
 
 In test server the same should be:
 http://internalserver/www/test.php
  
  
  Non-php solution:
  
  Use relative links. Instead of referring to a page as 
  http://www.domain.com/www/test.php;, rather just use 
  /www/test.php or even just /test.php, if the script containing 
  that link is already in /www. Thus your links will look the same on 
  both versions.
 
 /test.php would refer to root.
 so it would be www.domain.com/test.php
 not www.domain.com/www/test.php (!)
 
 probably a small typo ;)

Oops, twas indeed. Well spotted :-

 
 Barry
 
 -- 
 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] POP3 or other servers in php

2006-01-23 Thread Geoff
I'm looking a POP3/IMAP server written in PHP. Or failing that, any 
socket-based sever would help me by being an example I could base my 
own on.

I know there are a million functions, routines and classes for 
talking to POP3/IMAP servers. That is not what I need. I need an 
actual service (or example of one) in PHP, one that listens on a 
port and handles multiple incoming connections. What 'nixers would 
call a daemon.

I've done some RTFM and found quite a lot of interesting stuff in 
the manual and manual comments of the Socket Functions section. 
What I'm now seeking is real-world examples.

Many thanks,

Geoff.

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



Re: [PHP] Can PHP works with telnet?

2006-01-22 Thread Geoff
In the php manual, in the fsockopen() page, in the user comments, I 
found this:

--
Found this php class to use telnet from here:
http://cvs.adfinis.ch/cvs.php/phpStreamcast/telnet.class.php
There's no docs and a lot of it's in french though so maybe it will 
help someone to have my working code. This code is used to telnet 
into a pix and execute the shun command.


//---telnet.class.php usage example-
   $telnet = new telnet;
// Next line is for logging.  
//By default you need to create a folder called /log and give it 
//the rights your webserver is running.
   $telnet-setLog(1,mylog);
   $telnet-set_host(myhost.myplace.com);
//You need to set the prompt to what you know its going to be,
//then call wait_prompt...which waits for what you just set
   $telnet-set_prompt(Password: );
   $telnet-connect();
   $telnet-wait_prompt();
   $telnet-write(mypassword);
//Have to change the prompt...in my example this is the 
//prompt that a pix will change to after loggin in.
   $telnet-set_prompt(pix );
   $telnet-wait_prompt();
   $telnet-write(en);
   $telnet-set_prompt(Password: );
   $telnet-wait_prompt();
   $telnet-write(enable_password);
//When you go into enable mode in a pix the prompt changes
   $telnet-set_prompt(pix# );
   $telnet-wait_prompt();
   $telnet-write(shun  . $shun_address);
   $telnet-wait_prompt();
   $telnet-write(clear xlate);
   $telnet-wait_prompt();
   $telnet-write(write mem);
   $telnet-wait_prompt();
   $telnet-write(exit);
   $telnet-disconnect();

--

In that same manual page, there is lots of other information and 
suggestions on making telnet connections.

Note that cURL will also allow telnet.

Geoff.


On 23 Jan 2006 at 9:56, HoWang Wang wrote:

 Hi all,
 
 Recently I got a job to write a PHP webpage to display some infomation
 which have to obtain from telnet. Telnet is the only way to query the
 software. I have made a quick search on php.net but I can't found amy
 extension support telnet. Is there any way to do so? Or it is impossible
 with PHP but can be done with external binaries?
 Please help, thanks.
 
 HoWang Wong
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 !DSPAM:43d445e0116957800291649!
 

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



Re: [PHP] Determining number of days in a selected month

2006-01-21 Thread Geoff
Apart from using date(t, $month) you can also determine the last 
day of a month by getting the 0th day of the following month.

Say I wanted to know the last day in Feb 2006:
$mnth = 2;
echo date(d,mktime(13,0,0,$mnth + 1, 0, 2006));

This is sometimes useful when you are calculating, or your code 
needs to walk up or down dates.

P.S. You may wonder why I specify 1pm as the time on the given day. 
If I don't (if I use 0) this is the same as saying midnight, in 
which case it is right at the very end of the day. This way I avoid 
daylight saving and/or minor hour/min/sec differences that might 
push the timestamp over into the next day. A small thing, but since 
I deploy code in a number of places, it has saved me countless 
headaches.

Geoff.


On 20 Jan 2006 at 13:51, Jeffrey Pearson wrote:

 The java mailing list I belong to recently had this same  
 conversation. I didn't know php had that ability built in. Java  
 doesn't (score another one for php). The cleanest solution I saw on  
 the Java list that would be non-language specific (in other words,  
 the same logic can be implemented in ANY language) would be to set a  
 variable to the first day of the month AHEAD of the month you want.  
 For example, if your looking for February, 2000, set the variable to  
 be March 1st, 2000. Then subtract 1 day. I have actually archived  
 this solution in my own little knowledge base as I thought it was  
 quite clever.
 
 
 Hope this helps other people as well.
 
 
 Jeff Pearson
 
 
 
 
 
 
 
 
 On Jan 20, 2006, at 8:17 AM, [EMAIL PROTECTED] tg- 
 [EMAIL PROTECTED] wrote:
 
  date(t) will give you the number of days in the current month.
 
  Or you can do:
 
  date(t, mktime(0, 0, 0, $month, $day, $year))
 
 
  to get the number of days in a specific month in a specific year  
  (that way you can get leap year accurate counts..)
 
  -TG
 
  = = = Original message = = =
 
  Is there a way to easily tell PHP how many days there are in a  
  selected
  month without writing the following out for each month:
 
  if($Month == January)
  ~$NumberOfDays = 31;
 
  elseif($Month == February)
  ~if($Year == A Leap Year)
  ~~$NumberOfDays = 29;
  ~
  ~elseif($Year != A Leap Year)
  ~~$NumberOfDays = 28;
  ~
 
  elseif($Month == March)
  ~$NumberOfDays = 31;
 
  and so on, and so on, and so on
 
  I would greatly appreciate any help.  Thanks.
 
 
 
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
  ___
  Sent by ePrompter, the premier email notification software.
  Free download at http://www.ePrompter.com.
 
  -- 
  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
 
 
 
 !DSPAM:43d1ab1b244201588548228!
 

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



[PHP] anyone know a good php proxy

2006-01-21 Thread Geoff
Hi all,

Does anyone know of (or have sample code for) a decent PHP proxy? 
All I need to do fetch webpages from a remote site, replace certain 
trigger text, then return them to the browser.

However, the user's browser must only be aware of my proxy page - it 
shouldn't know where the pages are coming from.

Thanks in advance,

Geoff.

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



[PHP] inserting text into a mime message

2006-01-19 Thread Geoff
Hi All,

I've been searching the archives for help on this, but have come up 
empty-handed. Here's the thing:

I'm using a PHP script to parse every message coming through a 
mailserver. The server invokes my script for each message, giving it 
a filename containing the full raw text of the email. The script 
needs to modify the raw message file, inserting a footer (some 
trailing text, eg: a disclaimer) at the end of each part of readable 
message. It doesn't touch file attachments, but it needs to insert 
the footer in any plaintext, HTML text or both (if they exist).

There are so many different mime options and encoding types that it 
seemed like re-inventing the wheel to try working with only the raw 
message text, so instead I decided to use the PEAR Mail_mimeDecode 
module, which returns a very nice object array of all the parts, 
decoded and ready for use.

It's no problem going through this and inserting the footer wherever 
it is needed. That much I've done.

My problem is trying to rebuild that object array (the output of the 
Mail_mimeDecode::decode() function) back into its raw form once 
again, so that I can write the modified raw text back to the message 
file and the email can go on its way.

Another complication is that except for the insertion of the footer, 
I cannot modify the original message. All the headers, dates, 
receive-paths, etc, must remain unchanged.

Has anybody ever done anything like this before - re-encoding a 
message that had been decoded by Mail_mimeDecode::decode()? I've 
looked at the encode() function, but it seems to be used for making 
a simple message from scratch (with just one body part), it is not 
really the opposite of decode(). [I may be wrong about this - there 
are no examples in the PEAR manual].

I'm not hung up about what to use, it doesn't have to be PEAR, I 
will use any library or code that will do the job. Alternatively, if 
it is possible to do this with encode(), I would love to see an 
example, as I couldn't get it to work that way myself.

Many thanks.

Geoff.


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



Re: [PHP] Grouping

2006-01-19 Thread Geoff
Sound like a straightforward control-break (at least, that's what 
they used to call it in the COBOL days :-)  

assuming you're getting data into an assoc array called $records, 
you could stick this into your loop:  

{
$letter = $records['LastName']{0};
if ($prev != $letter) {
print(br$letter$sep);
$prev = $letter;
}
print($records['LastName'] . br);
}

If you want to keep it neat, you can put it in a function, using a 
static var to keep hold of $prev. It can return an empty string when 
there is no change, or the delimiter if the letter has changed.  

Geoff.


On 19 Jan 2006 at 10:19, Jeffrey Pearson wrote:

 OK. I know I did this a LONG time ago but I don't remember how I did  
 it. Thus, my post.
 
 I have a list of last names from a MySQL database. I need to display  
 them grouped by the first letter of their last names and insert a  
 separator on display. Similar to a phone book. So it looks like;
 
 
 A
 ___
 Adams
 Apple
 Army
 
 B
 __
 Banjo
 Bank
 Bark
 
 C
 __
 Captain
 Car
 
 
 
 Is there a way without jumping through too many hoops?
 
 Thanks for any input you can give.
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 !DSPAM:43cfe677219529533614314!
 

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



Re: [PHP] URL - stream context

2006-01-19 Thread Geoff
3 suggestions:

I honestly have no idea if this would work, but maybe fopen supports 
non-blocking connections? Or creation of context-based connections 
(for which you can use stream_set_blocking). If so, you could take a 
stamp of the current time plus a timeout value, make the fopen call 
(which would return immediately) then wait politely (I mean that 
from a CPU perspective) in a loop until you have data, or the 
current time goes past your time stamp.

Another avenue for investigation might be to try file_get_contents 
to see if it's connection timeout can be controlled. It seems to 
work in a similar way to fopen, in terms of having wrappers that are 
aware of multiple resource types.

It might also be worth taking a look at cURL or similar libraries 
that are also multi-resource aware, but give you greater control of 
connections parameters and timeouts.

Geoff.


On 19 Jan 2006 at 14:49, Richard Lynch wrote:

 On Thu, January 19, 2006 5:17 am, Jochem Maas wrote:
  Richard Lynch wrote:
  So I've been poring over the docs for the new stream stuff, and it
  looks pretty nifty, except...
 
  I'd really like to be able to just hand a URL to PHP like:
  http://php.net/manual/en/ref.stream.php
 
  er you can if allow_url_fopen ini setting is set to 1  (can't you?)
 
  $fh = fopen('http://php.net/');
 
 The crucial point buried too far into my initial post (sorry):
 
 I NEED to specify a timeout for the initial CONNECTION to acquire the
 data.
 
 fopen does not allow this.
 
 fsockopen does, but then I'm stuck with re-inventing the wheel on
 handling dozens of different protocols to initiate the process to get
 the data rolling.
 
 For HTTP, you have to send GET $path HTTP/1.0\n
 For FTP, you have to send GET $path\n
 For a file, you don't send anything
 ..
 ..
 ..
 
 So to get all the functionality of fopen() I'd need a monster long
 switch statement with a bunch of protocols about which I know almost
 nothing, including some rather complex stuff I can guarantee is over
 my head for ssl:// https:// ftps:// and friends.
 
 I really do not want to re-code all that, when I know it's down in the
 guts of 'fopen'
 
 In other words, I need an additional 'timeout' argument to fopen()
 that works when url_wrappers is on, or a function to set the default
 timeout for fopen() to wait.
 
 PLEASE don't refer me to stream_set_timeout.  THAT only applies to how
 long to wait for data AFTER the stream is open and you are reading
 data.
 
 I'm asking for:
 
 The convenience of fopen() that knows about dozens of protocols and
 takes care of the grotty details so I can just start reading data.
 
 The power of fsockopen() that allows one to specify how long to wait
 for a slow source feed.
 
 What I was hoping for, then, was that I could call this mythical
 function url2context() that would convert *any* URL into an
 appropriate stream context.
 
 Then I thought I would be able to use that contact for fsockopen()
 with a timeout for connection.
 
 I now see that fsockopen() does not even take a stream_context, but
 that fopen() now does, and none of this would do me any good at all...
 
 I guess I was thinking that the magic of fopen() being able to handle
 all those protocols had been bundled into the streams code, and that I
 ought to be able to utilize that somehow WITH a timeout on the
 connection.
 
 I guess I'm stuck with re-coding all the stuff from fopen() in a giant
 PHP switch and using my old-school fsockopen, just so I can have
 control over connection timeout.  :-(
 
 And it looks like all the new streams stuff is very nifty for some
 things, but rather useless for the feature that I believe quite a few
 users have been asking for:
 
 Gimme fopen() with control over timeout, so I can ignore all the
 minutia of what kind of file/stream/URL/whatever I'm reading, but not
 have my application waiting for 2 minutes when somebody else's server
 goes down.
 
 I tried to open a Feature Request to this, but it's already been
 closed as Bogus wherein I was told to rtfm.
 
 I've re-opened it, but based on my past mixed experience with the
 people behind bugs.php.net, I figure I've only got a 50/50 chance of
 somebody who actually reads and comprehends what I typed seeing it
 before it gets closed again and ignored. :-(
 
 Don't get me wrong -- I know what a monumental task they face, and am
 aware that there are certain Pavlovian automatic reactions, and that's
 how it is when they see the keywords embedded in my Change Request, so
 I'm not dis-ing them... It's just Reality that a worthy feature worth
 considering is probably going to get buried in the Bogus pile. [shrug]
 
 If anybody reading this actually agrees with me, feel free to vote here:
 http://bugs.php.net/bug.php?id=36072
 
 If you think I'm an idiot, by all means vote against the feature request.
 
 -- 
 Like Music?
 http://l-i-e.com/artists.htm
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] New to PHP

2006-01-19 Thread Geoff
I have a local web server running on my development PC, with an 
exact copy of all my sites stored locally, so I can develop and test 
as I go, only uploading when I know everything is 100%.
For Windows machines, you can choose IIS or Apache, although I'd 
recommend you go with whatever your web server is running.

Geoff.


On 19 Jan 2006 at 16:02, Jedidiah wrote:

 I mentioned earlier that I recently switched my site over to PHP.  I had a
 couple of reasons for this:
 
 1: I was using Server Side Includes, and had been told that PHP includes
 were better and definitely more popular.
 
 2: I began sending out a newsletter which was written by someone else in
 PHP.
 
  
 
 I am beginning to wonder if this was a good idea.  I can no longer preview
 my pages without uploading the files to the server.  This can really become
 a problem when I am making slight formatting changes to my CSS file where I
 need to refresh the page every few seconds until I get the look just right.
 
 Is it really worth changing all the files to PHP files and using includes?
 Is there any way around this, or am I stuck uploading??
 
  
 
 Thanks,
 
 
 Jedidiah
 
 
 
 !DSPAM:43d01a9147492034818120!
 

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



[PHP] (Fwd) inserting text into a mime message

2006-01-19 Thread Geoff
Nobody got any ideas on this? I would be interested to hear from 
anyone who has successfully adjusted parts of an email message while 
it is in transit, by ANY method. I'm getting desparate and will try 
anything, even if it is not 100% PHP.

All ideas, suggestions greatly appreciated.

Geoff.


--- Forwarded message follows ---
From:   Geoff [EMAIL PROTECTED]
To: php-general@lists.php.net
Subject:inserting text into a mime message
Date sent:  Thu, 19 Jan 2006 10:51:37 +0200

Hi All,

I've been searching the archives for help on this, but have come up 
empty-handed. Here's the thing:

I'm using a PHP script to parse every message coming through a 
mailserver. The server invokes my script for each message, giving it 
a filename containing the full raw text of the email. The script 
needs to modify the raw message file, inserting a footer (some 
trailing text, eg: a disclaimer) at the end of each part of readable 
message. It doesn't touch file attachments, but it needs to insert 
the footer in any plaintext, HTML text or both (if they exist).

There are so many different mime options and encoding types that it 
seemed like re-inventing the wheel to try working with only the raw 
message text, so instead I decided to use the PEAR Mail_mimeDecode 
module, which returns a very nice object array of all the parts, 
decoded and ready for use.

It's no problem going through this and inserting the footer wherever 
it is needed. That much I've done.

My problem is trying to rebuild that object array (the output of the 
Mail_mimeDecode::decode() function) back into its raw form once 
again, so that I can write the modified raw text back to the message 
file and the email can go on its way.

Another complication is that except for the insertion of the footer, 
I cannot modify the original message. All the headers, dates, 
receive-paths, etc, must remain unchanged.

Has anybody ever done anything like this before - re-encoding a 
message that had been decoded by Mail_mimeDecode::decode()? I've 
looked at the encode() function, but it seems to be used for making 
a simple message from scratch (with just one body part), it is not 
really the opposite of decode(). [I may be wrong about this - there 
are no examples in the PEAR manual].

I'm not hung up about what to use, it doesn't have to be PEAR, I 
will use any library or code that will do the job. Alternatively, if 
it is possible to do this with encode(), I would love to see an 
example, as I couldn't get it to work that way myself.

Many thanks.

Geoff.

--- End of forwarded message ---

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



Re: [PHP] (Fwd) inserting text into a mime message

2006-01-19 Thread Geoff
 It seems to me that if you looked at the raw email and found the
 boundary, and focused on the only mime-types you care about, you'd
 be able to hack the file pretty easily... 

I just may have to do that. One problem though is that many mails 
are encoded in some way (I mean byte-encoding, like base 64) and I 
was hoping to make use of the transparent decoding capability of a 
class or library made to do that sort of thing. But if I cannot, 
then yours is the approach I will probably use.

 All them lawyerly crapola signatures outside the control of the
 actual user implies that there is SOME kind of software available
 to do it... 

...but many of them are in commercial packages, or are plugins to 
MSExchange or similar. And most of the open-source ones only stick 
the footer in the first piece of text/plain that they find, without 
being aware of multiparts.

Thanks,

Geoff.


On 19 Jan 2006 at 16:38, Richard Lynch wrote:

 All them lawyerly crapola signatures outside the control of the actual
 user implies that there is SOME kind of software available to do it...
 
 It seems to me that if you looked at the raw email and found the
 boundary, and focused on the only mime-types you care about, you'd be
 able to hack the file pretty easily...
 
 And if it's not mime-encoded, it's just text, and a simple fopen($x,
 'a'); fwrite($x, $sig); fclose($x); would do it.
 
 Maybe I'm over-simplifying something?
 
 
 On Thu, January 19, 2006 4:22 pm, Geoff wrote:
  Nobody got any ideas on this? I would be interested to hear from
  anyone who has successfully adjusted parts of an email message while
  it is in transit, by ANY method. I'm getting desparate and will try
  anything, even if it is not 100% PHP.
 
  All ideas, suggestions greatly appreciated.
 
  Geoff.
 
 
  --- Forwarded message follows ---
  From:   Geoff [EMAIL PROTECTED]
  To: php-general@lists.php.net
  Subject:inserting text into a mime message
  Date sent:  Thu, 19 Jan 2006 10:51:37 +0200
 
  Hi All,
 
  I've been searching the archives for help on this, but have come up
  empty-handed. Here's the thing:
 
  I'm using a PHP script to parse every message coming through a
  mailserver. The server invokes my script for each message, giving it
  a filename containing the full raw text of the email. The script
  needs to modify the raw message file, inserting a footer (some
  trailing text, eg: a disclaimer) at the end of each part of readable
  message. It doesn't touch file attachments, but it needs to insert
  the footer in any plaintext, HTML text or both (if they exist).
 
  There are so many different mime options and encoding types that it
  seemed like re-inventing the wheel to try working with only the raw
  message text, so instead I decided to use the PEAR Mail_mimeDecode
  module, which returns a very nice object array of all the parts,
  decoded and ready for use.
 
  It's no problem going through this and inserting the footer wherever
  it is needed. That much I've done.
 
  My problem is trying to rebuild that object array (the output of the
  Mail_mimeDecode::decode() function) back into its raw form once
  again, so that I can write the modified raw text back to the message
  file and the email can go on its way.
 
  Another complication is that except for the insertion of the footer,
  I cannot modify the original message. All the headers, dates,
  receive-paths, etc, must remain unchanged.
 
  Has anybody ever done anything like this before - re-encoding a
  message that had been decoded by Mail_mimeDecode::decode()? I've
  looked at the encode() function, but it seems to be used for making
  a simple message from scratch (with just one body part), it is not
  really the opposite of decode(). [I may be wrong about this - there
  are no examples in the PEAR manual].
 
  I'm not hung up about what to use, it doesn't have to be PEAR, I
  will use any library or code that will do the job. Alternatively, if
  it is possible to do this with encode(), I would love to see an
  example, as I couldn't get it to work that way myself.
 
  Many thanks.
 
  Geoff.
 
  --- End of forwarded message ---
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 -- 
 Like Music?
 http://l-i-e.com/artists.htm
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 !DSPAM:43d0236364872042218820!
 

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



Re: [PHP] URL - stream context

2006-01-19 Thread Geoff
Richard, have you seen this:
http://bugs.php.net/bug.php?id=5153edit=1
This bug goes back to June 2000. And it's closed even though it is 
clearly not fixed. Doesn't seem like they'll get to it anytime soon. 
You might have to do it the long way, building your own protocol 
handlers. Or, you might want to look into a 3rd party library, or a 
command line option like lynx -dump -connect_timeout=n uri which 
is multi-resource aware.

Geoff.


On 19 Jan 2006 at 17:28, Richard Lynch wrote:

 On Thu, January 19, 2006 4:08 pm, Geoff wrote:
  I honestly have no idea if this would work, but maybe fopen supports
  non-blocking connections?
 
 Not as far as I can tell...
 
 You can call stream_set_blocking after it's open, but that doesn't
 help a slow connection in the first place.
 
  Or creation of context-based connections
  (for which you can use stream_set_blocking).
 
 Unless I'm seriously mis-reading docs, stream_set_blocking can only be
 called on an already-open stream, not on the soon-to-be-opened stream.
 
 fopen() in PHP5 does take a context, and if I could figure out how to
 embed the concepts of do not block and timeout in $x seconds
 within a context from the docs, and if fopen() would still handle all
 the details of the various protocols, I'd be all set...
 
 That's sort of what I was asking for in the original email, but...
 
 It seems like you have to specify the 'scheme' as the key in the
 context array.
 
 So, I guess, I could, in theory, find a listing of all the schemes
 fopen() supports, which might even be in a function, iterate over all
 of those, and do something like:
 $schemes = function_that_returns_all_schemes_fopen_supports();
 $opts = array();
 foreach($schemes as $scheme){
   $opts[$scheme]['some_magic_undocumented_thing'] =
 STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT ;
 }
 
 $foo = fopen($url, 'r', false, $opts);
 if ($foo == false) $errors[] = $url timed out;
 
 Only problem is, these constants are documented ONLY to work with:
 http://www.php.net/manual/en/function.stream-socket-client.php
 and that pretty clearly is working at a much lower-level than fopen
 (and friends) as the very first example shows using TCP as a protocol,
 and then you have to send the GET and any other headers, which is
 exactly what I'm trying to avoid having to re-code in the first place.
 
 So I'm back to square one, as far as I can see from the docs...
 
 It's possible (still) that I'm just mis-reading docs, or am
 continually skipping over the one new page in 'streams' that is making
 everybody think this should be so simple, but I don't think so, since
 I've read EVERY page in the new streams section several times now.
 
 I'm not claiming 100% comprehension of every implication on every
 page, mind you :-)
 
  If so, you could take a
  stamp of the current time plus a timeout value, make the fopen call
  (which would return immediately) then wait politely (I mean that
  from a CPU perspective) in a loop until you have data, or the
  current time goes past your time stamp.
 
 Yes -- if I could compose a stream_context doohickey that convinced
 fopen() to use a time-out...
 
  Another avenue for investigation might be to try file_get_contents
  to see if it's connection timeout can be controlled. It seems to
  work in a similar way to fopen, in terms of having wrappers that are
  aware of multiple resource types.
 
 file_get_contents() seems to suffer from the exact same limitations of
 file()
 
 I get the simplicity of fopen() with no control over connection timeout.
 
 Maybe there is some underlying voodoo going on in the PHP internals
 that some makes it crystal-clear why that has to be, but to this naive
 user, if fsockopen can have a timeout, fopen and friends out to be
 able to also, at least for schemes that support such a thing.
 
 Obviously SOME kind of timeout is involved somewhere in fopen()
 because it WILL timeout on some sites sometimes, even though
 experimentation has shown that had it waited, it would have gotten
 data eventually.
 
  It might also be worth taking a look at cURL or similar libraries
  that are also multi-resource aware, but give you greater control of
  connections parameters and timeouts.
 
 Maybe I've been mis-using cURL all these years, but it doesn't seem to
 be anywhere near as simple as the mythical function I've described,
 and really not much better than a giant switch for fsockopen to
 duplicate all that code that's gotta be down in the guts of fopen (and
 friends)
 
 -- 
 Like Music?
 http://l-i-e.com/artists.htm
 
 
 
 
 !DSPAM:43d02ead91711894325842!
 



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



Re: [PHP] Decision table/business rule parser?

2005-11-23 Thread Geoff - Creative Living
Hi folks

  As an alternative, I worked briefly on a native PHP Petri-net workflow
  engine with a guy called Tony Marston before we parted ways. He has
  written it up here:
  
  http://www.tonymarston.net/php-mysql/workflow.html

 I wrote to Tony a couple of months ago and he said that his workflow code 
 might
 be available someday, but wasn't available currently. His ideas are published
 on his website, but only code snippets.
 

The code is Tony's, so I can't help, I'm afraid. I think you'll find
it's itertwined with his development framework, so I'm not sure how
useful it would be as a standalone in any case.




Geoff Caplan
Creative Living

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



Re: [PHP] Decision table/business rule parser?

2005-11-22 Thread Geoff - Creative Living
Hi Mike

 I'm not aware of any. I am kind of developing my own for my current
 Materials System. 

Sounds as though, like me, you might just get away with a decision table
parser rather than a fully-fledged corporate rules engine. though your
application is a bit more complex than ours. 

It's surprising to me that we are faced with rolling our own or working
with Java - suggests that PHP still has a bit to go as a platform for
serious business systems.

 With jBPM I hope I'll be able to change routing/approval of
 electronic documents more easily than it is currently.
 
Are you planning to have PHP run as a servelet within JBoss? Does this
work reliably? I much prefer to keep things as simple as possible.

As an alternative, I worked briefly on a native PHP Petri-net workflow
engine with a guy called Tony Marston before we parted ways. He has
written it up here:

http://www.tonymarston.net/php-mysql/workflow.html



Geoff Caplan
Creative Living
Direct: 0121 515 1154
General: 01803 840 607

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



[PHP] Decision table/business rule parser?

2005-11-21 Thread Geoff - Creative Living
Hi

Does anyone know of an open source or commercial php library for parsing
decision tables? Or failing that, a more general business rules parser?
I can't find anything on the usual php script sites.

Unless I'm missing something, this seems to be a gap - in the Java world
there is a wide choice of native solutions.


Geoff Caplan
Creative Living

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



Re: [PHP] Decision table/business rule parser?

2005-11-21 Thread Geoff - Creative Living
Mike

 How about jBPM (http://www.jboss.org/products/jbpm)? I looked at it,
 briefly, awhile back. May implement it in the next release of my
 company software. Anyone have any experience with it?

There's a wide range of Java solutions:

http://www.manageability.org/blog/stuff/rule_engines/view

Most of them are over-specified for our relatively modest requirements.
Plus, I've never really looked into the practicality of using Java
libraries with Php 4. The only practical option I've found is this
project:

http://sourceforge.net/project/showfiles.php?group_id=117793

... but it's only got a couple of developers and I'm wary of betting my
business on a library like this. Do you know a better way?

With our modest needs, I'd much prefer to find a native solution, (if
such a thing exists) rather than add a layer of complexity and potential
unreliability by inter-operating with the Java VM.


Geoff Caplan
Creative Living

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



[PHP] Error Generated but no error?

2005-03-30 Thread Geoff Martin
I have a page that receives data from a form. Using $_POST['foo'], I am 
able to use this data in the page but I continually receive an error 
notice (PHP Notice:  Undefined index:  foo  in 
/Library/WebServer/Documents/.. etc).

This happens to all three indices that are passed by this form, yet the 
data IS appearing. How do I prevent these error messages?

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


[PHP] Re: Please wait page while processing - SOLVED

2004-12-04 Thread Geoff Caplan
Hi

For anyone interested, it was a combination of issues.

First, I had to use flush() and ob_end_flush() combined to
get the page to display in IE. end_flush didn't work on its
own.

Second, I was being dim in redirecting away from the message
page - because of course it won't display after a redirect.
So you have to do the processing in the message script,
saving the result to the session. Then keep polling the
message page with a client-side refresh till the gateway
processing completes and you can re-direct to the result
page.

GC I'm writing a checkout.

GC When user submits their card details, I want to redirect
GC them to page with a please wait message. Then redirect to
GC the script that does the payment processing. Then when I
GC have the response from the gateway, redirect again to the
GC result page.

form - message - processor - result_page

GC I've seen this done but I can't figure out how.

-- 
Geoff Caplan
Vario Software Ltd
(+44) 121-515 1154 

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



[PHP] Please wait page while processing

2004-12-03 Thread Geoff Caplan
Hi folks -

I'm writing a checkout.

When user submits their card details, I want to redirect
them to page with a please wait message. Then redirect to
the script that does the payment processing. Then when I
have the response from the gateway, redirect again to the
result page.

form - message - processor - result_page

I've seen this done but I can't figure out how.

The browser (IE) simply shows the initial card details form
until the processing is complete, then shows the final
result page. I can't get it to show the message page in the
middle.

Any suggestions would be welcome!

-- 
Geoff Caplan
Vario Software Ltd
(+44) 121-515 1154 

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



  1   2   3   >