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 21 Oct 2005 10:29:47 -0000 Issue 3749

php-general-digest-helplists.php.net
Date: Fri Oct 21 2005 - 05:29:47 CDT


php-general Digest 21 Oct 2005 10:29:47 -0000 Issue 3749

Topics (messages 224372 through 224393):

Trapping for an uploaded file that's too large?
        224372 by: Brian Dunning
        224373 by: Jordan Miller
        224374 by: Brian Dunning

Re: Executing process in background
        224375 by: Jasper Bryant-Greene

SCRIPT_NAME
        224376 by: John Taylor-Johnston
        224378 by: Jasper Bryant-Greene
        224379 by: Robert Cummings
        224380 by: Minuk Choi
        224381 by: Robert Cummings
        224384 by: John Taylor-Johnston

Re: No redirect with header() [solved]
        224377 by: Dotan Cohen

OOP Newbie - why does this not work?
        224382 by: Bob Hartung
        224383 by: Stephen Leaf
        224385 by: Stephen Leaf
        224386 by: Stephen Leaf
        224387 by: Jesper Gran
        224388 by: Jochem Maas

Re: PHP and files Upload
        224389 by: Andy Pieters

Re: How can I count the usage of mail function in scripts?
        224390 by: Andy Pieters

Preference for User Permissions system
        224391 by: Richard Davey
        224393 by: James Benson

Re: LDAP and a pain in my neck
        224392 by: Jochem Maas

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:


In my File Upload form, if the file is >=2MB, the user just gets a
blank "error opening file" screen, almost immediately after the
upload starts. I don't know how to trap for this to give a more user-
friendly experience. Can anyone point me in the right direction?

attached mail follows:


On Oct 20, 2005, at 6:29 PM, Brian Dunning wrote:

> In my File Upload form, if the file is >=2MB, the user just gets a
> blank "error opening file" screen, almost immediately after the
> upload starts. I don't know how to trap for this to give a more
> user-friendly experience. Can anyone point me in the right direction?
>

are you using PHP 5? If so, maybe check out this, below.

Jordan

