php-general Digest 7 Dec 2003 15:26:52 -0000 Issue 2459

Topics (messages 172111 through 172129):

Random Numbers..
        172111 by: TheHeadSage
        172115 by: Alex
        172116 by: Burrito Warrior

Re: Random Numbers.. [Solved, Ignore]
        172112 by: TheHeadSage

Re: Check type of uploaded file
        172113 by: Richard Davey
        172121 by: Gerard Samuel

Re: Apache 2 + PHP
        172114 by: Yves Arsenault

Help!session problem!
        172117 by: ÎÚÓÐ ÎÞ
        172119 by: Chris Shiflett

Persistence of session files
        172118 by: Pablo Gosse
        172120 by: Chris Shiflett
        172125 by: Justin French

getimagesize() & MySQL Image Storage (Running functions on contents of variables)
        172122 by: Galen
        172126 by: Justin Patrin
        172127 by: Justin Patrin

Re: PHP and IIS
        172123 by: V.B. de Haan
        172124 by: V.B. de Haan
        172129 by: John W. Holmes

Re: MySQL Dump using PHP
        172128 by: Cesar Aracena

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 ---
Hey,

I've got a script which used to generate a random quote. It worked fine
untill this problem occurred..

Say we have 4 quotes with QuoteID's of 1 through to 4
The script would grab a number of rows, and generate a random number
between 1 and this value (being 4 in this case) This worked fine untill,
one of the quotes was removed and another added, leaving 4 quotes once
again, but the last one had an ID of 5. The problem is the Random number
generated is between 1 and 4, so the final quote is never shown..

I tried using the RAND() function in the MySQL statement it's self, but
it's not random enough...

Then I thought of doing this:

Select all the Quote ID's from the DB.
Store them in an Array.
Generate a random number between 1 and the last ID.
If the Random Number matches a Quote ID, then display the quote,
otherwise Generate another

But I couldn't get the code to work. Any suggestions on either how to
write the above, or made the MySQL RAND() function, more random?

--- End Message ---
--- Begin Message --- Theheadsage wrote:
Hey,

I've got a script which used to generate a random quote. It worked fine
untill this problem occurred..

Say we have 4 quotes with QuoteID's of 1 through to 4
The script would grab a number of rows, and generate a random number
between 1 and this value (being 4 in this case) This worked fine untill,
one of the quotes was removed and another added, leaving 4 quotes once
again, but the last one had an ID of 5. The problem is the Random number
generated is between 1 and 4, so the final quote is never shown..

I tried using the RAND() function in the MySQL statement it's self, but
it's not random enough...

Then I thought of doing this:

Select all the Quote ID's from the DB.
Store them in an Array.
Generate a random number between 1 and the last ID.
If the Random Number matches a Quote ID, then display the quote,
otherwise Generate another

But I couldn't get the code to work. Any suggestions on either how to
write the above, or made the MySQL RAND() function, more random?

how about if ($randnumber == 4) $randnumber++; ?

--- End Message ---
--- Begin Message ---
No, I wouldn't do that.  What if another quote gets deleted.  The new
assigned
QuoteID would be 6 and your solution wouldn't work.

This would:
/* selecting a random record, where n = 1.  Works fine on small tables */
mysql> SELECT value FROM table ORDER BY RAND() LIMIT n;

/* selecting a random record.  This is good on large tables if numbering
sequence is used */
mysql> SET @val = FLOOR(RAND() * n) + 1;
mysql> SELECT value FROM table WHERE ID = @val;

