php-general Digest 24 Feb 2010 03:43:07 -0000 Issue 6606
Topics (messages 302315 through 302329):
Re: How to get the 'return type' of a function?
302315 by: Nathan Rixham
302325 by: Ashley Sheridan
302327 by: Kevin Kinsey
302328 by: Ashley Sheridan
Re: help, please, understanding my problem
302316 by: Stan
PLEASE, PLEASE, PLEASE - HELP ME GET OFF THIS LIST
302317 by: William C. Schnute
302318 by: Ashley Sheridan
302319 by: Daniel Brown
Re: Sending e-mail via socket
302320 by: John Black
Re: PHP / mySQL Project... Real men use 'cat'
302321 by: Daevid Vincent
302322 by: Ashley Sheridan
302329 by: Paul M Foster
Creating Days in a Year - Stored Procedure
302323 by: Pointmade_Noah1
302324 by: clancy_1.cybec.com.au
Re: $_POST vs $_REQUEST
302326 by: Jochem Maas
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 ---
tedd wrote:
> At 3:17 PM +0100 2/23/10, Daniel Egeberg wrote:
>> 2010/2/23 Dasn <[email protected]>:
>> > Could you tell me how to retrieve the 'return type'?
>>> Thanks.
>>>
>>>
>>> --
>>> Dasn
>>
>> That's not possible. Consider this function:
>>
>> function foo()
>> {
>> switch (rand(0, 1)) {
>> case 0: return 42;
>> case 1: return 'bar';
>> }
>> }
>>
>> What should the return type be?
>>
>> --
>> Daniel Egeberg
>
>
> It can be anything you want to test for -- check out:
>
> is_int();
> is_nan();
> is_float();
> is_long();
> is_string();
>
> IOW, is_whatever();
>
> Cheers,
>
> tedd
>
As PHP is loosely typed, the only real way around this is to specify a
return type in a PHPDoc block, then parse that using reflection to get
the @return parameter.
another option is to use something like haXe which is an ECMA style
typed language that compiles to multiple targets, one of which is PHP.
Regards!
Nathan
--- End Message ---
--- Begin Message ---
On Tue, 2010-02-23 at 09:31 -0500, tedd wrote:
> At 3:17 PM +0100 2/23/10, Daniel Egeberg wrote:
> >2010/2/23 Dasn <[email protected]>:
> > > Could you tell me how to retrieve the 'return type'?
> >> Thanks.
> >>
> >>
> >> --
> >> Dasn
> >
> >That's not possible. Consider this function:
> >
> >function foo()
> >{
> > switch (rand(0, 1)) {
> > case 0: return 42;
> > case 1: return 'bar';
> > }
> >}
> >
> >What should the return type be?
> >
> >--
> >Daniel Egeberg
>
>
> It can be anything you want to test for -- check out:
>
> is_int();
> is_nan();
> is_float();
> is_long();
> is_string();
>
> IOW, is_whatever();
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
is_quantum() is pretty useful as well, if you want to see if it's sort
of there and not at the same time. Probably turns into a cat in a box at
some point too, everything quantum has cats in...
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
is_quantum() is pretty useful as well, if you want to see if it's sort
of there and not at the same time. Probably turns into a cat in a box at
some point too, everything quantum has cats in...
Thanks,
Ash
So, should we add to the list:
is_schrodingers_cat_alive()
??
KDK
--- End Message ---
--- Begin Message ---
On Tue, 2010-02-23 at 19:19 -0600, Kevin Kinsey wrote:
> Ashley Sheridan wrote:
> > is_quantum() is pretty useful as well, if you want to see if it's sort
> > of there and not at the same time. Probably turns into a cat in a box at
> > some point too, everything quantum has cats in...
> >
> > Thanks,
> > Ash
>
> So, should we add to the list:
>
> is_schrodingers_cat_alive()
>
> ??
>
> KDK
>
I think PHP would crash trying to return the boolean value from that
one!
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Thanks all.
I rediscovered DIFF, compared the source for the first and second rendering.
Besides the unique variable names there was also the message ... which
contained imbedded single quote marks. When I changed them to imbedded
double quote marks the problem went away.
""Stan"" <[email protected]> wrote in message
news:[email protected]...
> I have a PHP page that has
> require_once("genMyOverlay.js.php");
> .
> .
> .
> echo "<body>";
> echo "<script language=\"JavaScript\">doit(\"mydiv\");</script><br>";
> echo "</body>";
>
> genMyOverlay.js.php contains: createDiv() (see below) that creates a <DIV
> ID="mydiv"> and sets it up to overlay a portion of the wbe page and
> doit()starts it off.
>
> invoke the web page once and it works like it should. invoke the web page
a
> second time (and thereafter until a new session) and it gets error:
> "doit is not defined"
>
> view the source (at the client browser) and it is identical both (all)
times
>
> can anyone please help me understand what is happening?
>
> genMyOverlay.js.php contains
> <script language="PHP">
> echo "<script language=\"JavaScript\">";
> echo "function createDiv()";
> echo " {";
> .
> .
> .
> echo " }";
> echo "function doit(ElementID)";
> echo " {";
> echo " creatDIV()";
> .
> .
> .
> echo " }";
> echo "</script>";
> </script>
>
>
--- End Message ---
--- Begin Message ---
PLEASE, PLEASE, PLEASE - HELP ME GET OFF THIS LIST --- YOU PEOPLE ARE
DRIVING ME CRAZY!!!!!!!!!!!!!!!!!!!!!!!!1
Please unsubscribe: [email protected],
[email protected] or anyone else @honeyflowfarm.com or
[email protected]
PLEASE!!!!!!!!!!!!
At 08:32 AM 2/23/2010, you wrote:
>Hi! This is the ezmlm program. I'm managing the
>[email protected] mailing list.
>
>I'm working for my owner, who can be reached
...snip...
> >
> >
> >This was a request generated from the form at
> >http://www.php.net/mailing-lists.php by 67.45.116.83.
--- End Message ---
--- Begin Message ---
On Tue, 2010-02-23 at 12:10 -0500, William C. Schnute wrote:
> PLEASE, PLEASE, PLEASE - HELP ME GET OFF THIS LIST --- YOU PEOPLE ARE
> DRIVING ME CRAZY!!!!!!!!!!!!!!!!!!!!!!!!1
>
> Please unsubscribe: [email protected],
> [email protected] or anyone else @honeyflowfarm.com or
> [email protected]
>
> PLEASE!!!!!!!!!!!!
>
> At 08:32 AM 2/23/2010, you wrote:
> >Hi! This is the ezmlm program. I'm managing the
> >[email protected] mailing list.
> >
> >I'm working for my owner, who can be reached
> ...snip...
> > >
> > >
> > >This was a request generated from the form at
> > >http://www.php.net/mailing-lists.php by 67.45.116.83.
>
>
Have you tried emailing the unsubscribe email address? You can find it
in the email headers of all the emails you receive from the mailing
list.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Tue, Feb 23, 2010 at 12:10, William C. Schnute
<[email protected]> wrote:
> PLEASE, PLEASE, PLEASE - HELP ME GET OFF THIS LIST --- YOU PEOPLE ARE
> DRIVING ME CRAZY!!!!!!!!!!!!!!!!!!!!!!!!1
Good.
> Please unsubscribe: [email protected],
> [email protected] or anyone else @honeyflowfarm.com or
> [email protected]
>
> PLEASE!!!!!!!!!!!!
Unfortunately, you have to unsubscribe yourself. Make sure you
don't have any forwarders being sent to your email account, if you're
unable. Just send a blank email to
[email protected] or go to
http://php.net/mailinglists and enter your email address, select the
General mailing list, and click the Unsubscribe button.
--
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers? Ask me how we can fit your budget!
--- End Message ---
--- Begin Message ---
On 02/23/2010 01:16 AM, Andre Polykanine wrote:
Hello everyone,
I've just subscribed to the list, and I already have a question.
what I need to do is to send mail using sockets. Actually, the
built-in Mail() function is great and I wouldn't have to search for
something else if I didn't need more than one message to be sent at a
time. Say, I have ten or a hundred of users who want to receive a
notification about new blog entries. If I use the mail() function in
the loop, it will be performed too slow since it constantly opens and
closes the door, I mean, the SMTP connection.
Have you figured it out yet?
I have written a SMTP function a couple of years ago which will talk to
any SMTP server directly via socket. The only limitation I have noticed
is that it does not support encrypted logins but that can be added, I
just never bothered to do it.
So let me know if you still require it and I'll dig it out.
--
John
Ihr führt Krieg? Ihr fürchtet euch vor einem Nachbarn? So nehmt doch die
Grenzsteine weg - so habt ihr keinen Nachbarn mehr. Aber ihr wollt den
Krieg und deshalb erst setztet ihr die Grenzsteine.
[Friedrich Nietzsche]
--- End Message ---
--- Begin Message ---
Am I the only Linux/Unix guy here? Do you guys not know what 'cat' is? :-\
http://en.wikipedia.org/wiki/Cat_(Unix)
http://techrepublic.com.com/5208-12846-0.html?forumID=102&threadID=310099&m
essageID=3099392&tag=content;leftCol
> -----Original Message-----
> From: Richard Quadling [mailto:[email protected]]
> Sent: Tuesday, February 23, 2010 3:43 AM
>
> On 23 February 2010 00:28, Daevid Vincent <[email protected]> wrote:
> >> -----Original Message-----
> >> From: Ashley Sheridan [mailto:[email protected]]
> >>
> >> On Mon, 2010-02-22 at 14:39 -0800, Don Wieland wrote:
> >>
> >> > I am needing assistance IMMEDIATELY in finishing up a
> project (the
> >> > developer went in to have shoulder surgery and will be out of
> >> > commission for 3 weeks) and I need this finished soon.
> >>
> >> That only puts one arm out of action surely?
> >> A real programmer would use the one hand!
> >
> > Real programmers use 'cat'.
>
> I've always found 'dog' and 'rabbit' to be more stimulating.
>
> -----Original Message-----
> From: Phpster [mailto:[email protected]]
> Sent: Tuesday, February 23, 2010 4:56 AM
>
> Depends on what you do with them!
>
> Bastien
--- End Message ---
--- Begin Message ---
On Tue, 2010-02-23 at 15:06 -0800, Daevid Vincent wrote:
> Am I the only Linux/Unix guy here? Do you guys not know what 'cat' is? :-\
>
> http://en.wikipedia.org/wiki/Cat_(Unix)
>
> http://techrepublic.com.com/5208-12846-0.html?forumID=102&threadID=310099&m
> essageID=3099392&tag=content;leftCol
>
> > -----Original Message-----
> > From: Richard Quadling [mailto:[email protected]]
> > Sent: Tuesday, February 23, 2010 3:43 AM
> >
> > On 23 February 2010 00:28, Daevid Vincent <[email protected]> wrote:
> > >> -----Original Message-----
> > >> From: Ashley Sheridan [mailto:[email protected]]
> > >>
> > >> On Mon, 2010-02-22 at 14:39 -0800, Don Wieland wrote:
> > >>
> > >> > I am needing assistance IMMEDIATELY in finishing up a
> > project (the
> > >> > developer went in to have shoulder surgery and will be out of
> > >> > commission for 3 weeks) and I need this finished soon.
> > >>
> > >> That only puts one arm out of action surely?
> > >> A real programmer would use the one hand!
> > >
> > > Real programmers use 'cat'.
> >
> > I've always found 'dog' and 'rabbit' to be more stimulating.
> >
> > -----Original Message-----
> > From: Phpster [mailto:[email protected]]
> > Sent: Tuesday, February 23, 2010 4:56 AM
> >
> > Depends on what you do with them!
> >
> > Bastien
>
>
>
It's like a dog, but smaller and smarter :p
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Tue, Feb 23, 2010 at 11:05:14PM +0000, Ashley Sheridan wrote:
> On Tue, 2010-02-23 at 15:06 -0800, Daevid Vincent wrote:
> >
> > http://techrepublic.com.com/5208-12846-0.html?forumID=102&threadID=310099&messageID=3099392&tag=content;leftCol
That guy's partial to JOE. Pffft. Real men use Vim. And Emacs is for
Martians with ten fingers on each hand.
And yeah, for what it's worth, I've been running Linux since 1996.
And yeah, cats are smarter than dogs.
Flame on! ;-}
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
I found this code below online and I am trying to modify it for my
needs. I want to pass a YEAR (Int) to the stored procedure and have it
create all the day in that passed year. With one tweak, If the day is
Sunday the "sStatus" field will equal "Closed" ELSE "Open". All
attempts come up with ERRORS. Also, I would like the sdate field to be
a DATE result. Little help please? I appreciate it.
USE colombo;
-- this table will store dates sequence
CREATE TABLE seq_dates
(
sdate DATETIME NOT NULL,
sStatus VARCHAR NULL,
);
DROP PROCEDURE IF EXISTS colombo.sp_init_dates;
CREATE PROCEDURE colombo.sp_init_dates
(IN p_fdate DATETIME, IN p_tdate DATETIME)
BEGIN
DECLARE v_thedate DATETIME;
DECLARE v_Status VARCHAR;
TRUNCATE TABLE colombo.seq_dates;
SET v_thedate = p_fdate;
WHILE (v_thedate < p_tdate) DO
IF (DayName(v_theDate) = "Sunday" {
SET v_Status = "Closed";
}else{
SET v_Status = "Open";
} // I know this CODE is wrong
-- insert dates squence into seq_dates table
INSERT INTO seq_dates (sdate, sStatus)
VALUES (v_thedate, v_Status);
-- go to the next day
SET v_thedate = DATE_ADD(v_thedate, INTERVAL 1 DAY);
END WHILE;
END;
--- End Message ---
--- Begin Message ---
On Tue, 23 Feb 2010 14:49:01 -0800, [email protected] (Pointmade_Noah1) wrote:
>I found this code below online and I am trying to modify it for my
>needs. I want to pass a YEAR (Int) to the stored procedure and have it
>create all the day in that passed year. With one tweak, If the day is
>Sunday the "sStatus" field will equal "Closed" ELSE "Open". All
>attempts come up with ERRORS. Also, I would like the sdate field to be
>a DATE result. Little help please? I appreciate it.
>
>USE colombo;
>
>-- this table will store dates sequence
>CREATE TABLE seq_dates
>(
> sdate DATETIME NOT NULL,
> sStatus VARCHAR NULL,
>);
>
>DROP PROCEDURE IF EXISTS colombo.sp_init_dates;
>
>CREATE PROCEDURE colombo.sp_init_dates
>(IN p_fdate DATETIME, IN p_tdate DATETIME)
>BEGIN
>DECLARE v_thedate DATETIME;
>DECLARE v_Status VARCHAR;
>
>TRUNCATE TABLE colombo.seq_dates;
>
>SET v_thedate = p_fdate;
>
>WHILE (v_thedate < p_tdate) DO
>
>IF (DayName(v_theDate) = "Sunday" {
>SET v_Status = "Closed";
>}else{
>SET v_Status = "Open";
>} // I know this CODE is wrong
>
> -- insert dates squence into seq_dates table
> INSERT INTO seq_dates (sdate, sStatus)
> VALUES (v_thedate, v_Status);
>
> -- go to the next day
> SET v_thedate = DATE_ADD(v_thedate, INTERVAL 1 DAY);
>
>END WHILE;
>
>END;
You could probably do something cunning with the library functions mktime(),
etc, but I
have two functions:
Abs_day ($date); which converts $date into an absolute day, with 1:1:1800 =
day 0
and
Ymd ($abs_day); which converts an absolute day back into Y:M:D
For your purpose there is a lot of redundancy, but between them these functions
provide
all the information you have asked for. Day zero was a Wednesday, so you can
readily work
out the DOW for any arbitrary day.
I have tested these functions up to 2500, but no obvious upper limit).
// Convert date YYYY:MM:DD into absolute day; 1:1:1800 = 0, Wednesday
function abs_day ($u)
{
$days = array
(0 => array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365,
375),
( 1 => array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366,
375));
// 0 is normal year, 1 is leap year
$y = $u[0];
if (($y % 400) == 0) { $ly = 1; } // See if leap year
elseif (($y % 100) == 0) { $ly = 0; }
elseif (($y % 4) == 0) { $ly = 1; }
else { $ly = 0; }
$y -= 1800;
$c = (int) (($y - 0.99)/100);
$c = (int) ($c * 0.75 +0.3); // Fiddle factor for centuries (most are
not leap
years)
$abs_day = (int) (($y) * 365.25 - $c - 0.1);
$d = (int) $u[1];
$abs_day += $u[2]-1 + $days[$ly][$d];
return $abs_day;
}
// Converts abs day to YMD.
function ymd ($day)
{
//echo '<h5>Stdu_408: Day = '.$day.'</h5>';
$days = array
(0 => array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365,
375),
( 1 => array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366,
375));
$u = false;
$c = (int)(($day + 0.6)/36524.25); // No of centuries
$ly = 0; if ((($c + 2) % 4) == 0) { $ly = 1; } // See if leap year
$d0 = $day - (int) ($c * 36524.25 + 0.3); // Calculate remaining
days
$yy = (int) (($d0 -$ly + 1.1)/365.25); // Calculate year
$d2 = $d0 +1 - (int) ($yy * 365.25 + $ly - 0.125); // & remaining days
(again!)
if ($yy != 0)
{
if (($yy % 4) == 0) { $ly = 1; } else { $ly = 0; } // See if
leap year
}
$u[0] = 100 * $c + $yy +1800; // Calc calendar year
$i = 1; $j = 0;
while ($d2 > $days[$ly][$i] && $i < 14) { $i++; } // and
month & day
$d2 -= $days[$ly][$i-1];
$u[1] = $i; $u[2] = $d2;
return $u;
}
--- End Message ---
--- Begin Message ---
Op 2/23/10 10:27 AM, Ashley Sheridan schreef:
> On Tue, 2010-02-23 at 09:19 +0000, Richard wrote:
>
>> Hi,
>>
>> Well people better than me (how is that possible?!) have said that
>> $_REQUEST has the potential to open your app up to security
>> vulnerabilities, and that it should be avoided because of that. Here's
>> a post from Stephan Esser about it on the PHP-Internals list:
>>
>> http://www.mail-archive.com/[email protected]/msg32832.html
>>
>> Stephan heads up the Hardened-PHP project and when it comes to
>> security, I don't know of anyone better. So, if he advises not to use
>> _REQUEST, it's a good idea to follow that advice.
>>
>> --
>> Richard Heyes
>>
>
>
> Well, he's only saying there that it 'most probably vulnerable' and
> mentions that cookies can overwrite post and get data. This isn't a
> problem with $_REQUEST itself but rather an applications' use of it. So
> what if someone crafts a cookie to send a bad value. If someone has the
> gen to do that, then they are going to know how to send get and post
> values as well. Only decent sanitisation will be able to protect against
> this.
>
> If the order of override variables in $_REQUEST is such an issue too,
> use the request_order ini setting to specify the order you'd prefer.
>
> I've never had any issues with using $_REQUEST, but found a lot of
> advantages to using it, as I often use a mix of data sources in the same
> app.
and that is exactly Essers point. you use $_REQUEST and assume the data came
from either GET or POST ... I'd hazard a guess your apps never expect such
'mixed'
data to be coming via COOKIE ... so your app will work as 'advertised' but if
some
one happens to slip a cookie onto someone else machine whose name matches some
rather important GET/POST input then it's that user who potentially has just
suffered
a denial of service - and you'll get the blame for the fact things don't work
and
you'll probably never be able to work out that it's a rogue cookie on the
client putting
a spanner in the works. (imagine you have an 'id' parameter and I managed to
set a
cookie on your users' machine called 'id' with a value of 1 ... have fun with
that)
you should be as strict with exceptable input vectors as you are with
sanitisation
of the actual input.
use of $_REQUEST is rather lazy - if you want to except either POST or GET for
a given
input write a simple wrapper function for that specific requirement - this will
also
save you from unforeseen problems related to incorrect or changed values for the
request_order ini setting.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
--- End Message ---