> From: jmilhymiegladstone.com
> Subject: Re: [PHP] Re: PHP 5 limits "readfile" to 1.9 MB?
> Date: August 17, 2005 10:26:40 AM CDT
> To: catalinisp-software.de
> Cc: php-generallists.php.net
> In-Reply-To: <98.D9.33075.49553034pb1.pair.com>
>
> Ok, just checking (I am new to the fopen() function). That makes
> sense. Awesome, thanks!
>
> Jordan
>
> On Aug 17, 2005, at 10:19 AM, Catalin Trifu wrote:
>
>
>
>> Hi,
>>
>> Indeed a fclose($fp) is needed (wrote it as an example :)).
>> 1MB is more than enough as a buffer. If you have a 53MB file,
>> what will happen then ?
>> I have no idea if it's a bug or a feature. Either way I did lose
>> some hair over this when I switched from PHP4 to PHP5.
>>
>> Catalin
>>
>>
>> Jordan Miller wrote:
>>
>>
>>
>>> Catalin,
>>> Wow, that worked great, thanks.
>>> I'm curious why you set a static buffer of 1024768... why not
>>> just do filesize($file), as shown at http://www.php.net/fread ?
>>> Is it better for memory usage to have a potentially smaller
>>> buffer? Also, you may want an fclose($fp) after the file has
>>> been downloaded.
>>> So is this a bug in PHP 5 or are they just purposely limiting
>>> the abilities of the "readfile" command?
>>> Jordan
>>> On Aug 17, 2005, at 3:36 AM, Catalin Trifu wrote:
>>>
>>>
>>>
>>>> Hi,
>>>>
>>>> I've had a similar problem. The download always stopped at
>>>> exactly 2.000.000 bytes.
>>>> You have to work around that with:
>>>> $fp = fopen($file, 'r');
>>>> if($fp) {
>>>> while(!feof($fp)) {
>>>> echo fread($fp, 1024768);//see the huge buffer to read into
>>>> }
>>>> } else {
>>>> //whatever error handler
>>>> }
>>>>
>>>> Catalin
>>>>
>>>>
>>>> Jordan Miller wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> Hello all,
>>>>> I am new to this list and I have searched the archives to no
>>>>> avail. I am having a peculiar problem when upgrading to PHP 5:
>>>>> My downloads are now limited to the first 1.9 MB of the file
>>>>> in question, with the download either terminating at 1.9 MB
>>>>> or seemingly continuously stuck in a downloading process at
>>>>> 1.9 MB. The code in the PHP script has not changed and all
>>>>> parameters that I could find that are relevant to this
>>>>> problem are given below:
>>>>> the minimal code needed for download:
>>>>> // $file_to_read is the complete path of the file to
>>>>> download
>>>>> header("Content-Type: application/pdf");
>>>>> header( "Content-Disposition: inline; filename=
>>>>> \"$filename \"");
>>>>> $len = filesize($file_to_read);
>>>>> header("Content-Length: $len");
>>>>> readfile($file_to_read);
>>>>> php.ini file for both php version 4 and 5 contain the
>>>>> following settings that may be relevant:
>>>>> allow_url_fopen = On
>>>>> max_execution_time = 300 ; Maximum execution time of each
>>>>> script, in seconds
>>>>> max_input_time = 300 ; Maximum amount of time each script
>>>>> may spend parsing request data
>>>>> memory_limit = 8M ; Maximum amount of memory a script
>>>>> may consume (8MB)
>>>>> post_max_size = 200M
>>>>> upload_max_filesize = 200M
>>>>> Some additional details:
>>>>> All files less than 1.9 MB download fine
>>>>> It is not a corrupted file, because all files larger than 1.9
>>>>> MB fail after 1.9 MB
>>>>> The connection is not timing out (download of 1.9 MB takes
>>>>> only ~15 sec)
>>>>> Mac OS X 10.3.9 with Marc Liyanage's PHP 5.0.4
>>>>> Fails for both Safari and Firefox
>>>>> Fails regardless of "inline" or "attachment"
>>>>> Fails regardless of "pdf" or "ppt" content-type
>>>>> This PHP code ALWAYS works for Marc Liyanage's PHP 4.3.4 with
>>>>> the same settings, above
>>>>> What am I doing wrong??? Any other parameter in php.ini I
>>>>> should have set? Any suggestions are much appreciated.
>>>>> thanks,
>>>>> Jordan
>>>>>
>>>>>

attached mail follows:


On Oct 20, 2005, at 4:55 PM, Jordan Miller wrote:

> are you using PHP 5?

No, 4 unfortunately. Shoulda said so.

attached mail follows:


On Thu, 2005-10-20 at 15:07 -0700, Surya Mishra wrote:
> I have to start a task on the server side that is going to take pretty long
> to process in the server side. So I would like to show a message to the user
> and ask him/her to check again later. But starting a new task holds up the
> thread and won't let me exit the php. The user's browser does keeps showing
> busy.
> I tried to create a new thread using pcntl_fork, but my php doesn't allow
> that as it has not been compiled with pcntl support and its not possible to
> change that.
> I also tried to create a script that would do the task and called the script
> using system command and passed an '&' at the end to make it process in
> background, but that also keeps the main thread busy.

Add it to a list (flat file, DB, whatever) of processes to be done and
run a cron script regularly (how regular would depend on the specific
app) to execute all the processes in the list.

--
Jasper Bryant-Greene
General Manager
Album Limited

e: jasperalbum.co.nz
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

attached mail follows:


SCRIPT_NAME and PHP_SELF always include leading url information and
slashes. Is there a function I can use to skin either down to the
filename? No slashes or leading url.
John

attached mail follows:


On Thu, 2005-10-20 at 22:22 -0400, John Taylor-Johnston wrote:
> SCRIPT_NAME and PHP_SELF always include leading url information and
> slashes. Is there a function I can use to skin either down to the
> filename? No slashes or leading url.

http://php.net/basename for filesystem paths

http://php.net/parse_url for URLs

--
Jasper Bryant-Greene
General Manager
Album Limited

e: jasperalbum.co.nz
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

attached mail follows:


On Thu, 2005-10-20 at 22:22, John Taylor-Johnston wrote:
> SCRIPT_NAME and PHP_SELF always include leading url information and
> slashes. Is there a function I can use to skin either down to the
> filename? No slashes or leading url.

echo ereg_replace( '^.*/', '', $_SERVER['SCRIPT_NAME'] )

ereg is greedy, it'll match as much as it can.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


Off the top of my head...

$filename = $_SERVER['PHP_SELF'];

$strippedFilename = substr($filename, strrpos($filename, '/'));

references :
http://us3.php.net/substr

http://us3.php.net/manual/en/function.strrpos.php

-Minuk

John Taylor-Johnston wrote:

> SCRIPT_NAME and PHP_SELF always include leading url information and
> slashes. Is there a function I can use to skin either down to the
> filename? No slashes or leading url.
> John
>

attached mail follows:


On Thu, 2005-10-20 at 23:27, Minuk Choi wrote:
> Off the top of my head...
>
> $filename = $_SERVER['PHP_SELF'];
>
> $strippedFilename = substr($filename, strrpos($filename, '/'));

Won't work, I'll leave the reason as an exercise :B

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


Thanks!
John

attached mail follows:


On 10/20/05, Oliver Grätz <oliver.graetzarcor.de> wrote:
> So perhaps it was good that I was pushing to see the code ;-)
> So you looked more closely...
>
> Tip: I put an output buffer around my "not supposed to output anything"
> code:
>
> <?php
> ob_start();
> // include function libraries, perform non-visible stuff etc.
> $premature=ob_get_clean();
> // if premature is non-empty then there was premature output => log to file
>
> // regular output
> ?>
>
> This could help you in preventing some output problems in the future.
>
> OLLi
>
>

Most certainly! Thank you.

Dotan
http://lyricslist.com/lyrics/artist_albums/360/motley_crue.php
Motley Crue Song Lyrics

attached mail follows:


Hi all,
   I'm trying to get started in OOP with PHP. I have the following
short code snipped. I'f I comment out the 'class Test' definition and
the following references to it, it prints
    This is outside the php code block

         and

    Start defining the class here:

If I do not comment out the code as noted, then the page returned is
totally blank. It does this with or without using the constructor.
PHP 5 on apache. Same behavior both on Win32 and FC4.

All help appreciated to get me going.

Code Snippet:

<html>

<head>
   <title>PHP Class testing</title>

</head>
<body>
        <br>
          <P>This is outside the php code block</P>
        <br>
        <?php
          echo "Start defining the class here: <BR>" ;
/* class Test
          {
        
            function __constructor()
                 {
                   var $saying ;
                        $saying = "Im in the Test Class" ;
                 }
                
                 function get()
                 {
                   return $saying ;
                
          }
        
          var $liveclass ;
          $liveclass = new Test ;
          echo $liveclass->get() ;
          echo "<BR>" ;
      echo "This is in the php code block" ;
*/
        ?>

</body>
</html>

attached mail follows:


Try removing the /* and */
Other than that, check your brackets.
you never closed the get() function's