-----Original Message-----
From: Alex [mailto:[EMAIL PROTECTED]
Sent: Sunday, December 07, 2003 12:00 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Random Numbers..


Theheadsage wrote:
> Hey,
>
> I've got a script which used to generate a random quote. It worked fine
> untill this problem occurred..
>
> Say we have 4 quotes with QuoteID's of 1 through to 4
> The script would grab a number of rows, and generate a random number
> between 1 and this value (being 4 in this case) This worked fine untill,
> one of the quotes was removed and another added, leaving 4 quotes once
> again, but the last one had an ID of 5. The problem is the Random number
> generated is between 1 and 4, so the final quote is never shown..
>
> I tried using the RAND() function in the MySQL statement it's self, but
> it's not random enough...
>
> Then I thought of doing this:
>
> Select all the Quote ID's from the DB.
> Store them in an Array.
> Generate a random number between 1 and the last ID.
> If the Random Number matches a Quote ID, then display the quote,
> otherwise Generate another
>
> But I couldn't get the code to work. Any suggestions on either how to
> write the above, or made the MySQL RAND() function, more random?

how about if ($randnumber == 4) $randnumber++; ?

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

--- End Message ---
--- Begin Message ---
Sorry for this e-mail, When I wrote this, my e-mail server was down, and it
was archived for sending. By the time the e-mail server was restored, I had
solved this problem.

- TheHeadSage
----- Original Message -----
From: "TheHeadSage" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, December 07, 2003 2:39 PM
Subject: [PHP] Random Numbers..


> Hey,
>
> I've got a script which used to generate a random quote. It worked fine
> untill this problem occurred..
>
> Say we have 4 quotes with QuoteID's of 1 through to 4
> The script would grab a number of rows, and generate a random number
> between 1 and this value (being 4 in this case) This worked fine untill,
> one of the quotes was removed and another added, leaving 4 quotes once
> again, but the last one had an ID of 5. The problem is the Random number
> generated is between 1 and 4, so the final quote is never shown..
>
> I tried using the RAND() function in the MySQL statement it's self, but
> it's not random enough...
>
> Then I thought of doing this:
>
> Select all the Quote ID's from the DB.
> Store them in an Array.
> Generate a random number between 1 and the last ID.
> If the Random Number matches a Quote ID, then display the quote,
> otherwise Generate another
>
> But I couldn't get the code to work. Any suggestions on either how to
> write the above, or made the MySQL RAND() function, more random?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Hello Bob,

Sunday, December 7, 2003, 1:00:44 AM, you wrote:

BH> I want to test an uploaded file to see if it is a text file, but I don't want
BH> to rely on the presence of an os command such as 'file.'  Is there a
BH> straightforward way to do this within PHP?  Thanks in advance.

Yes, check the $_FILES['userfile']['type'] after upload.

-- 
Best regards,
 Richard                            mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
On Saturday 06 December 2003 11:01 pm, Richard Davey wrote:
> Yes, check the $_FILES['userfile']['type'] after upload.
>
That can be spoofed.
There isn't really a way to determine file types...

--- End Message ---
--- Begin Message ---
Thanks to all who replied!

I will try to avoid using PHP 4 on Apache 2.

Does PHP 5 look like it will suit apache 2 for production?

Yves Arsenault
Carrefour Infotech
5, Acadian Dr.
Charlottetown, PEI
C1C 1M2
[EMAIL PROTECTED]
(902)368-1895 ext.242


-----Original Message-----
From: Mike Morton [mailto:[EMAIL PROTECTED] 
Sent: December 6, 2003 9:17 AM
To: Yves Arsenault; PHP-General
Subject: Re: [PHP] Apache 2 + PHP

Yves:

I am not sure of the exact technical issues that affect it, but when I
was
forced to use it in a production environment (does anyone actually admit
to
CHOOSING to use it?  anyway....) I received a lot of errors on includes,
intermittently.  This was most noticable when using phpmyadmin - but it
was
noticed throughout the application.  Errors including a file, then you
refresh and there are no errors.

In general the webserver was very unstable, prone to hanging processes
and
needing the webserver stopped and restarted.  In the beginning it was no
big
deal - once twice a week, but in the last 3 weeks it has been 5-6 times
a
day.

We just switched to Apache 1.3.2 (using PHP 4.3.4 on both machines.) and
we
have had 0 problems across the board in 3 days of operation now.

So there you go - if you are OK with instability then go for it - if
not,
choose Apache 1.3.x

PS.  Anyone out there know/work with PLESK?  6.0 comes with Apache 2.0
and
PHP 4.3.something - I want to 'downgrade' it to apache 1.3 - but *shrug*
no
idea.  If there is anyone out there that has done It successfully, msg
me
offline to chat.  WHY OH WHY do these companies not work WITH the php
community?  If only they had asked....  Itools is the same way (server
manager for Mac OSX - for the love of GOD DO NOT EVER USE IT!!!!! That
is
what was forced upon us and caused the above problems - you could not
use it
unless you used Apache 2, and they 'said' that there are no
'instabilities'
with PHP - either they lied or just have a terrible QC division!!!)

On 12/5/03 1:00 PM, "Yves Arsenault" <[EMAIL PROTECTED]> wrote:

> 
> Would anyone know of the issues that might affect PHP 4.3.4 and Apache
> 2.0.48 ?
> 
> Thanks,
> 
> Yves
> 
> -----Original Message-----
> From: Martin Hudec [mailto:[EMAIL PROTECTED]
> Sent: 5 décembre 2003 10:52
> To: PHP-General
> Subject: Re: [PHP] Apache 2 + PHP
> 
> 
> Hi there,
> 
> when I had Gentoo Linux, I was using Apache 2.0.48 with PHP 4.3.4
installed
> from Gentoo portage. It was running <10 smallscale php/mysql based
> virtualhosts without any difficulties.
> 
> On Friday 05 December 2003 15:24, Yves Arsenault wrote:
>> Is this warning outdated?
>> http://www.php.net/manual/en/install.apache2.php
>> "Do not use Apache 2.0 and PHP in a production environment neither on
Unix
>> nor on Windows."
>> I'm running RedHat 9.
>> 
>> I've got Apache 2.0.48 running and was ready to install the latest
php
>> 4.3.x..
>> Just thought I would check.
> --
> :
> :. kind regards
> :..                      Martin Hudec
> :.:
> :.: =w= http://www.aeternal.net
> :.: =m= +421.907.303393
> :.: [EMAIL PROTECTED] [EMAIL PROTECTED]
> :.:
> :.: "When you want something, all the universe
> :.:   conspires in helping you to achieve it."
> :.:                   - The Alchemist (Paulo Coelho)
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Cheers

Mike Morton

****************************************************
*
* Tel: 905-465-1263
* Email: [EMAIL PROTECTED]
*
****************************************************

"Indeed, it would not be an exaggeration to describe the history of the
computer industry for the past decade as a massive effort to keep up
with
Apple."
- Byte Magazine

Given infinite time, 100 monkeys could type out the complete works of
Shakespeare. Win 98 source code? Eight monkeys, five minutes.
-- NullGrey 

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

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003
 

--- End Message ---
--- Begin Message ---
 Hello:
      I want your help! And i am pool in english! 
      The session sometime works well,sometime works badly!
 It creates new empty file in /tmp.I also find this problem
 with apache1.3.12&php4.1.1&sybase11.9.2&linux
 My php.ini is fault
 my server config:
    php4.3.3
    httpd2.0.44
    linux 9
    sybase-11.9.2
 tar-vzxf php-4.3.3.tar.gz
 ../configure ?with-apxs2=/home/apache/bin/apxs
 ?with-sybase-ct=/opt/Sybase-11.9.2 ?enable-ftp ?enable-track-vars
 ?disable-cli
 make
 make install
 cp php.ini-dist /usr/local/lib/php.ini
 
    
                  Thanks a lot
 
 Reproduce code:
 ---------------
 login.php:
         $user_array=sybase_fetch_row($result);
        session_start(); 
        session_register("user_array");
         ...
 index.php:
         session_start();
         $user_name=$user_array[1];


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
--- ÎÚÓÐ ÎÞ <[EMAIL PROTECTED]> wrote:
>  Reproduce code:
>  ---------------
>  login.php:
>          $user_array=sybase_fetch_row($result);
>       session_start(); 
>       session_register("user_array");
>          ...
>  index.php:
>          session_start();
>          $user_name=$user_array[1];

Try this instead:

login.php:
session_start();
$_SESSION['user_array'] = sybase_fetch_row($result);
...

index.php:
session_start();
$user_name = $_SESSION['user_array']['1'];
...

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
     Coming mid-2004
HTTP Developer's Handbook
     http://httphandbook.org/

--- End Message ---
--- Begin Message ---
Hi all.  I'm wondering if anyone can tell me how long temporary session
files stay on the server after the session has ended if
session_destroy() is not called.

I'm curious as part of the CMS I've been writing for the past year is a
class which dynamically generates and validates all forms in the CMS.
This class relies heavily on sessions so I've implemented a method which
is called upon the execution of every page within the CMS, and which
checks for expired forms and deletes them from the session.

This is proving to be very effective in minimizing the overall size of
the session while still having the user work with very large amounts of
session data.  However if the user just closes the browser instead of
logging out the final cleanup isn't called and there can be some large
session files left on the server.

What I'm curious about is how long these last before they are somehow
deleted?  Is there some way I can control this?

Cheers and TIA,

Pablo.

--- End Message ---
--- Begin Message ---
--- Pablo Gosse <[EMAIL PROTECTED]> wrote:
> Hi all. I'm wondering if anyone can tell me how long temporary
> session files stay on the server after the session has ended if
> session_destroy() is not called.

This is defined in php.ini (session.gc_maxlifetime), and you can write
your own garbage collection function (if you want) as part of
session_set_save_handler.

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
     Coming mid-2004
HTTP Developer's Handbook
     http://httphandbook.org/

--- End Message ---
--- Begin Message --- On Sunday, December 7, 2003, at 04:48 PM, Pablo Gosse wrote:

Hi all.  I'm wondering if anyone can tell me how long temporary session
files stay on the server after the session has ended if
session_destroy() is not called.

AFAIK, this depends on two php.ini directives:


---
; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.


session.gc_probability = 1
session.gc_divisor     = 100

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
---


If you still need a little clarification, after 1440 seconds (24 mins) of an inactive session, the session will be seen as garbage. BUT the probability of the garbage collection taking place is reliant on the the 1% (in the above case) chance that garbage collection should take place. On a busy server, this means that garbage will be thrown out almost straight after the 1440 seconds are up, but on a very quiet server, you might need to change the 1/100 to something like 2/100 (2%) or even more.

What I'm curious about is how long these last before they are somehow
deleted?  Is there some way I can control this?

Modify the php.ini and test.


session.gc_probability and session.gc_maxlifetime can also be modified via ini_set() or a .htaccess file.
http://au3.php.net/ini_set


Justin French
--- End Message ---
--- Begin Message --- I'm using a MySQL database to store images as BLOBs. I know how to handle all the MySQL stuff, it's easy, and really makes keeping track of files nice an clean. No permissions, no risk of getting things out of sync, finding stuff is as easy as SQL.

My question is about handling stuff once you pull it out of the database. When I store images in the database, I currently stash the format and the resolution in the database, which works but is a bit messy. I can't find any easy way to run getimagesize on the contents of a variable, not a file. I could write the image to a file if I needed to, but that can be slow and rather inelegant, I'd rather store the values in the DB. Any ideas on how I could use getimagesize or similar function to determine the format and resolution of the image in a variable?

I have had a similar problem with ftp uploading. There was no way to upload the contents of a variable, so I had to write everything to the disk, kind of annoying when I have 1,000 files. The script wasn't a very heavily used script nor could the public execute it, but it bugged me to no end. I think there are some other functions that also only operate on files and I've fought with them too.

Is there any kind of generic solution for this? Some kind of wrapper I could use to make a variable act like a reference to a file but actually be in memory only?

If this seems totally pointless, please tell me. But it seems like there should be a way for almost any function that runs off a file to run off the contents of a variable, it's just binary data.

Thanks,
        Galen

--- End Message ---
--- Begin Message --- Galen wrote:

I'm using a MySQL database to store images as BLOBs. I know how to handle all the MySQL stuff, it's easy, and really makes keeping track of files nice an clean. No permissions, no risk of getting things out of sync, finding stuff is as easy as SQL.

My question is about handling stuff once you pull it out of the database. When I store images in the database, I currently stash the format and the resolution in the database, which works but is a bit messy. I can't find any easy way to run getimagesize on the contents of a variable, not a file. I could write the image to a file if I needed to, but that can be slow and rather inelegant, I'd rather store the values in the DB. Any ideas on how I could use getimagesize or similar function to determine the format and resolution of the image in a variable?

I have had a similar problem with ftp uploading. There was no way to upload the contents of a variable, so I had to write everything to the disk, kind of annoying when I have 1,000 files. The script wasn't a very heavily used script nor could the public execute it, but it bugged me to no end. I think there are some other functions that also only operate on files and I've fought with them too.

Is there any kind of generic solution for this? Some kind of wrapper I could use to make a variable act like a reference to a file but actually be in memory only?

If this seems totally pointless, please tell me. But it seems like there should be a way for almost any function that runs off a file to run off the contents of a variable, it's just binary data.

Thanks,
    Galen

If the programs read from a file descriptor, you could open a pipe, write into it on your side, and have the command read from it. But that's really messy... and won't work for the image size function.

--- End Message ---
--- Begin Message --- Galen wrote:

I'm using a MySQL database to store images as BLOBs. I know how to handle all the MySQL stuff, it's easy, and really makes keeping track of files nice an clean. No permissions, no risk of getting things out of sync, finding stuff is as easy as SQL.

My question is about handling stuff once you pull it out of the database. When I store images in the database, I currently stash the format and the resolution in the database, which works but is a bit messy. I can't find any easy way to run getimagesize on the contents of a variable, not a file. I could write the image to a file if I needed to, but that can be slow and rather inelegant, I'd rather store the values in the DB. Any ideas on how I could use getimagesize or similar function to determine the format and resolution of the image in a variable?

I have had a similar problem with ftp uploading. There was no way to upload the contents of a variable, so I had to write everything to the disk, kind of annoying when I have 1,000 files. The script wasn't a very heavily used script nor could the public execute it, but it bugged me to no end. I think there are some other functions that also only operate on files and I've fought with them too.

Is there any kind of generic solution for this? Some kind of wrapper I could use to make a variable act like a reference to a file but actually be in memory only?

If this seems totally pointless, please tell me. But it seems like there should be a way for almost any function that runs off a file to run off the contents of a variable, it's just binary data.

Thanks,
    Galen

If the programs read from a file descriptor, you could open a pipe, write into it on your side, and have the command read from it. But that's really messy... and won't work for the image size function.

--- End Message ---
--- Begin Message ---
Of course but when I make a file test.shtml, the php-code will be ignored,
and when I name the file test.php, the SSI will be ignored.


----- Original Message -----
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "V.B. de Haan" <[EMAIL PROTECTED]>
Cc: "PHP General Mailing List" <[EMAIL PROTECTED]>
Sent: Saturday, December 06, 2003 11:54 PM
Subject: Re: [PHP] PHP and IIS


> V.B. de Haan wrote:
> > I'm running IIS 5.0 on win 2000 professional. I want to include SSI and
PHP
> > code in one single file of HTML. How can I do this?
>
> The question is WHY you'd want to do this. Whatever you're doing in your
> SSI should just be done in PHP.
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
>
>
>
>
>

--- End Message ---
--- Begin Message ---
Now the WHY-question:

at the bottom of every page, a complex CGI-Perl-script has to be executed,
it's more easily to add only one line of SSI-comment, than the whole content
of te script. I also have to translate it to PHP.

Vincent
----- Original Message -----
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "V.B. de Haan" <[EMAIL PROTECTED]>
Cc: "PHP General Mailing List" <[EMAIL PROTECTED]>
Sent: Saturday, December 06, 2003 11:54 PM
Subject: Re: [PHP] PHP and IIS


> V.B. de Haan wrote:
> > I'm running IIS 5.0 on win 2000 professional. I want to include SSI and
PHP
> > code in one single file of HTML. How can I do this?
>
> The question is WHY you'd want to do this. Whatever you're doing in your
> SSI should just be done in PHP.
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
>
>
>
>
>

--- End Message ---
--- Begin Message --- V.B. de Haan wrote:

Now the WHY-question:

at the bottom of every page, a complex CGI-Perl-script has to be executed,
it's more easily to add only one line of SSI-comment, than the whole content
of te script. I also have to translate it to PHP.

No you don't. Just use virtual().


http://us2.php.net/virtual

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
"Justin Patrin" <[EMAIL PROTECTED]> wrote
news:[EMAIL PROTECTED]

> Use mysqldump in a system() call, redirect it to a temp file, then read
> it back and out to the browser.
>
> Or, you could use popen to get the output piped back into php. Make sure
> to check the mysqldump options for things you need (I often use -Q -e
> --add-drop-table).
>
> <?php
> header('Content-type: application/mysql');
> header('Content-disposition: attachment; filename=dump.sql');
> $fd = popen('mysqldump -uuser -ppassword databaseName', 'r');
> while(!feof($fd)) {
>    echo fgets($fd);
> }
> pclose($fd);
> ?>

Thanks a lot. I haven't used this functions ever, but I'm sure PHP.net (and
maybe some help from you guys) will do the job. Also thanks to Ajai for the
idea.
___________________________
Cesar L. Aracena
Commercial Manager / Developer
ICAAM Web Solutions
2K GROUP
Neuquen, Argentina
Tel: +54.299.4774532
Cel: +54.299.6356688
E-mail: [EMAIL PROTECTED]

--- End Message ---

Reply via email to