OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 18 Mar 2005 00:45:28 -0000 Issue 3344

php-general-digest-helplists.php.net
Date: Thu Mar 17 2005 - 18:45:28 CST


php-general Digest 18 Mar 2005 00:45:28 -0000 Issue 3344

Topics (messages 210966 through 211003):

Re: multiple OR's
        210966 by: eoghan
        210970 by: AndreaD
        210972 by: anirudh dutt
        210978 by: Jeff Schmidt
        210997 by: Chris Shiflett

Data and time problem
        210967 by: virtualsoftware.gmail.com
        210973 by: kalinga

Re: SimpleXML and xpath woes
        210968 by: Simon Turvey

can I do a for each here??
        210969 by: AndreaD
        210971 by: Chris Ramsay
        210975 by: Marek Kilimajer
        210976 by: AndreaD
        210983 by: Jeff Schmidt
        210986 by: Jeff Schmidt
        210988 by: AndreaD
        210999 by: Chris Shiflett

Re: showing the decimal places
        210974 by: Jay Blanchard
        210991 by: Jochem Maas

function troubles...
        210977 by: William Stokes
        210980 by: Chris Ramsay

Re: Ensure only one instance of a script is running
        210979 by: Jeremiah Fisher

Re: db to xml using php
        210981 by: Jason Barnett

Re: Strange PHP5 message
        210982 by: Jason Barnett

Re: opt-in mail list best practice
        210984 by: Jason Barnett

Re: Session time out
        210985 by: Jason Barnett

Re: Session in URL [RESOLVED}
        210987 by: Mignon Hunter

Re: Encrypted 2.5+M files do upload, but don't create a record when stored as LongBlobs (PHP/Apache/MySQL)
        210989 by: Steven Altsman
        210992 by: Jason Barnett

Different approach?
        210990 by: John Taylor-Johnston

Re: PHP source code formatter for OS X
        210993 by: Jochem Maas

getting text with strange encodng
        210994 by: Diana Castillo
        210998 by: Chris Shiflett

Re: migrating to PHP 5 + Apache 2 from PHP 4.3.8 + Apache 1.3.33.
        210995 by: Rasmus Lerdorf

Re: file/array manipulation
        210996 by: Jochem Maas

Re: Files upload - Encrypt into a variable - Do not inject into db (PHP/Apache/MySQL)
        211000 by: Steven Altsman

Re: Help with dates
        211001 by: Jochem Maas

Re: FreeBSD php upgrade oddity - can't load dynamic librari es [RESOLVED]
        211002 by: Al Arzaga

Setting cookies for other domains
        211003 by: Brian Dunning

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


can do:
if ($name==andrea || $name==john)

On 17 Mar 2005, at 11:59, AndreaD wrote:

> if ($name==andrea) OR ($name==john)

attached mail follows:


This works...

if ($name == jim || andrea || tommy)