On Thursday 20 October 2005 09:35 pm, Bob Hartung wrote:
> Hi all,
> I'm trying to get started in OOP with PHP. I have the following
> short code snipped. I'f I comment out the 'class Test' definition and
> the following references to it, it prints
> This is outside the php code block
>
> and
>
> Start defining the class here:
>
> If I do not comment out the code as noted, then the page returned is
> totally blank. It does this with or without using the constructor.
> PHP 5 on apache. Same behavior both on Win32 and FC4.
>
> All help appreciated to get me going.
>
> Code Snippet:
>
> <html>
>
> <head>
> <title>PHP Class testing</title>
>
> </head>
> <body>
> <br>
> <P>This is outside the php code block</P>
> <br>
> <?php
> echo "Start defining the class here: <BR>" ;
> /* class Test
> {
>
> function __constructor()
> {
> var $saying ;
> $saying = "Im in the Test Class" ;
> }
>
> function get()
> {
> return $saying ;
>
> }
>
> var $liveclass ;
> $liveclass = new Test ;
> echo $liveclass->get() ;
> echo "<BR>" ;
> echo "This is in the php code block" ;
> */
> ?>
>
> </body>
> </html>

attached mail follows:


Sorry.. 1 more thing.
php5 does not use var.
use public $variable=value; instead.
public is only within a class however. you cannot use it outside.

On Thursday 20 October 2005 09:35 pm, Bob Hartung wrote:
> Hi all,
> I'm trying to get started in OOP with PHP. I have the following
> short code snipped. I'f I comment out the 'class Test' definition and
> the following references to it, it prints
> This is outside the php code block
>
> and
>
> Start defining the class here:
>
> If I do not comment out the code as noted, then the page returned is
> totally blank. It does this with or without using the constructor.
> PHP 5 on apache. Same behavior both on Win32 and FC4.
>
> All help appreciated to get me going.
>
> Code Snippet:
>
> <html>
>
> <head>
> <title>PHP Class testing</title>
>
> </head>
> <body>
> <br>
> <P>This is outside the php code block</P>
> <br>
> <?php
> echo "Start defining the class here: <BR>" ;
> /* class Test
> {
>
> function __constructor()
> {
> var $saying ;
> $saying = "Im in the Test Class" ;
> }
>
> function get()
> {
> return $saying ;
>
> }
>
> var $liveclass ;
> $liveclass = new Test ;
> echo $liveclass->get() ;
> echo "<BR>" ;
> echo "This is in the php code block" ;
> */
> ?>
>
> </body>
> </html>

attached mail follows:


Here is the working code
You had __constructor() it's __construct()

notice I also moved your saying declaration outside of the constructor.
this is to make it a class level variable.
the way that you had it set it was only in scope until you finished the
construct code.

I guess I was wrong about the var bit. I do remember having lots of issues
with it back a few months ago. perhaps theses were fixed in newer versions.
most likely var is depreciated in php5. (can someone confirm this?)

<html>
        <head>
                <title>PHP Class testing</title>
        </head>
        <body>
                <br/>
                <p>This is outside the php code block</p>
                <br/>
                <?php
                        echo "Start defining the class here: <br/>" ;
                        class Test {
                                public $saying = "";

                                function __construct() {
                                        $saying = "Im in the Test Class" ;
                                }
                                function get() {
                                        return $saying ;
                                }
                        }

                        $liveclass = new Test ;
                        echo $liveclass->get() ;
                        echo "<br/>" ;
                        echo "This is in the php code block" ;
         ?>
        </body>
</html>

