php-general Digest 20 May 2011 16:55:34 -0000 Issue 7320
Topics (messages 312945 through 312978):
Re: hey
312945 by: Ashley Sheridan
312949 by: Richard Quadling
Re: Warning: Cannot modify header information - headers already sent by -
classic
312946 by: shiplu
312951 by: Carlos Medina
312956 by: Marc Guay
Re: A Review Request
312947 by: Tim Streater
312950 by: Tim Streater
312952 by: Peter Lind
312958 by: Joshua Kehn
312959 by: Robert Cummings
312974 by: Alex Nikitin
Re: PHP intreprets trailing slashes incorrectly?
312948 by: Richard Quadling
Date validation
312953 by: Geoff Lane
312954 by: João Cândido de Souza Neto
312962 by: Geoff Lane
312963 by: Peter Lind
312964 by: João Cândido de Souza Neto
312966 by: Peter Lind
312967 by: Geoff Lane
312969 by: João Cândido de Souza Neto
312970 by: Peter Lind
312972 by: Geoff Lane
312973 by: Geoff Lane
<img src .....> problem in onclick
312955 by: Negin Nickparsa
312957 by: Robert Cummings
312960 by: Negin Nickparsa
312977 by: Andre Polykanine
Need experience with OOPHP
312961 by: Jasper Mulder
312965 by: Robert Cummings
i need delay time in doing array_key_exists but while(true) can't work 4 it.
312968 by: Negin Nickparsa
312971 by: Jim Lucas
312975 by: Negin Nickparsa
312976 by: Negin Nickparsa
PHP Brainteasers 2011
312978 by: Marc Guay
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Thu, 2011-05-19 at 15:48 -0500, [email protected] wrote:
> Hey , i felt so overwhelmed before this
> http://citizenstelecom.com/redirect.php?to=aHR0cDovL3d3dy5uYmMxMGZpbmFuY2UuY29tLz9waWQ9NjYwNTA0
>
I guess it was just too close to Friday for him to wait?
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On 19 May 2011 21:48, <[email protected]> wrote:
> Hey , i felt so overwhelmed before this
> http://citizenstelecom.com/redirect.php?to=aHR0cDovL3d3dy5uYmMxMGZpbmFuY2UuY29tLz9waWQ9NjYwNTA0
Why? You run a get rich quick scam now? Gee! I wonder if you would
just give me some money. You are so completely loaded, I'm sure you
wouldn't miss a couple of thousand pounds. I've got a wife and 3 kids
to support and I'm mortgaged to the hilt.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/iZdpBR
--- End Message ---
--- Begin Message ---
On Fri, May 20, 2011 at 1:45 AM, Marc Guay <[email protected]> wrote:
> Hi folks,
>
> I'm running some code locally which should produce this fun error we
> all know and love: Warning: Cannot modify header information -
> headers already sent by... but does not. Switching from 5.3 to 5.2
> reveals the error and running it on another server with 5.2 also shows
> the error. I don't believe the version has anything to do with it,
> but who knows. I set error_reporting = E_ALL | E_STRICT and verified
> that display_errors = On, still nothing. Any ideas what could be
> allowing a header('Location:'); call to redirect without throwing an
> error after output has been sent to the browser?
>
> Marc
>
Marc, I think you should mimic this in command line using curl. You can
easily understand where the extra byte before headers are coming.
> --
>
Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
Innovation distinguishes between follower and leader
--- End Message ---
--- Begin Message ---
Am 20.05.2011 10:38, schrieb shiplu:
On Fri, May 20, 2011 at 1:45 AM, Marc Guay<[email protected]> wrote:
Hi folks,
I'm running some code locally which should produce this fun error we
all know and love: Warning: Cannot modify header information -
headers already sent by... but does not. Switching from 5.3 to 5.2
reveals the error and running it on another server with 5.2 also shows
the error. I don't believe the version has anything to do with it,
but who knows. I set error_reporting = E_ALL | E_STRICT and verified
that display_errors = On, still nothing. Any ideas what could be
allowing a header('Location:'); call to redirect without throwing an
error after output has been sent to the browser?
Marc
Marc, I think you should mimic this in command line using curl. You can
easily understand where the extra byte before headers are coming.
--
Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
Innovation distinguishes between follower and leader
Delete de ?> from all php files, if there are not using HTML but only php.
Regards
Carlos
--- End Message ---
--- Begin Message ---
To everyone who did not read my original message but responded to it,
Thank you.
Marc
--- End Message ---
--- Begin Message ---
On 20 May 2011 at 04:03, Alex Nikitin <[email protected]> wrote:
> but here is a brief example:
>
> (!DEBUG) || error_log("Fetch Data: ".memory_get_usage()/1048576);
>
> reads and writes a lot better and faster then:
>
> if(DEBUG) {
> $memory = memory_get_usage()/1048576;
> error_log("Fetch Data: ".$memory);
> }
Not to me it doesn't. I find such usage incomprehensible.
tim
--- End Message ---
--- Begin Message ---
On 19 May 2011 at 23:47, Adam Richardson <[email protected]> wrote:
> You did make several other great points (session hijacking, multiple login
> attempts), but to be fair to Tedd, there are many levels of security, and I
> doubt he's trying to educate PHP developers with your background. In the
> same way that someone's first foray into the world of database access using
> PHP likely avoids a 20 table database with complex transactions for atomic
> operations and in-memory queues for eventually consistent data where
> performance is a must, I see this as a reasonable first exposure to the
> general principles of how one might use the features of PHP to password
> protect a group of pages in a site.
I think this is the salient point. Provided the example is correct in itself,
is marked as being aimed at the novice, and at the same time lists some of the
areas that deliberately haven't been addressed in the example provided, then
that should suffice.
The difficulty IME is finding more advanced examples, which would help the
transition from learning mode to preparing for a production environment.
tim
--- End Message ---
--- Begin Message ---
On 20 May 2011 11:20, Tim Streater <[email protected]> wrote:
*snip*
> [...] is marked as being aimed at the novice, and at the same time lists some
> of the areas that deliberately haven't been addressed in the example
> provided, then that should suffice.
>
Apart from the above that would make great additions, would also be
great to see some links of where to get info on the subjects that are
not covered (such as security) so that people could find out more on
those topics.
Regards
Peter
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
On May 20, 2011, at 4:41 AM, Tim Streater wrote:
> On 20 May 2011 at 04:03, Alex Nikitin <[email protected]> wrote:
>
>> but here is a brief example:
>>
>> (!DEBUG) || error_log("Fetch Data: ".memory_get_usage()/1048576);
>>
>> reads and writes a lot better and faster then:
>>
>> if(DEBUG) {
>> $memory = memory_get_usage()/1048576;
>> error_log("Fetch Data: ".$memory);
>> }
>
> Not to me it doesn't. I find such usage incomprehensible.
>
> tim
I understand what you're doing, and I think it's a bad shortcut to be taking.
Make a dedicated class for logging and handle all this there.
Regards,
-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com
--- End Message ---
--- Begin Message ---
On 11-05-20 09:14 AM, Joshua Kehn wrote:
On May 20, 2011, at 4:41 AM, Tim Streater wrote:
On 20 May 2011 at 04:03, Alex Nikitin<[email protected]> wrote:
but here is a brief example:
(!DEBUG) || error_log("Fetch Data: ".memory_get_usage()/1048576);
If you're going to use ugly little shortcuts why not simplify the logic?
DEBUG && error_log("Fetch Data: ".memory_get_usage()/1048576);
reads and writes a lot better and faster then:
if(DEBUG) {
$memory = memory_get_usage()/1048576;
error_log("Fetch Data: ".$memory);
}
Personally I prefer the above use of an if conditional. It make it that
much easier to understand what you are doing.
Not to me it doesn't. I find such usage incomprehensible.
tim
I understand what you're doing, and I think it's a bad shortcut to be taking.
Make a dedicated class for logging and handle all this there.
That I think is the better idea... or for the procedural types a wrapper
log function that performs the DEBUG check.
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
Absolutely agree with logging function or class (i ofcourse prefer the
latter) for persistent logging that is to be present in the end product;
however its is not the best of ideas to spend time developing logging code
and using it for debug purposes that will only be used during the initial
development cycle of the said code. I can define debug just before or in the
beginning of a method or class, say one that i suspect is using up too much
memory, and throw a couple of these debug lines in there to avoid further
obfuscating code. Needless to say that there is only one line to remove
before publishing that code to production, say i do this 15 times in a block
of code, the "oh this is much more clean" version would mean that i would
have to go back through and remove 60 lines of code, and I, for one, am lazy
and dont like to do extra work.
I never said it was a good coding practice to use this kind of logic, infact
the "if" is on average about 20% faster, so i would recommend an inline if,
all i said is that it reads much quicker and cleaner, that said i would
normally write it as: if(DEBUG) ... Works just as well, actually better, i
just like to improvise, figure out new ways to do something, that kind of
spans my approach to thinking about programming in general, but i wont go
into that as i doubt its interesting to anyone, and certainly to some
extent, i like to confuse people with crazy code so that they dont stare
over my shoulder, especially code that i know i am going to remove. Oh and
in terms of performance, a callout to a function is about 40% slower then my
crazy code, and about 75% slower then an if check. Calling out to a logging
class is about 2 times slower then my logic, and almost 3 times slower then
an if.
Actually i accidentally left the debugs spanning from tracing through memory
use issues in someone else's code *caugh*PHPExcel*/caugh* in my class linked
above, so Adam (and/or others if you were looking at it) new pastebin link:
http://pastebin.com/2qg4qJRh
Also to tedd, i would say that you should make it a series of tutorials of
how to make simple user auth progressively more and more secure, i would say
that would be a good learning experience for someone. Start with your basic
code, introduce new concepts that will teach novice a little bit more about
how the internet works, how sessions work, how it can all be exploited
conceptually, and introduce ways to fix those issues with progressively more
hardened code...? I think that that would be a great way of learning for a
novice, i would say maybe 3 more tutorials, each progressively more secure;
suggesting next one to introduce hashing, cleaning the code, and some of the
initial concepts outlined above, then a system setup for https, going over
tls renegotiation, setting up rewriting rules, etc, and changing the code
with securing the session code and introducing login limits, and finally
perhaps how to take make all of this system a bit more web 2.0 with jquery,
ajax, and perhaps use that as the introduction of the next set of tuts of
how to do this same thing with a database back end with references back to
this auth system? I would have certainly liked to read a tutorial like that
when i was starting out... And, i'm up to help, i'm sure others as well
would not mind chiming in their $.02 :)
P.S. I like to play around with programming concepts, actually just gave up
of playing with a radix sort implementation in PHP, that deals with both
positive and negative numbers as well as floats, which are a pain in the
butt in php when you are dealing with binary operations, amongst other
things i had to write my own dec2bin that deals with float. It's mostly
working, still a couple of quirks that would need to be fixed, but its slow
in PHP as opposed to C++, where it can be many times faster then
library-provided sorting functions, so it's not really worth any more of my
time, but it was kind of fun to figure out how to do all of that, especially
converting signed ints and floats to positive ints and back :)
-- Alex --
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
On Fri, May 20, 2011 at 9:14 AM, Joshua Kehn <[email protected]> wrote:
> On May 20, 2011, at 4:41 AM, Tim Streater wrote:
>
> > On 20 May 2011 at 04:03, Alex Nikitin <[email protected]> wrote:
> >
> >> but here is a brief example:
> >>
> >> (!DEBUG) || error_log("Fetch Data: ".memory_get_usage()/1048576);
> >>
> >> reads and writes a lot better and faster then:
> >>
> >> if(DEBUG) {
> >> $memory = memory_get_usage()/1048576;
> >> error_log("Fetch Data: ".$memory);
> >> }
> >
> > Not to me it doesn't. I find such usage incomprehensible.
> >
> > tim
>
> I understand what you're doing, and I think it's a bad shortcut to be
> taking. Make a dedicated class for logging and handle all this there.
>
> Regards,
>
> -Josh
> ____________________________________
> Joshua Kehn | [email protected]
> http://joshuakehn.com
>
>
--- End Message ---
--- Begin Message ---
On 19 May 2011 21:13, Daniel Brown <[email protected]> wrote:
> On Thu, May 19, 2011 at 15:04, Scott Baker <[email protected]> wrote:
>> I have a script:
>>
>> http://www.perturb.org/index.php
>>
>> I accidentally put a trailing / on the url and it STILL loaded:
>>
>> http://www.perturb.org/index.php/
>>
>> Is that a bug in URL interpretation? I've tried it on three servers and
>> all seem to have the same behavior. All three were Apache on Linux, but
>> different versions as far back as PHP 5.2.x.
>
> It's not only intentional, it's also an exploitable feature used
> in search engine-friendly URLs and such, and is used by frameworks
> including CodeIgniter.
>
> You can grab that data from the $_SERVER['PATH_INFO'] superglobal
> value. Try this:
>
> <?php
> // Filename: test.php
> var_dump($_SERVER['PATH_INFO']);
> ?>
>
> Then, if that file is in the web root of your local machine, hit it like
> so:
>
> http://localhost/test.php/this/is/neat
> http://localhost/test.php/another/fine/day/in/the/suburbs
> http://localhost/test.php/
> http://localhost/test.php
>
> http://localhost/test.php/check/this/out?foo=bar&fruit[]=apple&fruit[]=banana&fruit[]=cherry
>
> This way, you can see a variety of examples of how it grabs that
> and only that. Now get creative. ;-P
>
>
> --
> </Daniel P. Brown>
> Network Infrastructure Manager
> http://www.php.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Assuming no knowledge of the underlying web server, as I understand
things, the path is parsed left to right and broken at /, ? and #.
At a / the left hand part is used to try and find a matching file. If
so, we win. The rest of the URL is passed onto PATH_INFO.
At a ? the right hand part is sent to the QUERY_STRING
At a #, the fragment_id doesn't seem to reach PHP.
Running ...
http://site.com/phpinfo.php/some/junk/path?some=junk&value=supplied#stop_here
I get ...
_REQUEST["some"] junk
_REQUEST["value"] supplied
_GET["some"] junk
_GET["value"] supplied
_SERVER["DOCUMENT_ROOT"] D:\Web Sites\Development\Accounts
Department\public_html
_SERVER["REQUEST_URI"]
/global/phpinfo.php/some/junk/path?some=junk&value=supplied
_SERVER["SCRIPT_FILENAME"] D:\Web Sites\All Sites\phpinfo.php
_SERVER["APPL_PHYSICAL_PATH"] D:\Web Sites\Development\Accounts
Department\public_html\
_SERVER["PATH_INFO"] /some/junk/path
_SERVER["PATH_TRANSLATED"] D:\Web Sites\All
Sites\phpinfo.php\some\junk\path
_SERVER["QUERY_STRING"] some=junk&value=supplied
_SERVER["SCRIPT_NAME"] /global/phpinfo.php
_SERVER["URL"] /global/phpinfo.php
_SERVER["ORIG_PATH_INFO"] /global/phpinfo.php/some/junk/path
_SERVER["PHP_SELF"] /global/phpinfo.php/some/junk/path
_SERVER["argv"]
Array
(
[0] => some=junk&value=supplied
)
_SERVER["argc"] 1
No mention at all of the "stop_here" text.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/iZdpBR
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
What about using this:
$date = DateTime::createFromFormat("Y-m-d", "2011-05-20");
--
João Cândido de Souza Neto
"Geoff Lane" <[email protected]> escreveu na mensagem
news:[email protected]...
> 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
>
--- End Message ---
--- Begin Message ---
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 "<p>Date 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]
<p>Date is 7 feb 2010</p>
<pre>DateTime Object
(
[date] => 2010-02-07 15:11:34
[timezone_type] => 3
[timezone] => Europe/London
)
</pre>
20 May 2011<br />
[/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
--- End Message ---
--- Begin Message ---
On 20 May 2011 16:22, Geoff Lane <[email protected]> wrote:
> 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 "<p>Date 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]
> <p>Date is 7 feb 2010</p>
> <pre>DateTime Object
> (
> [date] => 2010-02-07 15:11:34
> [timezone_type] => 3
> [timezone] => Europe/London
> )
> </pre>
> 20 May 2011<br />
> [/result]
>
> 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.
> 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.
Regards
Peter
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
If you look carefully, you´ll notice that I´m using the DateTime object
(default from PHP 5.2.0 or higher) not the function date.
--
João Cândido de Souza Neto
"Peter Lind" <[email protected]> escreveu na mensagem
news:[email protected]...
On 20 May 2011 16:22, Geoff Lane <[email protected]> wrote:
> 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 "<p>Date 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]
> <p>Date is 7 feb 2010</p>
> <pre>DateTime Object
> (
> [date] => 2010-02-07 15:11:34
> [timezone_type] => 3
> [timezone] => Europe/London
> )
> </pre>
> 20 May 2011<br />
> [/result]
>
> 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.
> 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.
Regards
Peter
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
2011/5/20 João Cândido de Souza Neto <[email protected]>:
> If you look carefully, you´ll notice that I´m using the DateTime object
> (default from PHP 5.2.0 or higher) not the function date.
If you look carefully, you'll notice that I replied to Geoff.
Regards
Peter
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
What about using regular expression to validate so using DateTime object to
parse it if it?s a valid date?
--
João Cândido de Souza Neto
"Geoff Lane" <[email protected]> escreveu na mensagem
news:[email protected]...
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
--- End Message ---
--- Begin Message ---
On 20 May 2011 16:47, Geoff Lane <[email protected]> wrote:
*snip*
>>> 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!
>
My bad, I jumped into the middle of a thread - sorry.
Try:
$date = new DateTime($date_string_to_validate);
echo $date->format('Y-m-d');
Regards
Peter
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
i want to when clicking on the image then go to other page or set my
$_SESSION
i have this in php code:
echo"<img src=' ' onclick='$_SESSION['s1']=12(i mean a number)';/>";
how can i correct this
or if it is completely wrong how 2 solve it?
i tried to set header in onclick too but i think it can't do because header
is function of php and i echoed the html tag
--- End Message ---
--- Begin Message ---
It is completely wrong... JavaScript is client side technology (your
browser), PHP is server side technology (your web server). To do what
you want, you SHOULD just wrap the image in a link:
<a href="where-to-go.php"><img src="" alt="description" /></a>
If you MUST use JavaScript, then you can use onclick() to redirect:
onclick="document.location( 'where-to-go.php' );"
If you want to also set the SESSION then add a parameter to the URL and
catch it on the receiving page:
where-to-go.php?action=some-action-taken
Then in your PHP script (where-to-go.php):
if( isset( $_GET['action'] ) && $_GET['action'] == 'some-action-taken' )
{
$_SESSION['s1'] = 12;
}
I hope this helps... I'll be hiding for the rest of the day :B
Cheers,
Rob.
On 11-05-20 09:05 AM, Negin Nickparsa wrote:
i want to when clicking on the image then go to other page or set my
$_SESSION
i have this in php code:
echo"<img src=' ' onclick='$_SESSION['s1']=12(i mean a number)';/>";
how can i correct this
or if it is completely wrong how 2 solve it?
i tried to set header in onclick too but i think it can't do because header
is function of php and i echoed the html tag
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
I tried,You solved my problem tanx very much Rob
--- End Message ---
--- Begin Message ---
Hello Negin,
that is completely wrong. You're mixing up two things: PHP is a
server-side language, JavaScript is a client-side language.
onClick is client-side, so you can't say onClick="<?php
something();"?>" because onclick is performed *after* the PHP script
something();"?>is *completely* formed and sent to the user's browser.
What you can do is changing your PHP variables by using AJAX. Consider
reading about jQuery in general and $.ajax in particular.
--
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion
------------ Original message ------------
From: Negin Nickparsa <[email protected]>
To: [email protected]
Date created: , 4:05:34 PM
Subject: [PHP] <img src .....> problem in onclick
i want to when clicking on the image then go to other page or set my
$_SESSION
i have this in php code:
echo"<img src=' ' onclick='$_SESSION['s1']=12(i mean a number)';/>";
how can i correct this
or if it is completely wrong how 2 solve it?
i tried to set header in onclick too but i think it can't do because header
is function of php and i echoed the html tag
--- End Message ---
--- Begin Message ---
Just the short week that I have been subscribed to this list, I have
encountered numerous code examples using the new OOPHP. A bit of a
culture shock, but since I also code in Java regularly, no conceptual
difficulties occur.
Only thing is now, that I would like to improve my OOPHP skill by
writing some useful classes; I don't see any possibilities in my current
ensemble of projects and therefore was wondering if anyone had some
small project for me, which I would then try to implement. Preferably, I
would get some response afterwards on where to improve, thus making me a
better programmer. I stress I have quite some experience with the old,
procedural PHP.
Anybody interested?
Best regards,
Jasper Mulder
--- End Message ---
--- Begin Message ---
On 11-05-20 10:15 AM, Jasper Mulder wrote:
Just the short week that I have been subscribed to this list, I have
encountered numerous code examples using the new OOPHP. A bit of a
culture shock, but since I also code in Java regularly, no conceptual
difficulties occur.
Only thing is now, that I would like to improve my OOPHP skill by
writing some useful classes; I don't see any possibilities in my current
ensemble of projects and therefore was wondering if anyone had some
small project for me, which I would then try to implement. Preferably, I
would get some response afterwards on where to improve, thus making me a
better programmer. I stress I have quite some experience with the old,
procedural PHP.
Anybody interested?
I'd like to see drOOPal :)
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
===>if(array_key_exists('sub5',$_POST))
this line runs before i clicked on the submit
while(true) before this line can't work then how can i solve the time
problem?
here is the whole code:
<?php
session_start();
$connection=Mysql_connect('localhost','admin','123');
if(array_key_exists('sub3',$_POST))
{
if(!$connection)
{
echo 'connection is invalid';
}
else
{
Mysql_select_db('drugnet',$connection);
$query="select * from patient";
$result=mysql_query($query);
$num=Mysql_num_rows($result);
$num1=Mysql_num_fields($result);
}
if($num>0)
{
echo "<table border=2>";
for($i=0;$i<$num;$i++)
{
$row=mysql_fetch_row($result);
echo "<tr>";
for($j=0;$j<$num1;$j++)
{
echo"<td>$row[$j]</td>";
}
echo"<td><input type='submit' name='sub5' value='patient
file$row[0]'/></td>";
echo"</tr>";
}
echo"</table>";
}
}
if(array_key_exists('sub5',$_POST))
{
$_SESSION[s1]=$row[0];
header("Location: patient.php?");
}
?>
<html>
<head>
<title>Doctor</title>
<form method="post">
<input type="submit" name="sub3" value="patient list"/>
<input type="submit" name="sub4" value="search patient"/>
</form>
</head>
</html>
--- End Message ---
--- Begin Message ---
Negin,
You cannot "pause" PHP. You need to do your checking and header() redirect on a
processing page that your form is submitting to.
file process
form.php Displays form
process.php decide what to you, redirect to secondary page
secondary.php display your secondary page
On 5/20/2011 7:54 AM, Negin Nickparsa wrote:
> ===>if(array_key_exists('sub5',$_POST))
> this line runs before i clicked on the submit
> while(true) before this line can't work then how can i solve the time
> problem?
> here is the whole code:
> <?php
> session_start();
>
> $connection=Mysql_connect('localhost','admin','123');
> if(array_key_exists('sub3',$_POST))
> {
>
>
> if(!$connection)
> {
> echo 'connection is invalid';
> }
> else
> {
> Mysql_select_db('drugnet',$connection);
> $query="select * from patient";
> $result=mysql_query($query);
> $num=Mysql_num_rows($result);
> $num1=Mysql_num_fields($result);
> }
> if($num>0)
> {
> echo "<table border=2>";
> for($i=0;$i<$num;$i++)
> {
> $row=mysql_fetch_row($result);
> echo "<tr>";
> for($j=0;$j<$num1;$j++)
> {
> echo"<td>$row[$j]</td>";
> }
> echo"<td><input type='submit' name='sub5' value='patient
> file$row[0]'/></td>";
> echo"</tr>";
> }
> echo"</table>";
> }
> }
> if(array_key_exists('sub5',$_POST))
> {
> $_SESSION[s1]=$row[0];
> header("Location: patient.php?");
> }
> ?>
> <html>
> <head>
> <title>Doctor</title>
> <form method="post">
> <input type="submit" name="sub3" value="patient list"/>
> <input type="submit" name="sub4" value="search patient"/>
>
> </form>
> </head>
> </html>
>
--- End Message ---
--- Begin Message ---
i can't understand what u wanted to tell me.
i want to when clicking on the sub button then go to another page i wrote it
but i can't solve this problem:
php runs the code and "then" i click it
i don't know,how can i solve it
any suggestion?
--- End Message ---
--- Begin Message ---
the thing that is important to me is setting session
because i want the tables of the one that clicked be showed on patient.php
how can i change my wrong code?
--- End Message ---
--- Begin Message ---
I imagine this one's been done before, but maybe not in the same way....
<?php
$result = succeed();
while (!$result){
try{
$result = succeed();
}
catch (Exception $e){
echo $e;
}
}
echo "hell yeah";
function succeed(){
$a = rand(1,2);
switch($a){
case 1:
trigger_error('fml');
break;
case 2:
return TRUE;
break;
}
}
?>
--- End Message ---