php-general Digest 14 Dec 2005 22:15:46 -0000 Issue 3850
Topics (messages 227408 through 227442):
Re: Problem: Distortion while saving text file.
227408 by: David Grant
XSLT doesn't work anymore since PHP has been upgraded from 5.0.3 to 5.1.1
227409 by: Tobi Reif
Re: EXPORT DATA
227410 by: Miles Thompson
Re: Message Should be displayed based on Date ,Time and Eve nt name
227411 by: Jay Blanchard
227412 by: Jochem Maas
227413 by: Jay Blanchard
227422 by: tg-php.gryffyndevelopment.com
foreach $_FILES
227414 by: Shaun
227415 by: David Grant
227417 by: Jay Blanchard
227418 by: Jochem Maas
Re: Declaring arrays? Good practice?
227416 by: Al
227419 by: Jochem Maas
227421 by: Al
227424 by: Jochem Maas
227426 by: Kilbride, James
227427 by: Al
227428 by: adriano ghezzi
227430 by: tg-php.gryffyndevelopment.com
227432 by: Michael Hulse
Re: Accessing photos outside the web folder
227420 by: Jochem Maas
Re: Programming Query - Authentication - Multiple Logons
227423 by: Sarith Chandrasekaran
227425 by: tg-php.gryffyndevelopment.com
php file upload permission query
227429 by: Angelo Zanetti
looking for php programmers in mumbai / bombay
227431 by: mailing
227434 by: Derek Williams
When using foreach(), how to use &$value in php 4??
227433 by: Scott Fletcher
227437 by: comex
227438 by: comex
MIME E-mail message
227435 by: Oli Howson
227436 by: M. Sokolewicz
array to object conversion
227439 by: Cyril
PHPEclipse vs TruStudio
227440 by: Chris Lott
227441 by: dave
227442 by: dave
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 ---
Could it be the other way around, i.e. Windows is stripping slashes, and
Linux is not? How does $contents come to exist in the script?
Check for any difference in your ini files for magic_quotes_runtime.
Cheers,
David Grant
Janne Miettunen wrote:
> What could be wrong when this is transformed:
> "<img src="graphics/auringonlasku2.jpg" align="left">"
> ....to this form:
> "<img src=\"graphics/auringonlasku2.jpg\" align=\"left\">"
>
> The line is saved to text file with this function:
>
> function savesite($site, $lang, $contents){
>
> if (check_session()){
> $file=fopen('content/' . $site . '_' . $lang . '.txt', "w");
>
> fwrite($file, $contents);
>
> fclose($file);
> }
>
> I run it through nl2br() before saving and this only happens on Linux
> server, on Windows server it works fine, no \ before ".
>
> Tested with:
> On Windows: Apache2, PHP5
> Linux: Debian distro, Apache2, PHP4, also tried with PHP5
>
--
David Grant
http://www.grant.org.uk/
--- End Message ---
--- Begin Message ---
Hi
My ISP upgraded from 5.0.3 to 5.1.1. Since then, XSLT (at least my
script which uses it) doesn't work anymore.
The first error message on
http://www.pinkjuice.com/hayashi/materials/
is
Warning: XSLTProcessor::importStylesheet()
[function.importStylesheet]: Undefined variable in
/[...]/hayashi/pages.php5 on line 12
pages.php5:
<?php
# print dirname(__FILE__);
$xslt = new DomDocument();
$xslt->load("this.xslt");
$inputdom = new DomDocument();
$inputdom->load("../page_template.xml");
$proc = new XsltProcessor();
# previous version of the following line:
# $xslt = $proc->importStylesheet($xslt);
$proc->importStylesheet($xslt);
$proc->setParameter(null, "pagedir", $pagedir);
# seems to set params *and* toplevel variables
# $proc->setParameter(null, "topdir", $topdir);
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
?>
Thanks in advance,
Tobi
--- End Message ---
--- Begin Message ---
First of all, check the PostgreSQL docs on loading data - there may be a
native method you can call. Otherwise you normally export Excel to a .csv
file and import that.
How?
Never done it, but how about a combination of fgetcsv() and pg_copy() or
pg_insert()? There may be a tool out there on the web, have you googled for
"postgresql import excel"?
HTH - Miles Thompson
At 12:20 AM 12/14/2005, Aftab Alam wrote:
Hi all,
How can i export excel data to PostgresSQL using PHP.
regards
aftab
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
[snip]
I am accepting event name,Date and time and saving the data in PostgeSQL
table.. I have used PHP html Javascript and postgesql for this. Can anyone
tell me how can I display a popup message when that particular event occurs
on particular date and time.
[/snip]
Your best bet may be AJAX. Google has tons of information.
PHP is not well suited for triggering a client side pop-up event at a
precise time due to it being server side.
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
[snip]
I am accepting event name,Date and time and saving the data in PostgeSQL
table.. I have used PHP html Javascript and postgesql for this. Can anyone
tell me how can I display a popup message when that particular event occurs
on particular date and time.
[/snip]
Your best bet may be AJAX. Google has tons of information.
PHP is not well suited for triggering a client side pop-up event at a
precise time due to it being server side.
what is this??? invasion of the body snatchers? where is Jay 'RTFM' Blanchard?
:-)
--- End Message ---
--- Begin Message ---
[snip]
> Your best bet may be AJAX. Google has tons of information.
>
> PHP is not well suited for triggering a client side pop-up event at a
> precise time due to it being server side.
>
what is this??? invasion of the body snatchers? where is Jay 'RTFM'
Blanchard? :-)
[/snip]
It is the holidays, and I am a holiday kinda' guy, although I did tell
another programmer yesterday to 'RTFCC'. [Read The Fine Christmas Card]
OAN, I got my new laptop yesterday. 2Ghz, 100GbHD, 2GbRAM, 733Mhz FSB,
CD/DVD Burner.....ugh,ugh,ugh!
--- End Message ---
--- Begin Message ---
This is a kinder, gentler Jay.. hey, don't look a gift horse in the mouth!
But if anyone's still not satisfied... you can go RTFM if it makes you feel
better. :)
Happy holidays! (yeah, holidays.. christmas IS included in that.. jesus.. how
did political correctness turn to bite everyone on the ass by getting offended
by "happy holidays"?? holy buddah!) </rant> <--- not RFC 12345 ("Rant")
compliant
= = = Original message = = =
[snip]
> Your best bet may be AJAX. Google has tons of information.
>
> PHP is not well suited for triggering a client side pop-up event at a
> precise time due to it being server side.
>
what is this??? invasion of the body snatchers? where is Jay 'RTFM'
Blanchard? :-)
[/snip]
It is the holidays, and I am a holiday kinda' guy, although I did tell
another programmer yesterday to 'RTFCC'. [Read The Fine Christmas Card]
OAN, I got my new laptop yesterday. 2Ghz, 100GbHD, 2GbRAM, 733Mhz FSB,
CD/DVD Burner.....ugh,ugh,ugh!
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
Hi,
I have a form on my site with many file fields for users to upload files. I
am trying to verify that for each file uploaded it corresponds with the name
of the file field i.e.
<tr>
<td>File_1.CSV:</td>
<td><input type="file" name="File_1.CSV"></td>
</tr>
<tr>
<td>File_2.CSV:</td>
<td><input type="file" name="File_2.CSV"></td>
</tr>
However if I loop through the $_FILES array like this:
foreach( $_FILES as $key => $value ){
echo '$key = '.$key.'<br />';
echo '$value = '.$value.'<br />';
}
$key = File_1_CSV
$value['name'] = File_1.CSV
$key = File_2_CSV
$value['name'] = File_2.CSV
The . is replaced with an underscore in the $key value. I could get around
this with a substr() but it seems a little inelegant, can anyone tell me why
this is happening please?
Thanks for your advice.
--- End Message ---
--- Begin Message ---
Shaun,
That is the documented behaviour for form fields in PHP.
See "Dots in incoming variable names" on the following page:
http://php.net/variables.external
Cheers,
David Grant
Shaun wrote:
> Hi,
>
> I have a form on my site with many file fields for users to upload files. I
> am trying to verify that for each file uploaded it corresponds with the name
> of the file field i.e.
>
> <tr>
> <td>File_1.CSV:</td>
> <td><input type="file" name="File_1.CSV"></td>
> </tr>
> <tr>
> <td>File_2.CSV:</td>
> <td><input type="file" name="File_2.CSV"></td>
> </tr>
>
> However if I loop through the $_FILES array like this:
>
> foreach( $_FILES as $key => $value ){
> echo '$key = '.$key.'<br />';
> echo '$value = '.$value.'<br />';
> }
>
> $key = File_1_CSV
> $value['name'] = File_1.CSV
> $key = File_2_CSV
> $value['name'] = File_2.CSV
>
> The . is replaced with an underscore in the $key value. I could get around
> this with a substr() but it seems a little inelegant, can anyone tell me why
> this is happening please?
>
> Thanks for your advice.
>
--
David Grant
http://www.grant.org.uk/
--- End Message ---
--- Begin Message ---
[snip]
However if I loop through the $_FILES array like this:
foreach( $_FILES as $key => $value ){
echo '$key = '.$key.'<br />';
echo '$value = '.$value.'<br />';
}
$key = File_1_CSV
$value['name'] = File_1.CSV
$key = File_2_CSV
$value['name'] = File_2.CSV
The . is replaced with an underscore in the $key value. I could get around
this with a substr() but it seems a little inelegant, can anyone tell me why
this is happening please?
[/snip]
Periods are not allowed in variable names and are replaced by an underscore.
You could use regex to do the replacement so that you can do comparison.
--- End Message ---
--- Begin Message ---
Shaun wrote:
Hi,
I have a form on my site with many file fields for users to upload files. I
am trying to verify that for each file uploaded it corresponds with the name
of the file field i.e.
<tr>
<td>File_1.CSV:</td>
<td><input type="file" name="File_1.CSV"></td>
</tr>
<tr>
<td>File_2.CSV:</td>
<td><input type="file" name="File_2.CSV"></td>
</tr>
However if I loop through the $_FILES array like this:
foreach( $_FILES as $key => $value ){
echo '$key = '.$key.'<br />';
echo '$value = '.$value.'<br />';
}
$key = File_1_CSV
$value['name'] = File_1.CSV
$key = File_2_CSV
$value['name'] = File_2.CSV
The . is replaced with an underscore in the $key value. I could get around
this with a substr() but it seems a little inelegant, can anyone tell me why
a fullstop/dot is not allowed in the name of a variable in php.
// following line errors out...
echo $File_2.CSV;
this is mentioned in the manual.
this is happening please?
Thanks for your advice.
--- End Message ---
--- Begin Message ---
However....
For loops:
$new_array= array();
foreach($old array as $value){
$new_array= $value:
}
Otherwise, all you'll get it the last assignment of $new_array as a variable,
not an array.
You can also use;
foreach($old array as $value){
$new_array[]= $value:
}
But sometimes, if the expression is a bit fancy in the loop and you are using
$keys, it is easy to make a mistake.
Al..........
Michael Hulse wrote:
Sorry if this question sounds noobish:
$foo = array(); // Declare first, good practice.
$foo = array('one', 'two', 'three');
Using above as example, is it good to always declare the array first?
I usually/always declare my arrays first, but sometimes I get a bit
confused... for example:
function give_foo() {
$the_foo = array(); // Declare first, good practice.
$the_foo = array('one', 'two', 'three');
// Do some stuff here...
return $the_foo;
}
$foo = give_foo(); // Declare $foo also?
So, should I declare $foo as array and then give it the value of the
function? Example:
$foo = array(); // Declare first, good practice.
$foo = give_foo();
That seems kinda redundant. Thoughts?
Sorry if this is a stupid question... I am self-taught, and I am trying
to shake all my bad coding habits.
--- End Message ---
--- Begin Message ---
Al wrote:
However....
For loops:
$new_array= array();
foreach($old array as $value){
$new_array= $value:
}
Otherwise, all you'll get it the last assignment of $new_array as a
variable, not an array.
which is exactly what you get if yuou run the code above - after
the foreach loop $new_array will be set to the value of the
last item of $old_array.
regardless of whether you init the var you still have to
use the square-bracket notation to add items to the array.
You can also use;
foreach($old array as $value){
$new_array[]= $value:
}
But sometimes, if the expression is a bit fancy in the loop and you are
using $keys, it is easy to make a mistake.
Al..........
Michael Hulse wrote:
Sorry if this question sounds noobish:
$foo = array(); // Declare first, good practice.
$foo = array('one', 'two', 'three');
Using above as example, is it good to always declare the array first?
I usually/always declare my arrays first, but sometimes I get a bit
confused... for example:
function give_foo() {
$the_foo = array(); // Declare first, good practice.
$the_foo = array('one', 'two', 'three');
// Do some stuff here...
return $the_foo;
}
$foo = give_foo(); // Declare $foo also?
So, should I declare $foo as array and then give it the value of the
function? Example:
$foo = array(); // Declare first, good practice.
$foo = give_foo();
That seems kinda redundant. Thoughts?
Sorry if this is a stupid question... I am self-taught, and I am
trying to shake all my bad coding habits.
--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
Al wrote:
However....
For loops:
$new_array= array();
foreach($old array as $value){
$new_array= $value:
}
Otherwise, all you'll get it the last assignment of $new_array as a
variable, not an array.
which is exactly what you get if yuou run the code above - after
the foreach loop $new_array will be set to the value of the
last item of $old_array.
regardless of whether you init the var you still have to
use the square-bracket notation to add items to the array.
You can also use;
foreach($old array as $value){
$new_array[]= $value:
}
But sometimes, if the expression is a bit fancy in the loop and you
are using $keys, it is easy to make a mistake.
Al..........
Michael Hulse wrote:
Sorry if this question sounds noobish:
$foo = array(); // Declare first, good practice.
$foo = array('one', 'two', 'three');
Using above as example, is it good to always declare the array first?
I usually/always declare my arrays first, but sometimes I get a bit
confused... for example:
function give_foo() {
$the_foo = array(); // Declare first, good practice.
$the_foo = array('one', 'two', 'three');
// Do some stuff here...
return $the_foo;
}
$foo = give_foo(); // Declare $foo also?
So, should I declare $foo as array and then give it the value of the
function? Example:
$foo = array(); // Declare first, good practice.
$foo = give_foo();
That seems kinda redundant. Thoughts?
Sorry if this is a stupid question... I am self-taught, and I am
trying to shake all my bad coding habits.
Taint so Jochem. Try it.
--- End Message ---
--- Begin Message ---
WTF are you smoking Al?
Al wrote:
Jochem Maas wrote:
Al wrote:
However....
For loops:
$new_array= array();
foreach($old array as $value){
$new_array= $value:
}
Otherwise, all you'll get it the last assignment of $new_array as a
variable, not an array.
which is exactly what you get if yuou run the code above - after
the foreach loop $new_array will be set to the value of the
last item of $old_array.
regardless of whether you init the var you still have to
use the square-bracket notation to add items to the array.
You can also use;
foreach($old array as $value){
$new_array[]= $value:
}
Taint so Jochem. Try it.
1. using the word 'Taint' there makes no sense.
2. secondly your example code didn't even parse.
3. I don't need to bloody try it, but just for you I did - so now you
can explain the following ouput (i.e. that after the loop has run $new_array
is equal to the string 'A'):
PHP 5.0.4 (cli) (built: Aug 16 2005 15:29:25)
[EMAIL PROTECTED] -- Wed Dec 14 17:21:47
$> php -r '
$> $old_array = range(A,E); $new_array = array();
$>
$> echo "BEFORE:\n";
$> var_dump($new_array, $old_array);
$>
$> foreach($old_array as $value) { $new_array = $value; }
$>
$> echo "AFTER:\n";
$> var_dump($new_array, $old_array);
$> '
BEFORE:
array(0) {
}
array(5) {
[0]=>
string(1) "A"
[1]=>
string(1) "B"
[2]=>
string(1) "C"
[3]=>
string(1) "D"
[4]=>
string(1) "E"
}
AFTER:
string(1) "E"
array(5) {
[0]=>
string(1) "A"
[1]=>
string(1) "B"
[2]=>
string(1) "C"
[3]=>
string(1) "D"
[4]=>
string(1) "E"
}
--- End Message ---
--- Begin Message ---
<?php
$old_array= array('one','two','three','four');
$new_array= array();
foreach($old_array as $value){
$new_array= $value;
}
echo "$new_array";
?>
The result of the echo is "four". Doing the same above with the [] after
new_array returns the right result, a new array.(outputs Array). So what
exactly where you saying 'Taint so' Al? I'm confused since Jochem's
email about how to properly copy an array seems correct.
James Kilbride
> -----Original Message-----
> From: Al [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, December 14, 2005 10:47 AM
> To: [email protected]
> Subject: Re: [PHP] Re: Declaring arrays? Good practice?
>
> Jochem Maas wrote:
> > Al wrote:
> >
> >> However....
> >>
> >> For loops:
> >>
> >> $new_array= array();
> >>
> >> foreach($old array as $value){
> >>
> >> $new_array= $value:
> >> }
> >>
> >> Otherwise, all you'll get it the last assignment of
> $new_array as a
> >> variable, not an array.
> >
> >
> > which is exactly what you get if yuou run the code above -
> after the
> > foreach loop $new_array will be set to the value of the
> last item of
> > $old_array.
> >
> > regardless of whether you init the var you still have to use the
> > square-bracket notation to add items to the array.
> >
> >>
> >> You can also use;
> >>
> >> foreach($old array as $value){
> >>
> >> $new_array[]= $value:
> >> }
> >>
> >> But sometimes, if the expression is a bit fancy in the
> loop and you
> >> are using $keys, it is easy to make a mistake.
> >>
> >> Al..........
> >>
> >> Michael Hulse wrote:
> >>
> >>> Sorry if this question sounds noobish:
> >>>
> >>> $foo = array(); // Declare first, good practice.
> >>> $foo = array('one', 'two', 'three');
> >>>
> >>> Using above as example, is it good to always declare the
> array first?
> >>>
> >>> I usually/always declare my arrays first, but sometimes I
> get a bit
> >>> confused... for example:
> >>>
> >>> function give_foo() {
> >>> $the_foo = array(); // Declare first, good practice.
> >>> $the_foo = array('one', 'two', 'three');
> >>> // Do some stuff here...
> >>> return $the_foo;
> >>> }
> >>> $foo = give_foo(); // Declare $foo also?
> >>>
> >>> So, should I declare $foo as array and then give it the
> value of the
> >>> function? Example:
> >>>
> >>> $foo = array(); // Declare first, good practice.
> >>> $foo = give_foo();
> >>>
> >>> That seems kinda redundant. Thoughts?
> >>>
> >>> Sorry if this is a stupid question... I am self-taught, and I am
> >>> trying to shake all my bad coding habits.
> >>
> >>
> >>
>
> Taint so Jochem. Try it.
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
What I said was that arrays can be handled two different ways for loops.
1] By assigning the variable prior to the loop [i.e., $new_array= array();]
2] Or, by using inside the loop: $new_array[]= $value
Either one works. I've found, when the loop has lots of fancy stuff involving the $new_array, it is useful to go ahead
a assign it before starting the loop.
Kilbride, James wrote:
<?php
$old_array= array('one','two','three','four');
$new_array= array();
foreach($old_array as $value){
$new_array= $value;
}
echo "$new_array";
?>
The result of the echo is "four". Doing the same above with the [] after
new_array returns the right result, a new array.(outputs Array). So what
exactly where you saying 'Taint so' Al? I'm confused since Jochem's
email about how to properly copy an array seems correct.
James Kilbride
-----Original Message-----
From: Al [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 10:47 AM
To: [email protected]
Subject: Re: [PHP] Re: Declaring arrays? Good practice?
Jochem Maas wrote:
Al wrote:
However....
For loops:
$new_array= array();
foreach($old array as $value){
$new_array= $value:
}
Otherwise, all you'll get it the last assignment of
$new_array as a
variable, not an array.
which is exactly what you get if yuou run the code above -
after the
foreach loop $new_array will be set to the value of the
last item of
$old_array.
regardless of whether you init the var you still have to use the
square-bracket notation to add items to the array.
You can also use;
foreach($old array as $value){
$new_array[]= $value:
}
But sometimes, if the expression is a bit fancy in the
loop and you
are using $keys, it is easy to make a mistake.
Al..........
Michael Hulse wrote:
Sorry if this question sounds noobish:
$foo = array(); // Declare first, good practice.
$foo = array('one', 'two', 'three');
Using above as example, is it good to always declare the
array first?
I usually/always declare my arrays first, but sometimes I
get a bit
confused... for example:
function give_foo() {
$the_foo = array(); // Declare first, good practice.
$the_foo = array('one', 'two', 'three');
// Do some stuff here...
return $the_foo;
}
$foo = give_foo(); // Declare $foo also?
So, should I declare $foo as array and then give it the
value of the
function? Example:
$foo = array(); // Declare first, good practice.
$foo = give_foo();
That seems kinda redundant. Thoughts?
Sorry if this is a stupid question... I am self-taught, and I am
trying to shake all my bad coding habits.
Taint so Jochem. Try it.
--
PHP General Mailing List (http://www.php.net/) To
unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
imho
I agree always declare all kinds of variables before using
in the specific situation you have to consider that you are using two
different variables
rthe $foo inside the function and the $foo outside the function I think
its' correct to declar both, imho you should use different names
if you want to check all variables are properly declared you can turn on
error reporting for all during development and wwitch it off again in
production
2005/12/14, Michael Hulse <[EMAIL PROTECTED]>:
>
> Sorry if this question sounds noobish:
>
> $foo = array(); // Declare first, good practice.
> $foo = array('one', 'two', 'three');
>
> Using above as example, is it good to always declare the array first?
>
> I usually/always declare my arrays first, but sometimes I get a bit
> confused... for example:
>
> function give_foo() {
> $the_foo = array(); // Declare first, good practice.
> $the_foo = array('one', 'two', 'three');
> // Do some stuff here...
> return $the_foo;
> }
> $foo = give_foo(); // Declare $foo also?
>
> So, should I declare $foo as array and then give it the value of the
> function? Example:
>
> $foo = array(); // Declare first, good practice.
> $foo = give_foo();
>
> That seems kinda redundant. Thoughts?
>
> Sorry if this is a stupid question... I am self-taught, and I am trying
> to shake all my bad coding habits.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
In the examples I saw, when you used $new_array = $value (without the []), you
weren't going to get a proper copy of the array, as multiple people stated.
I'm curious why I didn't see (or maybe I just missed it) something like this:
$old_array = array('one', 'two', 'three', 'four');
$new_array = $old_array;
?
If you use a foreach() loop, you definitely need to use []:
foreach ($old_array as $value) {
$new_array[] = $value;
}
You'll loose all your key associations unless you do:
foreach ($old_array as $key => $value) {
$new_array[$key] = $value;
}
If you want to destroy your keys, you can use the first example of a foreach()
or you can also use:
$new_array = array_values($old_array);
I'm lazy so I don't tend to pre-define variable types although I should
probably get into the practice when there's a security need to do so.
So what was the original question again? hah
-TG
= = = Original message = = =
What I said was that arrays can be handled two different ways for loops.
1] By assigning the variable prior to the loop [i.e., $new_array= array();]
2] Or, by using inside the loop: $new_array[]= $value
Either one works. I've found, when the loop has lots of fancy stuff involving
the $new_array, it is useful to go ahead
a assign it before starting the loop.
Kilbride, James wrote:
> <?php
>
> $old_array= array('one','two','three','four');
> $new_array= array();
>
> foreach($old_array as $value)
>
> $new_array= $value;
>
> echo "$new_array";
> ?>
>
> The result of the echo is "four". Doing the same above with the [] after
> new_array returns the right result, a new array.(outputs Array). So what
> exactly where you saying 'Taint so' Al? I'm confused since Jochem's
> email about how to properly copy an array seems correct.
>
> James Kilbride
>
>
>>-----Original Message-----
>>From: Al [mailto:[EMAIL PROTECTED]
>>Sent: Wednesday, December 14, 2005 10:47 AM
>>To: [email protected]
>>Subject: Re: [PHP] Re: Declaring arrays? Good practice?
>>
>>Jochem Maas wrote:
>>
>>>Al wrote:
>>>
>>>
>>>>However....
>>>>
>>>>For loops:
>>>>
>>>>$new_array= array();
>>>>
>>>>foreach($old array as $value)
>>>>
>>>> $new_array= $value:
>>>>
>>>>
>>>>Otherwise, all you'll get it the last assignment of
>>
>>$new_array as a
>>
>>>>variable, not an array.
>>>
>>>
>>>which is exactly what you get if yuou run the code above -
>>
>>after the
>>
>>>foreach loop $new_array will be set to the value of the
>>
>>last item of
>>
>>>$old_array.
>>>
>>>regardless of whether you init the var you still have to use the
>>>square-bracket notation to add items to the array.
>>>
>>>
>>>>You can also use;
>>>>
>>>>foreach($old array as $value)
>>>>
>>>> $new_array[]= $value:
>>>>
>>>>
>>>>But sometimes, if the expression is a bit fancy in the
>>
>>loop and you
>>
>>>>are using $keys, it is easy to make a mistake.
>>>>
>>>>Al..........
>>>>
>>>>Michael Hulse wrote:
>>>>
>>>>
>>>>>Sorry if this question sounds noobish:
>>>>>
>>>>>$foo = array(); // Declare first, good practice.
>>>>>$foo = array('one', 'two', 'three');
>>>>>
>>>>>Using above as example, is it good to always declare the
>>
>>array first?
>>
>>>>>I usually/always declare my arrays first, but sometimes I
>>
>>get a bit
>>
>>>>>confused... for example:
>>>>>
>>>>>function give_foo()
>>>>> $the_foo = array(); // Declare first, good practice.
>>>>> $the_foo = array('one', 'two', 'three');
>>>>> // Do some stuff here...
>>>>> return $the_foo;
>>>>>
>>>>>$foo = give_foo(); // Declare $foo also?
>>>>>
>>>>>So, should I declare $foo as array and then give it the
>>
>>value of the
>>
>>>>>function? Example:
>>>>>
>>>>>$foo = array(); // Declare first, good practice.
>>>>>$foo = give_foo();
>>>>>
>>>>>That seems kinda redundant. Thoughts?
>>>>>
>>>>>Sorry if this is a stupid question... I am self-taught, and I am
>>>>>trying to shake all my bad coding habits.
>>>>
>>>>
>>>>
>>Taint so Jochem. Try it.
>>
>>--
>>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
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
On Dec 14, 2005, at 9:31 AM, <[EMAIL PROTECTED]> wrote:
I'm lazy so I don't tend to pre-define variable types although I
should probably get into the practice when there's a security need to
do so.
So what was the original question again? hah
Hehehe, looks like you answered it. :D
Thanks all for the input, it has been a very helpful read. ;)
Cheers,
Micky
--- End Message ---
--- Begin Message ---
Philip Hallstrom wrote:
I'm writing a content management application which saves file paths in
a database and allows users to search the database for those files.
Problem I'm having is that although the PHP script that handles the
database queries works fine, when the search results get to the
browser, all the paths are off limits.
I can't just move the photos inside the web folder as we're talking
tens of thousands of images that are already organized into a folder
structure that must be maintained as is.
Is there a way to allow the web page to see these photos?
The images are stored on a Windows box and all the web server stuff is
on a G5 Macintosh running OS 10.4 3 (in case that has any bearing on
the matter).
Depending on security issues you have two options.
Put a webserver on the Windows box and modify your search results to
link to the images using something like this:
<img src="http://windowsbox/getimage.php?path=/path/to/img.jpg">
Then put a "getimage.php" script on the windows box that does something
like:
<?php
readfile($_GET[path]);
?>
I would just like to add that you _must_ sanitize $_GET['path'], otherwise
stuff you don't want will get read.... like a passwd file or the secret
collection
of pr0n you have been hosting on the server at work ;-)
http://windowsbox/getimage.php?path=/etc/passwd">
If you can't (or don't want to) put the windows box on the internet,
then still do the above and then also do the same on the mac. Assuming
the mac can get to the windows box. If that mac can't, then you're hosed.
good luck
-philip
--- End Message ---
--- Begin Message ---
Hello there,
Goal: Preventing multiple user login using the same username & password
from different location (
Simoltanous Login)
Options Available:
1) IP Checking: One way to prevent multiple people from using the same
account to gain access to a
restricted area of a site is to store their IP address in a database
table, along with the "time()"
they first logged in. You would then have to check the users IP address
on subsequent pages against the
value stored in the database to make sure that the user is still using
the same IP to view the page. If
the user has a different IP, we would prevent the user from login in and
display a message saying "You
are Currently Logged In from Another Location! Please Log from the other
location and try again" (or
something like that). This check is usually done at given time intervals
(say every 5 minutes or so)
Problem with Method: Several Internet Service Providers like AOL, change
the users IP Address every few
minutes. So this could potentially lock your REAL user out of the system
as well. There are also some
problems with Proxy Based connections.
2) Session ID Tracking: A similar idea to method 1, except that you
would store the SESSION ID in the
database, and instead of checking the IP, you would then compare the
users SESSION ID to verify that
the user is still the same user. The advantage of thsi method is that it
does not depend on the users
IP. Therefore AOL users will not have a problem with this login system.
Problem with Method: Although the SESSION ID is unique for current
active user, it can be assigned by
server to any other later on. Plus you may have problems with Session ID
based login system, if you use
a shared Webhost.
3) Boolean Login Field: With this method, you would basically create a
boolean field in your database,
and set the value to TRUE if the user is logged in, or false if the user
is not. Again, to check if the
user is still logged in, you would have to use a timestamp like previous
methods to see if the user has
been inactive for more then a specific period of time, and reset the
Boolean database field value to
false if the user is inactive (This could basically either mean that the
user just closed his web
browser and left, or that he took a longer then usual lunch break and
forgot about your site).
Or if the browser crashes valid user is left in the muddle.
Problem with Method: The basic problem with this method (as with the
other two methods), is that if you
set a time period (say 5 minutes) to give the visitor to go to the next
page and verify that he is
still alive and on your site, if the visitor takes longer then 5 minutes
to move on to the next page,
he will be locked out of the system for ANOTHER 5 minutes (until the
system clears the hold on his
account).
THE QUESTION:
Here is my main question about this whole issue. Is there a better way
of performing this task that
will not require the setting of a time interval to see if the user is
still logged in? IS THERE A GOOD SOLUTION TO THIS ISSUE???
Many Thanks in advance,
Regards,
Sarith
--- End Message ---
--- Begin Message ---
Where I work, the system that was set up before I got here uses session ID and
a timeout of a couple of hours. I'm pretty sure that there's a good chance
that two people would not be issued the same session ID within a short period
of time. Certainly not within say 4 hours.
Maybe someone has a better way, but I'd say this works out ok for us so far.
-TG
= = = Original message = = =
Hello there,
Goal: Preventing multiple user login using the same username & password
from different location (
Simoltanous Login)
Options Available:
1) IP Checking: One way to prevent multiple people from using the same
account to gain access to a
restricted area of a site is to store their IP address in a database
table, along with the "time()"
they first logged in. You would then have to check the users IP address
on subsequent pages against the
value stored in the database to make sure that the user is still using
the same IP to view the page. If
the user has a different IP, we would prevent the user from login in and
display a message saying "You
are Currently Logged In from Another Location! Please Log from the other
location and try again" (or
something like that). This check is usually done at given time intervals
(say every 5 minutes or so)
Problem with Method: Several Internet Service Providers like AOL, change
the users IP Address every few
minutes. So this could potentially lock your REAL user out of the system
as well. There are also some
problems with Proxy Based connections.
2) Session ID Tracking: A similar idea to method 1, except that you
would store the SESSION ID in the
database, and instead of checking the IP, you would then compare the
users SESSION ID to verify that
the user is still the same user. The advantage of thsi method is that it
does not depend on the users
IP. Therefore AOL users will not have a problem with this login system.
Problem with Method: Although the SESSION ID is unique for current
active user, it can be assigned by
server to any other later on. Plus you may have problems with Session ID
based login system, if you use
a shared Webhost.
3) Boolean Login Field: With this method, you would basically create a
boolean field in your database,
and set the value to TRUE if the user is logged in, or false if the user
is not. Again, to check if the
user is still logged in, you would have to use a timestamp like previous
methods to see if the user has
been inactive for more then a specific period of time, and reset the
Boolean database field value to
false if the user is inactive (This could basically either mean that the
user just closed his web
browser and left, or that he took a longer then usual lunch break and
forgot about your site).
Or if the browser crashes valid user is left in the muddle.
Problem with Method: The basic problem with this method (as with the
other two methods), is that if you
set a time period (say 5 minutes) to give the visitor to go to the next
page and verify that he is
still alive and on your site, if the visitor takes longer then 5 minutes
to move on to the next page,
he will be locked out of the system for ANOTHER 5 minutes (until the
system clears the hold on his
account).
THE QUESTION:
Here is my main question about this whole issue. Is there a better way
of performing this task that
will not require the setting of a time interval to see if the user is
still logged in? IS THERE A GOOD SOLUTION TO THIS ISSUE???
Many Thanks in advance,
Regards,
Sarith
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
Hi all.
I've got a PHP script which does file uploads.
the files get uploaded fine but I see that the permission of the files are:
600
IE: Owner read and write.
In order for me to use the files, I would have to set the permissions on
each file, now for best practise would I set the permission once the
file is uploaded or is there something I can do before its uploaded?
usually when i have a file upload section all file permissions are fine,
this is the first time, so perhaps there is something with the current
permissions that is causing the permissions to be set to 600 when
uploaded, which if solved would allow me to not edit my PHP files.
any ideas?
thanks in advance
--
Angelo
--- End Message ---
--- Begin Message ---
we are looking for experienced php programemers in mumbai or bombay.
full time or freelance...
please contact at [EMAIL PROTECTED]
sumeet shroff
--- End Message ---
--- Begin Message ---
not quite PC, but why do you need to be in mumbai or bombay, is the
client located there?
mailing wrote:
we are looking for experienced php programemers in mumbai or bombay.
full time or freelance...
please contact at [EMAIL PROTECTED]
sumeet shroff
--- End Message ---
--- Begin Message ---
I have encountered a situation where I'm using the foreach() where I need to
assign new data to the $value in the foreach loop, foreach($x as $key ==>
$value). With PHP 5, you can do the ampersand to the $value but I'm using
PHP 4? So, how do you guys do it? I tried this sample code but it only work
in the child array but not the parent arrays... Food for Thought??
Thanks...
--code--
function XmlTreeCDataAsciiLoopThrough(&$tree)
{
foreach($tree as $key => $value)
{
if (is_array($value)) {
XmlTreeCDataAsciiLoopThrough($value);
} else {
if ($key == "VALUE") {
echo $tree[$key]." ###<br>";
$tree[$key] = "#############";
echo $tree[$key]." @@@<br>";
}
}
}
}
--code--
--- End Message ---
--- Begin Message ---
> XmlTreeCDataAsciiLoopThrough($value);
This should work:
> XmlTreeCDataAsciiLoopThrough($tree[$key]);
--- End Message ---
--- Begin Message ---
What? Why is this on the top of my email if it's two months old?
Sorry everyone for replying to a dead topic, I think. That or the
original poster has a messed up system clock.
--- End Message ---
--- Begin Message ---
I'm working on a private webmail (and other) system, and am struggling a
little with MIME mails. I've got a script to save all the attachments, but
the thing I can't figure out is how I decide which "part" is the main email
message itself (and hence which to display).
Oh and cheers for the info someone gave me the other day, it inspired me to
just connect to the pop3 server using a raw socket, SOOOOO much easier!!!
Cheers
Oli
--- End Message ---
--- Begin Message ---
hi,
Oli Howson wrote:
I'm working on a private webmail (and other) system, and am struggling a
little with MIME mails. I've got a script to save all the attachments, but
the thing I can't figure out is how I decide which "part" is the main email
message itself (and hence which to display).
Usually, the main part of the message, is the first non-attachment part
you find. So, if you have a tree like
mime1
|- text
|- mime2
|- attachment
|- another text (possibly mime3)
then the main part is text. Otherwise, just look for the first
text/plain or text/html mime-section you can find in the list (closest
to the top). If both a text/plain and a text/html section appear on the
same level, your script will need to decide which one to show (a lot of
mailers attach both a plain-text copy and an html copy of the text)
Oh and cheers for the info someone gave me the other day, it inspired me to
just connect to the pop3 server using a raw socket, SOOOOO much easier!!!
share the code please, I'm interested :)
Cheers
Oli
--- End Message ---
--- Begin Message ---
Is there any way of converting an array to an object of a type/class
other than stdClass?
I have been using the new PDO system and have experimented with
fetching rows with PDO::FETCH_CLASS
I would quite like to do the same with a plain array.
Any comments appreciated.
Cyril
--- End Message ---
--- Begin Message ---
Which of these are better Eclipse plugins for PHP Development? Or,
which advantages do each provide?
c
--
Chris Lott
--- End Message ---
--- Begin Message ---
I use PhpEdit and i'm very pleased, tryed eclipse .. and i must say i'm
not a fan :). Php developement never tryed.
Chris Lott wrote:
> Which of these are better Eclipse plugins for PHP Development? Or,
> which advantages do each provide?
>
> c
> --
> Chris Lott
>
--- End Message ---
--- Begin Message ---
sry, dumb answer :)
dave wrote:
> I use PhpEdit and i'm very pleased, tryed eclipse .. and i must say i'm
> not a fan :). Php developement never tryed.
>
> Chris Lott wrote:
>
>>Which of these are better Eclipse plugins for PHP Development? Or,
>>which advantages do each provide?
>>
>>c
>>--
>>Chris Lott
>>
>
>
--- End Message ---