On Thursday 20 October 2005 09:53 pm, Bob Hartung wrote:
> Changed to:
> var $saying ;
> public $saying = "....."
>
> Again, blank page. Funny though, even the <title>...</title> html block
> is not rendered. Again, same beavior on 2 FC4 and 1 Win32 install.
>
> Tnx
>
> Bob
>
> Stephen Leaf wrote:
> > Sorry.. 1 more thing.
> > php5 does not use var.
> > use public $variable=value; instead.
> > public is only within a class however. you cannot use it outside.
> >
> > On Thursday 20 October 2005 09:35 pm, Bob Hartung wrote:
> >>Hi all,
> >> I'm trying to get started in OOP with PHP. I have the following
> >>short code snipped. I'f I comment out the 'class Test' definition and
> >>the following references to it, it prints
> >> This is outside the php code block
> >>
> >> and
> >>
> >> Start defining the class here:
> >>
> >>If I do not comment out the code as noted, then the page returned is
> >>totally blank. It does this with or without using the constructor.
> >>PHP 5 on apache. Same behavior both on Win32 and FC4.
> >>
> >>All help appreciated to get me going.
> >>
> >>Code Snippet:
> >>
> >><html>
> >>
> >><head>
> >> <title>PHP Class testing</title>
> >>
> >></head>
> >><body>
> >> <br>
> >> <P>This is outside the php code block</P>
> >> <br>
> >> <?php
> >> echo "Start defining the class here: <BR>" ;
> >>/* class Test
> >> {
> >>
> >> function __constructor()
> >> {
> >> var $saying ;
> >> $saying = "Im in the Test Class" ;
> >> }
> >>
> >> function get()
> >> {
> >> return $saying ;
> >>
> >> }
> >>
> >> var $liveclass ;
> >> $liveclass = new Test ;
> >> echo $liveclass->get() ;
> >> echo "<BR>" ;
> >> echo "This is in the php code block" ;
> >>*/
> >> ?>
> >>
> >></body>
> >></html>

attached mail follows:


On 2005-10-21 06:17, Stephen Leaf wrote:

>most likely var is depreciated in php5. (can someone confirm this?)
>
>
Well, if I try to use Var in a class i get this message:

Strict Standards: var: Deprecated. Please use the
public/private/protected modifiers in C:\code\test\var.php on line 3*

/*Jesper*
*

attached mail follows:


Bob,

'wrapping' you class definition within HTML like you have done is
not only weird but down right ugly. I recommend sticking each class
you write in a seperate file and using include_once() or require_once()
before you output anything to the browser. basically try to
seperate you code into 'stages' (for want of a better word) e.g.:

1. setup an environment (includes loading classes)
2. process the request
3. redirect or output a page

Bob Hartung wrote:
> Hi all,

...

>
> </head>
> <body>
> <br>
> <P>This is outside the php code block</P>
> <br>
> <?php
> echo "Start defining the class here: <BR>" ;
> /* class Test
> {
>
> function __constructor()
> {
> var $saying ;

'var' doesn't belong here. it belongs directly in the body of class def.

> $saying = "Im in the Test Class" ;
> }
>
> function get()
> {
> return $saying ;

there is a missing '}' here.
also you should be returning and setting $this->saying

>
> }
>
> var $liveclass ;

drop the 'var' - it's only for php4 and then only for
defining the properties of classes/objects:

class Test {
        var $myProperty;
}

> $liveclass = new Test ;
> echo $liveclass->get() ;
> echo "<BR>" ;
> echo "This is in the php code block" ;
> */
> ?>
>
> </body>
> </html>
>

attached mail follows:


Hi

As a security precaution, all uploaded files are automatically deleted when
the script goes out of scope.

Use the move_uploaded_file function to move the file somewhere else before
your script ends.

There are various other security precautions you have to consider. And by all
means don't expect the browser to adhere to the limitations you set in the
form, like mime type and max sizes, also know that it is fairly easy for
someone to directly connect to the socket and upload a file, bypassing the
browser altogheter.

The php documentation site covers file uploads in depth (www.php.net)

HTH

With kind regards

Andy