I must have had an extra ( somewhere.

AD

"AndreaD" <andrea.davidsonsilene.co.uk> wrote in message
news:20050317122507.34687.qmaillists.php.net...
> Looking for the most code efficient way to do multiple boolean OR's on one
> line
>
> if ($name==andrea) OR ($name==john)
>
> Ta
>
> AD

attached mail follows:


and if u've got several checks for just $name, u could use in_array
(http://php.net/in_array).

if (in_array($name, array('andrea', 'john', 'jane')))

it's case sensitive so if the array has all lower-case letters, u
might wanna use strtolower (http://php.net/strtolower) on $name.

for general cases of OR...
On Thu, 17 Mar 2005 12:32:20 +0000, eoghan <phpredry.net> wrote:
> can do:
> if ($name==andrea || $name==john)
>
> On 17 Mar 2005, at 11:59, AndreaD wrote:
> > if ($name==andrea) OR ($name==john)

--
]#
Anirudh Dutt

...pilot of the storm who leaves no trace
like thoughts inside a dream

attached mail follows:


AndreaD wrote:
> This works...
>

But not the way you think it does.

> if ($name == jim || andrea || tommy)
>

This if statement will first check to see if $name == "jim" (oh yeah,
you are missing quotes around jim, andrea, and tommy, by the way). Then,
it does *NOT* check to see if $name == andrea. Instead, what it does, is
it treats "andrea" as a seperate test condition. A simple value by
itself, with no logical operator, gets automatically cast to a boolean
value. Because the string "Andrea" is not empty ("") or "0", PHP casts
it as TRUE. (See
http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
for more details).

So, this conditional is always true (assuming andrea and tommy are
wrapped in string delimters so that they are strings; it could be
possible that you have defined constants called jim, andrea, and tommy,
in which case you don't need the quotes - in any case, the same basic
principle applies - the == operator only applies to jim). Even if $name
= 'Bob', your conditional will evaluate to TRUE, and your code block
will execute. I suspect this is not the behavior you want.

As an earlier poster suggested, the best way to do this would be to use
the in_array construct, which tests to see if the first value is in the
array specified as the second value.

if (in_array($name, array("jim", "andrea", "bob")))
{
//code here
}

Jeff Schmidt

attached mail follows:


AndreaD wrote:
> Looking for the most code efficient way to do multiple boolean OR's on one
> line
>
> if ($name==andrea) OR ($name==john)

If you put an opening brace after that, you'll get a parse error. You're
also treating andrea and john as constants, which I'm guessing isn't
what you mean. I think you were wanting:

if ($name == 'andrea' || $name == 'john')

If you have a bunch of these conditions, a switch might be convenient:

switch ($name)
{
     case 'andrea':
     case 'john':
     case 'chris':
     case 'rasmus':
     case 'andi':
     case 'zeev':
         echo 'The name was one of those';
         break;
     default:
         echo 'The name wasn't one of those';
}

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

attached mail follows:


Hi,
I have a mysql database where i store a user name and date when he registered. The date format is like this 2005-03-17 02:41:51.

How can i found out how many minutes passed from the date he registered till now.

Thanks in advance for your help !

attached mail follows:


store the date as a 'unix timestamp', so you can easily compare
the stored timestamp with the current timestamp, by doing a
simple calculation you can get the duration in minutes without
a headache.

http://www.php.net/time

vk.

On Thu, 17 Mar 2005 14:32:48 +0200, virtualsoftwaregmail.com
<virtualsoftwaregmail.com> wrote:
> Hi,
> I have a mysql database where i store a user name and date when he registered. The date format is like this 2005-03-17 02:41:51.
>
> How can i found out how many minutes passed from the date he registered till now.
>
> Thanks in advance for your help !
>

--
vk.

attached mail follows:


Rob Richards kindly sent me the following response via email - posting it here as he's not subscribed.

>
> You need to register a namespace for XPath since there's a default
> namesapce.
>
> $xml = simplexml_load_file('test.xml');
> /* Register arbitrary namesapce prefix for xpath*/
> $xml->registerXPathNamespace('p',
> 'http://webservices.amazon.com/AWSECommerceService/2005-02-23');
> $query = '//p:ItemLookupResponse';
> $result = $xml->xpath($query);
> var_dump($result);

Just to add to this: the registerXPathNamespace method is only present in CVS/snapshot builds and is
scheduled for the 5.1 release.

Cheers,

Simon

attached mail follows:


I have about 10 text boxes each taking in value (ages) , The code I have
checks for a value and if it is set it then sets the cookie to that value.
The else just clears the value. On the next page I use a foreach to get the
values but I think there must be a quicker way to collect the data appart
from 10 if-else staements.

if (isset($andrea){

setcookie("cookie[andrea]", "$andrea");
}

else {setcookie("cookie[$andrea]", "");

}

if (isset($james){

setcookie("cookie[james]", "$james");
}

else {setcookie("cookie[$james]", "");

}

AD

attached mail follows:


Difficult to be definitive without seeing your code, but I would be
tempted by the use of arrays...

cheers

attached mail follows:


AndreaD wrote:
> I have about 10 text boxes each taking in value (ages) , The code I have
> checks for a value and if it is set it then sets the cookie to that value.
> The else just clears the value. On the next page I use a foreach to get the
> values but I think there must be a quicker way to collect the data appart
> from 10 if-else staements.
>
> if (isset($andrea){
>
> setcookie("cookie[andrea]", "$andrea");
> }
>
> else {setcookie("cookie[$andrea]", "");
>
> }
>
>
> if (isset($james){
>
> setcookie("cookie[james]", "$james");
> }
>
> else {setcookie("cookie[$james]", "");
>
> }

$names = array('andrea', 'james', ...);

foreach($names as $name) {
   if (isset($_POST[$name]){
     setcookie("cookie[$name]", $_POST[$name]);
   } else {
     setcookie("cookie[$name]", "");
   }
}

attached mail follows:


Think what I want to do then is create two arrays, one for the values of the
age and one for the correponding name e.g.

$age = array() // this is the inputed textbox values
$name= array('john', 'bob', 'tim')

Then I need to assign the the ages to cookie of the persons name by using a
for or do-while loop.

loop{
if (isset($age[x])){setcookie("cookie[ $name[x] ]", "$age[x]");}
else {
setcookie("cookie[ name[x] ]", "");}

}end loop

Any suggestion how I would execute this would be fantactic. Not to worry I
can just have 10 lines if need be.

AD

"Chris Ramsay" <raz.netgmail.com> wrote in message
news:828f82cb05031704547c60c71mail.gmail.com...
> Difficult to be definitive without seeing your code, but I would be
> tempted by the use of arrays...
>
> cheers

attached mail follows:


I would be tempted to do the following.

First, I would setup the html form so that the text boxes are named
something like 'age[Andrea]', 'age[Bob]', etc. When the form submitted,
this will give you an array, accessible as $_POST['age'] (or
$_GET['age'] depending on whether you used POST or GET form submission
method).

This array would look like ("Andrea" => "25", "Bob" => "13", etc).

Then, I would use the following:

foreach($_POST['age'] as $name => $age)
{
   setcookie("cookie[$name]", $age);
}

Although, unfortunately, this approach you take of using seperate
cookies for all your different stored value is what I call cookie bloat.
I would suggest you look at PHP's built-in session handling facilities.

http://www.php.net/manual/en/ref.session.php

  The way the session handling works is, in a nutshell, at the start of
each of your scripts, you call session_start(). Then, you can access
session variables as $_SESSION['name']. You can use the isset() operator
to test to see if you already set a session variable, and you can use
any of the normal access methods to manipulating the variable. You
assign to it with $_SESSION['name'] = "value", you can get the value
just by using $_SESSION['name'] anywhere you would otherwise use a
variable or constant (e.g. if($_SESSION['ages']['Andrea'] > 18) {echo
"You have been selected for Jury duty.";}.

(All this assumes your hosting provider has setup PHP for you, and
configured the session handler. If that is not the case, then cookies
might be an easier way to go. Depending on how ambitious you feel, and
how much control you have of your site, you might also setup session
handling yourself - it's not incredibly difficult, just read the
documentation).

With that in mind, I would alter my above code to be the following:

foreach($_POST['age'] as $name => $age)
{
   $_SESSION['age'][$name] = $age;
}

AndreaD wrote:

> Think what I want to do then is create two arrays, one for the values of the
> age and one for the correponding name e.g.
>
> $age = array() // this is the inputed textbox values
> $name= array('john', 'bob', 'tim')
>
> Then I need to assign the the ages to cookie of the persons name by using a
> for or do-while loop.
>
> loop{
> if (isset($age[x])){setcookie("cookie[ $name[x] ]", "$age[x]");}
> else {
> setcookie("cookie[ name[x] ]", "");}
>
> }end loop
>
> Any suggestion how I would execute this would be fantactic. Not to worry I
> can just have 10 lines if need be.
>
> AD
>
>
> "Chris Ramsay" <raz.netgmail.com> wrote in message
> news:828f82cb05031704547c60c71mail.gmail.com...
>
>>Difficult to be definitive without seeing your code, but I would be
>>tempted by the use of arrays...
>>
>>cheers
>
>

attached mail follows:


Yeah, after hitting the send button, I looked again at what I sent and
realized something else. Having already caused PHP to put the stuff into
an array, by the way I suggested constructing the form, you can
eliminate the foreach loop, and just use the assignment operator to get
PHP to copy the array from $_POST to $_SESSION (although, you might want
to do some validation code, in which case you probably do want to use
the foreach block, so that you have a chance to validate each of the
submitted values, and the keys [sometimes it's usefull to validate the
keys, to check to see if someone has forged a form submission with
values other than what they are supposed to be using]).

But, assuming you aren't worried about validating, you could do like this:

$_SESSION['age'] = $_POST['age'];

But, honestly, I would still use the foreach loop, check the values of
$name and $age to make sure they are legal, and in the correct format,
and then assign them individually, as before.

Jeff

Jeff Schmidt wrote:

> I would be tempted to do the following.
>
> First, I would setup the html form so that the text boxes are named
> something like 'age[Andrea]', 'age[Bob]', etc. When the form submitted,
> this will give you an array, accessible as $_POST['age'] (or
> $_GET['age'] depending on whether you used POST or GET form submission
> method).
>
> This array would look like ("Andrea" => "25", "Bob" => "13", etc).
>
> Then, I would use the following:
>
> foreach($_POST['age'] as $name => $age)
> {
> setcookie("cookie[$name]", $age);
> }
>
>

[snip]

>
> With that in mind, I would alter my above code to be the following:
>
> foreach($_POST['age'] as $name => $age)
> {
> $_SESSION['age'][$name] = $age;
> }
>

attached mail follows:


Thanks for all your replies.

I liked Jeffs approach as it was more straightforward and using
age[Andrea] for the texboxes creates les confusion when doing the foreach
statement.

I didn't quite get the cookie vs session bit. Are you saying they [cookies]
use greater resources?

AD

"AndreaD" <andrea.davidsonsilene.co.uk> wrote in message
news:20050317124854.69647.qmaillists.php.net...
>I have about 10 text boxes each taking in value (ages) , The code I have
>checks for a value and if it is set it then sets the cookie to that value.
>The else just clears the value. On the next page I use a foreach to get the
>values but I think there must be a quicker way to collect the data appart
>from 10 if-else staements.
>
> if (isset($andrea){
>
> setcookie("cookie[andrea]", "$andrea");
> }
>
> else {setcookie("cookie[$andrea]", "");
>
> }
>
>
> if (isset($james){
>
> setcookie("cookie[james]", "$james");
> }
>
> else {setcookie("cookie[$james]", "");
>
> }
>
>
> AD

attached mail follows:


AndreaD wrote:
> I have about 10 text boxes each taking in value (ages), The code I have
> checks for a value and if it is set it then sets the cookie to that value.
> The else just clears the value. On the next page I use a foreach to get the
> values but I think there must be a quicker way to collect the data appart
> from 10 if-else staements.
>
> if (isset($andrea){
>
> setcookie("cookie[andrea]", "$andrea");
> }
>
> else {setcookie("cookie[$andrea]", "");
>
> }

Let's look at your two setcookie() calls:

setcookie("cookie[andrea]", "$andrea")
setcookie("cookie[$andrea]", "")

Just for debugging purposes, assume $andrea is initialized prior to this
as follows:

$andrea = 29;

So, your code says that you want a cookie with the following name and
value (available on the next request):

$_COOKIE['cookie[andrea]'] = 29;

Is that really what you want?

Of course, it's very odd that if $andrea is not set, you want a cookie
like this:

$_COOKIE['cookie[]'] = '';

In addition, you will be generating a notice, because you're using
$andrea in the name of the cookie, although you're first making certain
that $andrea isn't set.

I'm also a bit concerned about where $andrea originates. Is this coming
from the user, and you're trusting it? That's a very dangerous practice.

If you explain your problem, we might be able to offer some help.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

attached mail follows:


[snip]
when I define a number as

$number = 2.00

then echo it the number shows as 2. How can I get the two zeros to show?

This is not in any of my books but a fairly easy solution I'll bet!
[/snip]

http://www.php.net/number_format

attached mail follows:


rossaztechost.com wrote:
> when I define a number as
>
> $number = 2.00
>
> then echo it the number shows as 2. How can I get the two zeros to show?
>
> This is not in any of my books but a fairly easy solution I'll bet!

please consider php.net as your book too ;-)

have fun with the following:

<?php

$newLine = ($viaWeb = isset($_SERVER["HTTP_HOST"]))
         ? "<br />"
           : "\n";

$number = 2.00;

echo $number; echo $newLine;
var_dump( $number ); if ($viaWeb) { echo $newLine; }
printf("%0.2f", $number); echo $newLine;
echo number_format( $number, 2 ); echo $newLine;
echo sprintf("%01.2f", $number); echo $newLine;
echo number_format(123456789, 2, ",", " "); echo $newLine;

>
> R.
>

attached mail follows:


I don't know whats wrong with this. Can someone help please.

<?php
require "sql.php";

function shit_func($var)
{
$sql = "select * from users where sessionid='$sessionid' ";
$kys = mysql_query($sql);
$user = mysql_fetch_row($kys);
$k_tun = $user[0];
$ok1 = $user[4];
$ok2 = $user[5];
$ok3 = $user[6];
$ok4 = $user[7];
$ok5 = $user[8];
$ok6 = $user[9];
$ok7 = $user[10];

echo "$var";
echo "$k_tun";
echo "$ok1";
echo "$ok2";
echo "$ok3";
echo "$ok4";
echo "$ok5";
echo "$ok6";
echo "$ok7";
}
$test=shaisse;
shit_func($test);
?>

This will print: "shaisse" but nothing else. I need to know why the other
variables won't print. The sql query worksand echoes work if not used in
function. I tested it in an other file and it worked but when I put it in a
function it doesn't work.

Help Appreciated!
Thanks
-Will

attached mail follows:


Will

Whatever you are making available in the required file sql.php, it is
not accessible by the function shit_func. Define the connection string
or whatever as a global inside function shit_func and it should work,
else make the connection within the function - not such a good idea...

chris

attached mail follows:


Test for a lock file when the script starts, and remove it when the
script ends. This isn't 100% reliable, but it's the typical solution to
this problem. If the script fails, the lock file may not be removed
(ever have a Mozilla browser crash and tell you the default profile is
locked?), so be careful with your error handling!

<?php

// test for lock file
if ( !$f = fopen( 'lock', 'r')) {
        // touch the lock file
        $f = fopen( 'lock', 'w');
        fwrite( $f, 'lock');
        fclose( $f);

} else {
        // lock file exists; another instance must be running (we hope)
        echo 'Error: An instance of this script is already running!';
        exit( 1);

}

/* script stuff */

// remove the lock file for the next instance
unlink( 'lock');

?>

Shaun wrote:
> Hi,
>
> I have a script that inserts data from files uploaded to our server. I need
> to make sure that only one instance of this script runs at anyone time, can
> anyone tell me how I can do this?
>
> Many thanks

attached mail follows:


K Karthik wrote:
...
> i downloaded the zip from
> http://php.chregu.tv/sql2xml/. and then i couldnt know what i am suppose
> to do..
> when i tried running the file am getting error
>
> Fatal error: main() [function.require]: Failed opening required
> 'XML/sql2xml.php' (include_path='.:/usr/local/lib/php') in
> /home/kkarthik/web/XML_sql2xml-0.3.2/sql2xml_ext.php on line 20

Apparently PHP looked for XML/sql2xml.php in the folder . and the folder
/usr/local/lib/php. However, it wasn't in either of those places. So
either change your include_path or move the include to a directory in
your include_path.

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

attached mail follows:


Andrei Verovski wrote:
> Hi, Jason,
>
> Thanks a lot for suggestion. Does it mean that I have tried to
> serialize some object (like adodb db object)? How I can eliminate this?
> I really cannot find where this object or whatever else is going to be
> serailized. The problematic line of code just serialized an array.
>
...

Yes, you tried to serialize some object. But rather than *not*
serializing the object, what you really want to do is to fix your
__sleep function. Serializing objects is "A Good Thing." (tm)

I don't know what your class is, but you need __sleep to return an array
of class properties. Certainly you can look at the last code example
that I provided and figure out how to do that. Or at least I hope that
you can ;)

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

attached mail follows:


Scott Haneda wrote:
...
> I use it to create HTML emails, send them to 1000's of people. I think I
> did a test to 30K or so, it handled it fine using mail locally.

HTML emails [shudder]

> As for tracking, what we do is embed a image bug in the html and track when
> that loads, it is getting less reliable in todays anti spam world, but in my
> case these are paying subscribers so they generally want to get these
> emails.

[shudder]
The above paragraph is why I abhor HTML emails, and why I am glad that
Mozilla lets me block all remote images (and click to view if I *really*
want to see them).

>
> To track your users, at least the bounces we set the bounce address
> (return-path) to mysql_user_iddomain.com and POP check domain.com every few
> seconds. We then scan for the bounce address and mark that user as bouncing
> x times, if they go over y we cancel the account.

Now this is interesting... so you're telling me that all I have to do to
get you to stop emailing me, is to bounce back all of your messages?
Sure I'll have to forge a few headers to make it look like the mail
server daemon didn't recognize my address... but THAT sounds like time
well spent!!!

OK, OK, I'm being a little harsh here. Because after all you're sending
emails to customers that have at least opted-in (or so I hope). But
there are so many shady ways of getting someone to opt-in, or making it
hard to opt-out, or just plain harvesting emails and ignoring the wishes
of the users.

So yeah, sometimes when I hear about these things it just rubs me the
wrong way. To anyone reading this: please use these techniques
judiciously if you use them at all.

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

attached mail follows:


Jacques wrote:
> Is session time measured in seconds or minutes?
>

seconds

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

attached mail follows:


I had my admin change the
session.use_trans_sid = 1
to =0
no more sess ID in the URL - woo hoo

I guess this has to be 0 or in later versions 4.3.0
session.use_only_cookies = 1

*********************************************
Hello

I have tested this app on my machine but it doesnt do this - but when testing on development server, my script is displaying the session in the url. I was reading in man about session.use_only_cookies can keep this from happening but the dev server has php 4.1.2

Is there another way to stop this?

My script is such:

 while($row = mysql_fetch_row($res))
        {
                echo "<li><a href = sess_downloads_p2.php?$row[0]>$row[1]</a></li>";
        }

where $row[0] is a filename like filename.pdf

But when sess_download_p2.php loads in browser the URL has ...&PHPSESSID=(rand number)

Thanks for any help

attached mail follows:


This may be a stupid question. If it is, could somebody do a one line reply
of "it is." That way I will know to turn my attention elsewhere.

I've gone through about 45 pages of archives trying to glean anything useful
out of it, and either it's the same answer or the version is about 4 years
out of date.

-----Original Message-----
From: Steven Altsman [mailto:webphpefastfunding.com]
Sent: Wednesday, March 16, 2005 12:15 PM
To: php-generallists.php.net; usershttpd.apache.org
Subject: [PHP] Encrypted 2.5+M files do upload, but don't create a record
when stored as LongBlobs (PHP/Apache/MySQL)

Files under 2.5 megs will go into the database just fine, any thing over
that will return the page without errors, but will not be injected into the
database. Not even a record is created.

Edited PHP.INI to allow up to 40M of data to be uploaded. Set the script
timeout to be 9000 seconds. Set the script operational memory to 80M. I
did a print_r of $_FILES and the results show that there is a file in the
tmp directory, but I'm not sure after that if there is a problem with mcrypt
or MySQL. I did read something about a limitation of MySQL and max packet
size between server and client, but only 4.1 or less is mentioned with that.
I also switched from the fopen/fread combo and did file_get_contents
instead, as it was recommended to be more efficient.

http://us4.php.net/fopen
http://us4.php.net/fread
http://us4.php.net/file_get_contents
http://us3.php.net/mcrypt
http://us3.php.net/features.file-upload
http://us3.php.net/print_r

http://www.ispirer.com/doc/sqlways38/Output/SQLWays-1-195.html
http://www.totalchoicehosting.com/forums/lofiversion/index.php/t10276.html
http://www.chipmunk-scripts.com/board/index.php?forumID=27&ID=1674
http://scripts.franciscocharrua.com/database-file-upload-download.php
http://www.hotscripts.com/Detailed/33694.html

http://www.google.com

If there is any other links to M's that I haven't R'ed, please let me know.
Otherwise I'm clueless. Google gives me a metric tonne of information, but
it is mostly people asking the same question I am with recommendations on
editing the PHP.INI. Obviously this is a useful script that many people
have written in their own way for their own needs, and I'm sure they've run
into the same problem I'm encountering now.

Using MySQL 5.0.2, PHP 5, newest mcrypt, mhash, Apache 2, FC 3, it is on
port 443 with a valid SSL cert, and if you need to know any other version or
variable info I will gladly provide it.

-=-=-=-=-=-=- /docs/phpinfo.php -=-=-=-=-=-

allow_call_time_pass_reference On On
allow_url_fopen On On
always_populate_raw_post_data Off Off

8< -- Snip Snip --- 8<

version_comment Official MySQL RPM
version_compile_machine i686
version_compile_os pc-linux
wait_timeout 28800

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

attached mail follows:


Steven Altsman wrote:
> This may be a stupid question. If it is, could somebody do a one line reply
> of "it is." That way I will know to turn my attention elsewhere.
>
...

It's not a stupid question, it's just that the people that have read it
so far (including me) don't really know the answer. I seem to recall
that Raditha Dissanayake had an upload script that let you do larger
uploads... just look in the archives for his messages and look for the
link in his signature.

HTH

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins

attached mail follows:


Hi,

I've read:

> http://dev.mysql.com/doc/mysql/en/create-table.html

Would anyone code/approach this differently?

#################################################
$server = "localhost";
$user = "myname";
$pass = "mypass";
$db = "mydb";
$table = "demo_assignment1";

#################################################
$myconnection = mysql_connect($server,$user,$pass);

#################################################
$sql = "CREATE TABLE IF NOT EXISTS `demo_assignment1` (
`StudentNumber` varchar(8) NOT NULL default '',
`Exercise1` varchar(100) NOT NULL default '',
`Exercise2` varchar(100) NOT NULL default '',
`TimeStamp` timestamp(14) NOT NULL,
PRIMARY KEY (`TimeStamp`)
) TYPE=MyISAM COMMENT='place something here';";

mysql_select_db($db,$myconnection);
mysql_query($sql) or die(print mysql_error());

#################################################
$sql = "INSERT INTO $table
(StudentNumber,Exercise1,Exercise2) values
('$StudentNumber','$Exercise1','$Exercise2')";

mysql_select_db($db,$myconnection);
mysql_query($sql) or die(print mysql_error());

mysql_close($myconnection);

attached mail follows:


DuSTiN KRySaK wrote:
> Does anyone know of a PHP source code formatter to clean up sloppy code
> that runs on OS X?

maybe the php tidy extension works?
http://php.net/tidy

>
> d
>

attached mail follows:


Does anyone know what kind of string encoding this is :
&reg&reg
mA&reg
and how can I decode this?

--
Diana Castillo
Global Reservas, S.L.
C/Granvia 22 dcdo 4-dcha
28013 Madrid-Spain
Tel : 00-34-913604039 Ext 216
Fax : 00-34-915228673
email: dianahotelkey.com
Web : http://www.hotelkey.com
      http://www.destinia.com

attached mail follows:


Diana Castillo wrote:
> Does anyone know what kind of string encoding this is :
> &reg&reg
> mA&reg
> and how can I decode this?

That looks almost like an HTML entity:

&reg;

Assuming that's what it is, and you just left off the semicolon, you can
decode it with this:

html_entity_decode()

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

attached mail follows:


symbulos partners wrote:
> Dear friends,
>
> we would like to migrate a server where we host several websites (in virtual
> hosting) to PHP 5 with Apache 2.
>
> Technical support at the hosting provider told us there are still problems
> about safety of threads on php 5 + Apache 2 (management of memory). They
> would propose to migrate Apache to the pre-fork version in order to avoid
> these problems (but we would be unable to use all the features of Apache
> 2).
>
> Is that right?

Yes, if you are going to use Apache2, use the prefork MPM.

-Rasmus

attached mail follows:


Mignon Hunter wrote:
> Ok I got this to work but I'm not sure how -- and am having trouble re-producing the data:
>
> My script I have so far is:
>
> $lines = file('test2.csv');
> foreach ($lines as $line) {
> $line_split = explode(",", $line);
> if(!(empty($line_split[0]) ) ){
> //echo "I'm not empty";
> $new_array = array(
> $line_split[0] => $line_split[1]
> );
> }
> print("<pre>");
> print_r($new_array);
> print("</pre>");
> //echo "<tr><td>" . $new_array[0] . "</td><td>" . $new_array[1] . "</td></tr>";// this doesnt work
> }
>
> Here's what the printed format spits out (abbreviated):
>
> Array
> (
> [R] => "ABC company
> )
> Array
> (
> [R] => "ABC company
> )
> Array
> (
> [R] => "ABC company
> )
> Array
> (
> [R] => "ABC company
> )
> Array
> (
> [O] => XYZ company
> )
> Array
> (
> [O] => XYZ company
> )
> Array
> (
> [O] => XYZ company
> )
> Array
> (
> [O] => XYZ company
> )
>
> So - I'm getting the write letters assigned to write companys which is great. But my echo line:
>
> echo "<tr><td>" . $new_array[0] . "</td><td>" . $new_array[1] . "</td></tr>";// this doesnt work

given the array you printed above:

<?php

foreach ($new_array as $k => $v) {
        echo "<tr><td>{$k}</td><td>{$v}</td></tr>";
}

>
> Do I have several arrays or a multidim array?

you create a single array for each line of the csv file. each array
contains one item. what you have done is assign the first field's value as the key of the
array item, and the second field's value as the array items value.

$t = array( "R" => "ABC company"); // array with 1 item, using associative key
var_dump($t[ "R" ],$t[ 0 ]);

$t = array( "R" , "ABC company"); // array with 2 items, using implicit numeric keys
var_dump($t[ "R" ],$t[ 0 ]);

>
> Thanks for any guidance
>
>
>>>>"Richard Lynch" <ceol-i-e.com> 03/15/05 10:39AM >>>
>
>
>>Hello
>>
>>I'm trying to manipulate a text(.csv) file using php. I've read the file
>>and can print each line,
>> but I need to write where column A is missing
>>
>>ColumnA ColumnB
>>
>>R ABC company
>> ABC company
>> ABC company
>> ABC company
>>O XYZ company
>> XYZ company
>> XYZ company
>> XYZ company
>>
>>What I need to do is write a while loop (I think) to interate through the
>>lines and populate ColumnA
>>while ColumnB equals $var (ABC company, XYZ company), so that I end up
>>with:
>>
>>ColumnA ColumnB
>>
>>R ABC company
>>R ABC company
>>R ABC company
>>R ABC company
>>O XYZ company
>>O XYZ company
>>O XYZ company
>>O XYZ company
>>
>>Is this possible. What I've got so far to print out the file:
>>
>>$lines = file('test2.csv');
>>
>
>
> $category = '';
>
>
>>// Loop through our array, and show line and numbers too.
>>foreach ($lines as $line_num => $line) {
>> echo "Line #<b>{$line_num}</b> : " . $line . "<br />\n";
>
>
> //Assuming it's the FIRST character of each line that has space or category:
> //Check first character:
> if ($line[0] != ' ' && $line[0] != "\t"){
> $category = $line[0];
> }
>
> echo "$category\t", trim(substr($line, 1)), "<br />\n";
>
>
>>}
>>
>>
>>Thanks in advance
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>

attached mail follows:


Yes, the link is http://www.radinks.com/upload/config.php

file_uploads = On
upload_max_filesize = 40M
max_input_time = 9000 (seconds)
memory_limit (not limited, per handload config, from source)
max_execution_time = 9000 (seconds)
post_max_size = 40M

also, hidden INPUT tag MAX_FILE_SIZE with value="40000", which I'm guessing
needs it in kilobytes.

Radditha has a pretty sweet upload script going on there.. however, not sure
if it contains the same security requirements I've got.

Per GLBA requirements, my data has to be stored no more than 48 hours and
must be encrypted with 128-bit or higher algorithms. I'm starting to
suspect that I have more lists I've got to sign up with, as it may be MCRYPT
or MySQL that is barfing because of it.

If that is all I can tweak in PHP, then I'm definitely hitting a dead-end on
this list.

Thank you for your time.

-----Original Message-----
From: Jason Barnett [mailto:jason.barnetttelesuite.com]
Sent: Thursday, March 17, 2005 10:35 AM
To: php-generallists.php.net
Subject: Re: [PHP] Encrypted 2.5+M files do upload, but don't create a
recordwhen stored as LongBlobs (PHP/Apache/MySQL)

Steven Altsman wrote:
> This may be a stupid question. If it is, could somebody do a one line
reply
> of "it is." That way I will know to turn my attention elsewhere.
>
...

It's not a stupid question, it's just that the people that have read it
so far (including me) don't really know the answer. I seem to recall
that Raditha Dissanayake had an upload script that let you do larger
uploads... just look in the archives for his messages and look for the
link in his signature.

HTH

attached mail follows:


Kevin wrote:
> Dear mr. Maas,

no need for 'mr' :-)

>
> First of all my appologies for taking so long to respond. I had a family
> death to attend to.

my condolences.
there is no need to apologise in any case.

...

>>
>>why is OBC relevant, I read later on that you take the start of egyptian
>>civilization as zero. is that not much earlier.
>
>
> Well it's relevant to make a baseline so that I can calculate the difference
> from then until now. That's the only reason thusfar.
>
>
>>whats the structure of the egyptian|rpg calendar?
>
>
> A year consists of 769 days, 13 months of 63 days a month, except for month
> 13 which has 14 days. Every month has 7 weeks of 9 days, of course month 13
> is the exception. A day is 24 hours.
>

a few thoughts:

1. you have a date in both calendars which represent the same day?
and/or rather what is day zero in the egyptian calendar in the gregorian
calendar?

2. maybe you should store the date internally as number of days since zero,
where zero is the first day on the egyptian calendar ......

er, checking this thread again, Richard Lynch puts it better than I can so
I'll just let you read his answer (again?) and hope it helps!

oh one last thing: I notice that in the function you posted you did this:

     # Calculating the year in Egypt.
     $yr_Egypt = floor($EgyptianDays / 769);
     # Calculating the Month in Egypt.
     $mnt_Egypt = round( ($EgyptianDays-($yr_Egypt*769)) / 63 );
     # Calculating the Day in Egypt.
     $dy_Egypt = round( $EgyptianDays - (($yr_Egypt * 769) + ($mnt_Egypt * 63)) );
     # Filling the date array variable with the day, month and year of the
     Egyptian calendar.
     $ec_date["Day"] = $dy_Egypt;
     $ec_date["Month"] = $mnt_Egypt;
     $ec_date["Year"] = $yr_Egypt;
     # Returning the Calculated date.
     return $ec_date;

which could be written more succinctly as:

     /* Calculating the year,month,day in Egypt and returning. */
     return array (
             "Year" => ($y = floor( $EgyptianDays / 769 )),
             "Month" => ($m = round( ($EgyptianDays - ($y * 769)) / 63 )),
             "Day" => round( $EgyptianDays - (($y * 769) + ($m * 63)) ),
     );

that might inspire you to use less variables in your code, which is a good thing - but in this
case completely beside the point. whats less beside the point is that you use floor() for the year
and round() for the day and month, I wonder if it helps if you use floor() for all 3?

beware of floating point rounding errors, compare:

<?php

$EgyptianDays = 10345;

var_dump(

array(
     "Year" => ($y = floor( $EgyptianDays / 769 )),
     "Month" => ($m = floor( ($EgyptianDays - ($y * 769)) / 63 )),
     "Day" => floor( $EgyptianDays - (($y * 769) + ($m * 63)) ),
),

array(
     "Year" => ($y = floor( $EgyptianDays / 769 )),
     "Month" => ($m = round( ($EgyptianDays - ($y * 769)) / 63 )),
     "Day" => round( $EgyptianDays - (($y * 769) + ($m * 63)) ),
)

);

?>

kind regards,
Jochem

attached mail follows:


For the sake of someone who may benefit from this info:

I resolved this by removing the file
/usr/local/etc/php/extensions.ini
and then reinstalling the php5 base
and then reinstalling php5-extensions

-----Original Message-----
From: Al Arzaga
Sent: Wednesday, March 16, 2005 10:34 PM
To: php-generallists.php.net
Subject: [PHP] FreeBSD php upgrade oddity - can't load dynamic libraries

I'm running FreeBSD 5.2.1, and last night I cvsupped to the latest
ports.

This afternoon, I proceeded to upgrade PHP from 5.0.1 to 5.0.3.
But I kept getting these errors when restarting apache that it could not
find various shared libraries in /usr/local/lib/php/20041030

I see that I'm supposed to have such a directory, but what I do have is
a /usr/local/lib/php/20040412 instead. (Pointing to that directory in
php.ini clearly is not the answer.)

Similar errors appear when running from the command line:

[kungpao:~]$ php -v
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/ctype.so' - Cannot open
&quot;/usr/local/lib/php/20041030/ctype.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/simplexml.so' - Cannot open
&quot;/usr/local/lib/php/20041030/simplexml.so&quot; in Unknown on line
0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/dom.so' - Cannot open
&quot;/usr/local/lib/php/20041030/dom.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/gd.so' - Cannot open
&quot;/usr/local/lib/php/20041030/gd.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/iconv.so' - Cannot open
&quot;/usr/local/lib/php/20041030/iconv.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/ldap.so' - Cannot open
&quot;/usr/local/lib/php/20041030/ldap.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/mysql.so' - Cannot open
&quot;/usr/local/lib/php/20041030/mysql.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/odbc.so' - Cannot open
&quot;/usr/local/lib/php/20041030/odbc.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/oracle.so' - Cannot open
&quot;/usr/local/lib/php/20041030/oracle.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/pcre.so' - Cannot open
&quot;/usr/local/lib/php/20041030/pcre.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/pdf.so' - Cannot open
&quot;/usr/local/lib/php/20041030/pdf.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/posix.so' - Cannot open
&quot;/usr/local/lib/php/20041030/posix.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/session.so' - Cannot open
&quot;/usr/local/lib/php/20041030/session.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/sqlite.so' - Cannot open
&quot;/usr/local/lib/php/20041030/sqlite.so&quot; in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/tokenizer.so' - Cannot open
&quot;/usr/local/lib/php/20041030/tokenizer.so&quot; in Unknown on line
0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030/xml.so' - Cannot open
&quot;/usr/local/lib/php/20041030/xml.so&quot; in Unknown on line 0
PHP 5.0.3 (cli) (built: Mar 16 2005 20:27:24)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
[kungpao:~]$

I've tried re-installing just the base install without any php
configurations but to no avail.

Can anyone provide some insight on how I may solve this?

-Al

attached mail follows:


I've always known that you can specify a domain when you set a cookie,
and for kicks I experimented with a test page setting a cookie for the
yahoo.com. Seems to me that browsers wouldn't allow this as it could
create any number of security problems. I tried the following code, and
the yahoo cookie did not get set, as I expected, and the
briandunning.com cookie did (that's my site). I made sure that my
browser's settings were set to allow all cookies, including those from
other sites.

<?php
setcookie('test', 'anything', time()+31536000, '/', '.yahoo.com');
setcookie('test', 'anything', time()+31536000, '/',
'.briandunning.com');
?>

Question: why didn't this work, is it supposed to work the way I was
trying, and if not, then what is that domain variable there for???

- Brian