php-general Digest 16 Feb 2007 22:38:43 -0000 Issue 4629
Topics (messages 248945 through 248963):
array_pop() with key-value pair ???
248945 by: Eli
248946 by: Eli
248950 by: Mikey
248952 by: Robin Vickery
248953 by: Németh Zoltán
248954 by: Robin Vickery
248955 by: Németh Zoltán
248958 by: Eli
248959 by: Eli
Re: Text Editor for Windows?
248947 by: Kai
248956 by: Sady Marcos
Re: Problem Directing the Page with header
248948 by: Németh Zoltán
248957 by: Martin Marques
Detecting user_abort when using ob_start().
248949 by: Mathijs
Re: Problem with Redirect
248951 by: David Blanco
Re: Session Problem
248960 by: datsclark
Re: plugging gmmktime value into gmdate yields incorrect date
248961 by: Terra Frost
Re: Session problems with 4.4.5?
248962 by: Jochem Maas
reverse http authentication
248963 by: Chris W
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 ---
Hi,
Why isn't there a function that acts like array_pop() returns a pair of
key-value rather than the value only ?
Reason is, that in order to pop the key-value pair, you do:
<?php
$arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$arr_keys = array_keys($arr);
$key = array_pop($arr_keys);
$value = $arr[$key];
?>
I benchmarked array_keys() function and it is very slow on big arrays
since PHP has to build the array. While array_pop() can be acceleraed by
the guts of PHP engine.
-thanks
--- End Message ---
--- Begin Message ---
More over.. PHP seems to be quiet slow when dealing with array_shift()
array_unshift(), but it is much faster with array_pop() array_push(). I
am not familiar with the PHP internals, but why not add a pointer to the
start and end of the array?
Good word can be said on PHP that accelerated at least count() function..
Maybe I require too much.. PHP is a rapid development scripting
language.. not a massive optimized programming language.. :-/
Eli wrote:
Hi,
Why isn't there a function that acts like array_pop() returns a pair of
key-value rather than the value only ?
Reason is, that in order to pop the key-value pair, you do:
<?php
$arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$arr_keys = array_keys($arr);
$key = array_pop($arr_keys);
$value = $arr[$key];
?>
I benchmarked array_keys() function and it is very slow on big arrays
since PHP has to build the array. While array_pop() can be acceleraed by
the guts of PHP engine.
-thanks
--- End Message ---
--- Begin Message ---
I guess you have tried foreach?
foreach ($array as $key => $value) {
...
}
Mikey
Eli wrote:
More over.. PHP seems to be quiet slow when dealing with array_shift()
array_unshift(), but it is much faster with array_pop() array_push(). I
am not familiar with the PHP internals, but why not add a pointer to the
start and end of the array?
Good word can be said on PHP that accelerated at least count() function..
Maybe I require too much.. PHP is a rapid development scripting
language.. not a massive optimized programming language.. :-/
Eli wrote:
Hi,
Why isn't there a function that acts like array_pop() returns a pair
of key-value rather than the value only ?
Reason is, that in order to pop the key-value pair, you do:
<?php
$arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$arr_keys = array_keys($arr);
$key = array_pop($arr_keys);
$value = $arr[$key];
?>
I benchmarked array_keys() function and it is very slow on big arrays
since PHP has to build the array. While array_pop() can be acceleraed
by the guts of PHP engine.
-thanks
--- End Message ---
--- Begin Message ---
On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:
Hi,
Why isn't there a function that acts like array_pop() returns a pair of
key-value rather than the value only ?
Reason is, that in order to pop the key-value pair, you do:
<?php
$arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$arr_keys = array_keys($arr);
$key = array_pop($arr_keys);
$value = $arr[$key];
?>
I benchmarked array_keys() function and it is very slow on big arrays
since PHP has to build the array.
benchmark this:
end($arr);
list($key, $value) = each($arr);
-robin
--- End Message ---
--- Begin Message ---
2007. 02. 16, péntek keltezéssel 10.23-kor Robin Vickery ezt írta:
> On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Why isn't there a function that acts like array_pop() returns a pair of
> > key-value rather than the value only ?
> >
> > Reason is, that in order to pop the key-value pair, you do:
> > <?php
> > $arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
> > $arr_keys = array_keys($arr);
> > $key = array_pop($arr_keys);
> > $value = $arr[$key];
> > ?>
> >
> > I benchmarked array_keys() function and it is very slow on big arrays
> > since PHP has to build the array.
>
> benchmark this:
>
> end($arr);
> list($key, $value) = each($arr);
array_pop also removes the element from the array so add one more line:
unset($arr[$key]);
greets
Zoltán Németh
>
> -robin
>
--- End Message ---
--- Begin Message ---
On 16/02/07, Németh Zoltán <[EMAIL PROTECTED]> wrote:
2007. 02. 16, péntek keltezéssel 10.23-kor Robin Vickery ezt írta:
> On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Why isn't there a function that acts like array_pop() returns a pair of
> > key-value rather than the value only ?
> >
> > Reason is, that in order to pop the key-value pair, you do:
> > <?php
> > $arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
> > $arr_keys = array_keys($arr);
> > $key = array_pop($arr_keys);
> > $value = $arr[$key];
> > ?>
> >
> > I benchmarked array_keys() function and it is very slow on big arrays
> > since PHP has to build the array.
>
> benchmark this:
>
> end($arr);
> list($key, $value) = each($arr);
array_pop also removes the element from the array so add one more line:
unset($arr[$key]);
Yeah, but he's not actually popping the last element of $arr, he's
just using it to get the last key from $arr_keys.
-robin
--- End Message ---
--- Begin Message ---
2007. 02. 16, péntek keltezéssel 10.47-kor Robin Vickery ezt írta:
> On 16/02/07, Németh Zoltán <[EMAIL PROTECTED]> wrote:
> > 2007. 02. 16, péntek keltezéssel 10.23-kor Robin Vickery ezt írta:
> > > On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:
> > > > Hi,
> > > >
> > > > Why isn't there a function that acts like array_pop() returns a pair of
> > > > key-value rather than the value only ?
> > > >
> > > > Reason is, that in order to pop the key-value pair, you do:
> > > > <?php
> > > > $arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
> > > > $arr_keys = array_keys($arr);
> > > > $key = array_pop($arr_keys);
> > > > $value = $arr[$key];
> > > > ?>
> > > >
> > > > I benchmarked array_keys() function and it is very slow on big arrays
> > > > since PHP has to build the array.
> > >
> > > benchmark this:
> > >
> > > end($arr);
> > > list($key, $value) = each($arr);
> >
> > array_pop also removes the element from the array so add one more line:
> > unset($arr[$key]);
>
> Yeah, but he's not actually popping the last element of $arr, he's
> just using it to get the last key from $arr_keys.
well, sorry, I didn't examine his code just read his original question
saying "a function that acts like array_pop()"
it's now up to him to decide whether he wants to unset that element or
not :)
greets
Zoltán Németh
>
> -robin
>
--- End Message ---
--- Begin Message ---
Robin Vickery wrote:
On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:
Hi,
Why isn't there a function that acts like array_pop() returns a pair of
key-value rather than the value only ?
Reason is, that in order to pop the key-value pair, you do:
<?php
$arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$arr_keys = array_keys($arr);
$key = array_pop($arr_keys);
$value = $arr[$key];
?>
I benchmarked array_keys() function and it is very slow on big arrays
since PHP has to build the array.
benchmark this:
end($arr);
list($key, $value) = each($arr);
Thanks! that benchmarks with normal speed.. :-)
--- End Message ---
--- Begin Message ---
Mikey wrote:
I guess you have tried foreach?
foreach ($array as $key => $value) {
...
}
No.. loop should not be necessary when you want to take only the first
or the last element in the array.
Better using array_pop() array_shift() reset() end() and each()
functions for better run times.
--- End Message ---
--- Begin Message ---
[snip]
I am finding that notepad is lacking when correcting syntax errors in my
php code. No line numbers.
What can people recommend for use under Windows?
[/snip]
Zend Studio :-) ...but it's not for free. Check out the trial version.
--- End Message ---
--- Begin Message ---
PDT - PHP Eclipse
--- End Message ---
--- Begin Message ---
2007. 02. 15, csütörtök keltezéssel 18.41-kor Ashish Rizal ezt írta:
> Hey Jim,
> Thanks for the quick response. I have actually made the whole
> code on same page (login.php) and the functions that i used in
> this code are in functions.php. Now this time it is showing the
> warning :
> Warning: Cannot modify header information - headers already sent
> by (output started at C:\Program
> Files\xampp\htdocs\fselection\login.php:1) in C:\Program
> Files\xampp\htdocs\fselection\login.php on line 19
> The line 19 is header("Location: http://$host$uri/$extra");
it says you sent out some output on line 1
what is on line 1? maybe you have a blank line in the beginning of your
php file?
greets
Zoltán Németh
>
> Below is the list of code for login.php.
> The Server i am using is SunOS 5.10.
>
> <?php
> session_start();
> require_once 'functions.php';
> $UserName = $_POST['UserName'];
> $Password = $_POST['Password'];
> $host = $_SERVER['HTTP_HOST'];
> $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
> $extra = 'adminlogin.php';
> $loc = "\"http://$host$uri/$extra\"";
> if ($_POST){
> $error = login_check($_POST);
> if (trim ($error)=="")
> {
> $accesslevel = accessLevel($UserName);
> ?>
> <?php
> if ($accesslevel == "admin"){
> $_SESSION["userid"] = login($_POST);
> header("Location: http://$host$uri/$extra");
> exit();
> }
> else if ($accesslevel == "user") {
> //echo "this is user";
> $_SESSION["userid"] = login($_POST);
> header('Location: userlogin.php');
> exit();
> }
> }
> else {
> print "Error :$error";
> }
> }
> ?>
> <BODY>
> <FORM id=form1 name=loginform method=post>
> <TABLE align=center> ........
> ***********************Login Form Goes Here **********
> nothing php Stuffs on this part
> </body>
>
> Thank you again for your time and consideration.
>
--- End Message ---
--- Begin Message ---
On Thu, 15 Feb 2007, Ashish Rizal wrote:
<?php
session_start();
require_once 'functions.php';
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$error = login_check($_POST);
$adminAddress = getAbsolutePath().'adminlogin.php';
$userAddress = getAbsolutePath().'userlogin.php';
$samePage = getAbsolutePath().'login-new.php';
if (trim ($error)=="")
{
$accesslevel = accessLevel($UserName);
if ($accesslevel == "admin"){
$_SESSION["userid"] = login($_POST);
You need to put a session_commit(); here, so session gets writen.
header("Location: $adminAddress");
exit();
}
--
21:50:04 up 2 days, 9:07, 0 users, load average: 0.92, 0.37, 0.18
---------------------------------------------------------
Lic. Martín Marqués | SELECT 'mmarques' ||
Centro de Telemática | '@' || 'unl.edu.ar';
Universidad Nacional | DBA, Programador,
del Litoral | Administrador
---------------------------------------------------------
--- End Message ---
--- Begin Message ---
Hello there,
I have a script which is called using ajax.
This script can take a while executing.
Now it sometimes happens that a user aborts a connection, like stop the
ajax request.
This won't stop the php script from executing.
Now i need some way to detect if the user has stoped/aborted the connection.
I tryed to use connection_aborted and/or connection_status.
But this doesn't seem to work or something.
I Tryed to search for a sollution, but not much luck.
Also, i use ob_start() because of headers that needs to be sent and to
compress etc..
Thx in advance.
--- End Message ---
--- Begin Message ---
Hi!
Ashish Rizal escribió:
> Hi friends, I am having problem with following code.
> I have actually made the whole code on same page (login.php) and
> the functions that i used in
> this code are in functions.php. Now this time it is showing the
> warning :
> Warning: Cannot modify header information - headers already sent
> by (output started at C:\Program
> ...
> $accesslevel = accessLevel($UserName);
> ?>
> <?php
> if ($accesslevel == "admin"){
> ...
> ANy help would be highly appreicated. Thanks
There is a "\n" between the "?>" and the "<?php" that is causing the
warning. You cannot send any output before all the headers. You don't
need that "?>" followed by "<?php" because this makes no sense so
delete it.
Greetings from Spain!
--
David Blanco - Programación y sistemas
Publicinet (Publicidad-Cine-Internet, S.L.)
Urzaiz, 71, entlo, izda. -- 36204 Vigo
Telf 902.014.606 -- http://www.publicinet.net
--- End Message ---
--- Begin Message ---
Also, make sure the session's are being saved properly. I had this same
problem when PHP wasn't able to write to the temp directory. You can set up
your own sessions dir with
session.save_path
in php.ini
""LoneWolf"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I am having a problem where it appears that the session is not being saved
>properly.
>
> While on a page, I can start a session and set variables to it. however,
> when I go to the next page.. the session variables appear to have been
> cleared out.
>
> first page:
> session_start();
>
> $_SESSION["user_level"] = "test";
>
>
>
> second page:
>
> session_start();
>
> echo $_SESSION["user_level"] ;
>
>
>
> We just installed php on the 2003 server. Is there maybe a problem with
> the php.ini file that I need to fix?
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Brad Fuller wrote:
-----Original Message-----
From: Brad Fuller [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 15, 2007 3:48 PM
To: 'Terra Frost'; 'Peter Lauri'
Cc: [email protected]
Subject: RE: [PHP] plugging gmmktime value into gmdate yields incorrect
date
-----Original Message-----
From: Terra Frost [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 15, 2007 3:20 PM
To: Peter Lauri
Cc: [email protected]
Subject: Re: [PHP] plugging gmmktime value into gmdate yields
incorrect
date
date('Z') on the server producing the incorrect output returns
3600. On
the other two, I get -18000 and -21600.
That said, I don't see how that'd make a difference. The whole reason
I'm using the gm* functions, in the first place, is because those are
supposed to work with a fixed timezone - GMT. Testament to this is
the
fact that gmdate('Z') returns 0 on all three of those.
Peter Lauri wrote:
And what are the time zones for those two different machines? And
what
is
the time? :)
Best regards,
Peter Lauri
www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free
-----Original Message-----
From: Terra Frost [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 15, 2007 8:47 PM
To: [email protected]
Subject: [PHP] plugging gmmktime value into gmdate yields incorrect
date
I tried running the following script on three different servers:
<?php
echo gmdate('m, d, Y', gmmktime(0,0,0,3,23,2000) );
?>
On two of the servers, I got 03, 23, 2000 back. On the other,
however, I got 03, 22, 2000. This doesn't make any sense to me.
On the servers that return the correct date (03, 23, 2000),
gmmktime(0,0,0,3,23,2000) returns 953769600. On the server that
returns the incorrect date (03, 22, 2000), gmmktime(0,0,0,3,23,2000)
returns 953766000. There's a difference of 3600 between the two,
which makes me think that some daylight savings time setting is to
blame.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
I may be way off... but isn't it redundant to use both gmdate() and
gmmktime()? I thought each of these functions were used to convert
your
local time into GMT...
So for example if you're GMT+5, the gmmktime() would subtract 5
hours, and
then gmdate() would subtract another 5 hours?
Like I said - I could be way off, but just a thought.
-Brad
Yes, I was a little off...
gmmktime() takes a GMT date and converts it to a local unix timestamp.
gmdate() takes a local unix timestamp and converts it to a GMT date.
So in theory you *should* get the same date you put in, if using both
functions like your example.
I think you are on the right track with the Daylight Saving time issue.
Starting this year, DST in the U.S. begins in March instead of April.
Given that the year of your date input is 2000, it shouldn't be
affected,
but perhaps that is in fact the culprit? Your date 3/23 falls in
between the
previous and future DST start dates.
Hmm...
Have you gotten similar results using a different month/day?
-Brad
if you run:
echo gmdate('I', gmmktime(0,0,0,3,23,2000) ); //Capital 'i'
I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
This might help you
I got 0 on all three servers (even the one that's giving the incorrect
dates).
According to php.net, though, daylight savings time settings shouldn't
make a difference:
is_dst:
Parameters always represent a GMT date so is_dst doesn't influence
the result.
I tried to play around with that setting, all the same.
On the server that was reporting a date that was a day off (which is
running PHP 4.1.2 on Sun Solaris), gmmktime(0,0,0,3,23,2000,1) gave the
correct answer. gmmktime(0,0,0,3,23,2000,0) gave the incorrect answer.
On one of the servers that gave the correct answer (running PHP 4.4.3 on
some distro of Linux), gmmktime(0,0,0,3,23,2000,0) gave the correct
answer and gmmktime(0,0,0,3,23,2000,1) gave the incorrect answer.
On the last server (running PHP 4.4.4 on Windows), the last parameter
doesn't make a difference. It returns the correct answer regardless.
Making them all run on the same version of PHP would be nice, but two of
the three are on shared hosts which I have no real influence over.
Besides, I'd prefer to have this yield the same results on all three of
those servers - to be as cross-server compliant as possible.
--- End Message ---
--- Begin Message ---
Ken Williams wrote:
> Is anyone else having problems with session in 4.4.5? I'm under apache
> 1.3.27 in linux 2.4.34 and all my web sites break under 4.4.5. As soon as a
> page tries to register a session variable with session_register apache will
> segfault. Has worked perfectly fine for the past 2 years and like 10
> version of PHP 4.4.X.
segfault probably indicates problem. goto bugs.php.net and file a bug with
details about your machine and a small reproduce script.
side note: use of session_register() is not recommended - reading the following
page may help you understand why, help you work around your current problem and
hopefully get you on the path of using $_SESSION:
http://php.net/session_register
>
> [EMAIL PROTECTED]
>
--- End Message ---
--- Begin Message ---
I want to read a page that is protected with http authentication. How
do I pass the user name and password to be authenticated with my php code?
--
Chris W
KE5GIX
"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"
Gift Giving Made Easy
Get the gifts you want &
give the gifts they want
One stop wish list for any gift,
from anywhere, for any occasion!
http://thewishzone.com
--- End Message ---