On Wednesday 19 October 2005 00:36, feiticeir0 wrote:
> hello all.
>
> I've managed to create files uploads pages in the past (dont remember if
> alredy with php 5).
>
> till now, i havent need for testing or using.
> today, i've tried to test an upload page (a very simple one) with php 5.0.5
> and i was unable to do it.
>
> the script always says it was sucessful to upload the file, but the
> destination directory was always empty...
> even when checking the $_FILES global
>
> $_FILES['var_name']['tmp_name'] and
> $_FILES['var_name']['name'] and
> $_FILES['var_name']['size'], the vars alwyas return empty values...
>
> is there any issue with php5 about files uploads ?
>
> in php.ini i set the temp directory to /tmp and still nothing works...
>
> Cheers,
>
> Bruno Santos
>
> --
> Open WebMail Project (http://openwebmail.org)
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.

--
Now listening to Top! Radio Live www.topradio.be/stream on amaroK
Geek code: www.vlaamse-kern.com/geek
Registered Linux User No 379093
If life was for sale, what would be its price?
www.vlaamse-kern.com/sas/ for free php utilities
--

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBDWKsK6Hylol726jIRAgQgAJ9tkOq2YmURuu/WY8jfRXm7V4/QNQCfdsV6
WcMGxFJvnRFrS7C5KIGY9+8=
=gfv0
-----END PGP SIGNATURE-----

attached mail follows:


Hi

While it *is* possible to do what you ask for, it would be worthless.

I can write from scratch a php script that
* looks up the mx record for a given email address
* connects to the mail server looked up
* send the message.

Since the SMTP protocol is fairly simple, I am sure many others can and will
use this to circumvent your limitations.

With kind regards

Andy

On Tuesday 18 October 2005 11:45, Cristea Adrian wrote:
> Hello peoples!
>
> short question: How can I count the usage of mail function in scripts?
>
> long description :D
>
> I have a webserver, and I want to limit the usage of mail function for
> each host I have there.. Notice that i have a couple of hundrest of
> virtual hosts (domains and subdomains) there, and i want to limit
> them, let`s say.. 100 mails per day.. there is any solution to do
> that? (i know there is, i saw that in a nwebhosting company) .. can
> you guide me find this solution?
>
> thanks in advance!
>
> cheers, cajbecu

--
Now listening to Top! Radio Live www.topradio.be/stream on amaroK
Geek code: www.vlaamse-kern.com/geek
Registered Linux User No 379093
If life was for sale, what would be its price?
www.vlaamse-kern.com/sas/ for free php utilities
--

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBDWKz96Hylol726jIRAjzaAKCfDk5ja3zTfO0vGNgH3zy72lJ47ACggspN
8mChXuCkfGyExQ9xilh/ajo=
=sr9X
-----END PGP SIGNATURE-----

attached mail follows:


Hi php-general,

  I'm interested to know what everyones preference is for user
  permissions / roles in php apps? For example do you employ a Unix
  style groups system, is there a ready-rolled class or package you
  use, or have you just built your own and stick with it?

Cheers,

Rich
--
Zend Certified Engineer
http://www.launchcode.co.uk

attached mail follows:


What I do is have different classes that build upon each other,

authentication & permissions class,
common database access extending PEAR DB.

then i have a custom class for specific actions like editing pages, my
database is just either either an email or username and password then
another table has permission levels in, permissions for every user are
defined in their DB table in a comma seperated list, that way i can
create many groups and have a user belong many groups, then page editng
for instance can be restricted to specific users or groups, I designed
it all to be flexible enough to reuse for all my websites I hope :)

Regards,
James

Richard Davey wrote:
> Hi php-general,
>
> I'm interested to know what everyones preference is for user
> permissions / roles in php apps? For example do you employ a Unix
> style groups system, is there a ready-rolled class or package you
> use, or have you just built your own and stick with it?
>
> Cheers,
>
> Rich

attached mail follows:


André Medeiros wrote:
> Check your webserver logs. If PHP couldn't use the extension, it will
> accuse that in the logs.

probably the best use of the word 'accuse' .... ever

(with a slight nod to commercials for Carlsberg lager :-)

>
> On 10/20/05, Jay Blanchard <jay.blanchardthermon.com> wrote:
>
>>[snip]
>>
>>>Call to undefined function: ldap_connect()
>>>
>>>What am I missing? TIA.
>>
>>
>>Did you uncomment (and properly define) the 'extension_dir' directive
>>in your php.ini?
>>[/snip]
>>
>>Yep.
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>