Home  |  Linux  | Mysql  | PHP  | XML
From:Nathan Wallace Date:Tue Jul  6 06:30:31 1999
Subject:PHP Knowledge Base Update -- July 5th, 1999
I'm amazed at the quantity and quality of the information on the PHP
mailing list everyday.  Although a lot of questions are now covered in
the knowledge base these summaries don't seem to be getting any
shorter...

Thanks to everyone who contributes their knowledge and time to the list,
making these summaries possible.

Cheers,

Nathan


------------------------------------------------------------
Can I use PHP to add a new user and password to my Unix system?
How can I add a new user to my FreeBSD system using PHP?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/393
------------------------------------------------------------
Karl Pielorz

Try exec'ing 'adduser' from PHP.  For more information on adduser do
this at the unix command line:

   man adduser

For security's sake make sure you do some sensible checking / protection
for the parameters.


------------------------------------------------------------
Can I use variable function names in PHP?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/395
------------------------------------------------------------
Nathan Wallace

Try something like the following:

    $fn_name = 'myfunc';

    $result = $fn_name($arg1, $arg2);

Then the function called myfunc (specified in the variable $fn_name)
will be called.


------------------------------------------------------------
Why can't I see the contents of my cookie in a function?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/396
------------------------------------------------------------
Nathan Wallace

PHP treats every variable as local to the function unless you specify it
as global.  Thus, you cannot access $HTTP_COOKIE_VARS in a function
unless you declare it as global inside that function.

This should work:

    function ReadCookie($name) {
        global $HTTP_COOKIE_VARS;
        return $HTTP_COOKIE_VARS[$name];
    }

Similarly the cookie is not accessable by name unless you declare it as
global.  In this case what we actually want is the variable that holds
the cookie (the one called $name) to be global, so we have to globalize
the variable variable...

    function ReadCookie($name) {
        global $$name
        return $$name;
    }


------------------------------------------------------------
Can I run a Javascript function automatically when someone leaves the
page?
How can I know that a user has left a page?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/397
------------------------------------------------------------
Jason Brooke

Once the browser finishes sending the page to the client, the state ends
there. Any session management features of a scripting language can then
only use cookies or a unique id passed in the query string or form
fields to identify the client on the next request.

The only thing you might be able to do is to use the javascript
onUnload() function to cause a form submission which might send
something back to your server.


------------------------------------------------------------
What is the client server sequence for setting a cookie?
How can I check if a browser accepts cookies?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/399
------------------------------------------------------------
Nathan Wallace

Here is the cookie setting sequence in PHP:

    Client                      Server

    requests page
                                gets request
                                sets cookie in reply
                                sends reply
    gets reply (with cookie)
    sets cookie on machine

    sends new request (with
        cookie included)
                                gets request
                                finds cookie in request
                                sets variable in script
                                runs script

The server has to interact with the client to be able to set a cookie or
determine if it has been set.


------------------------------------------------------------
How can I stop text from wrapping in a browser?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/401
------------------------------------------------------------
Nathan Wallace

Try using the HTML <pre> tags.  Anything between them will be shown in
the browser with the exact formatting (including line breaks) that you
specify.

<pre>
<?php
  echo "I should be a really long line that we don't want to wrap...";
?>
</pre>


------------------------------------------------------------
How can I work out the days in a month?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/402
------------------------------------------------------------
Chuck Hagenbuch

From the manual:

    http://www.php.net/manual/function.date.php3

the option to use is:

    t - number of days in the given month; i.e. "28" to "31"

so your code looks like:

    $days_this_month = date('t');
    // specify a timestamp if you want a different month


------------------------------------------------------------
How can I tell if the user has aborted the download?
How can I force a script to execute completely even if the user aborts?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/403
------------------------------------------------------------
Rasmus Lerdorf

Add connection_status() function.  This returns the raw bitfield which 
indicates whether the script terminated due to a user abort, a timeout
or normally.  Note that if ignore_user_abort is enabled, then both the 
timeout state and the user abort state can be active

    http://www.php.net/manual/function.connection-status.php3

Add connection_timeout() function.  This one can be called in a shutdown
function to tell you if you got there because of a timeout

    http://www.php.net/manual/function.connection-timeout.php3

Add ignore_user_abort() function and .ini/.conf directive of same name

    http://www.php.net/manual/function.ignore-user-abort.php3

Fix connection abort detection code - It should now work reliably with 
Apache.  Also added a user-level connection_aborted() function designed
to let people check whether the user aborted the connection in a
user-level shutdown function.

    http://www.php.net/manual/function.connection-aborted.php3

Here is the test script as used by Rasmus when writing the functions:

<?
    set_time_limit(5);
    ignore_user_abort(0);
    register_shutdown_function("done");
    function done() {
        global $i, $fp;

        fputs($fp,"i reached $i\n");
        if(connection_aborted())
            fputs($fp,"** the connection was aborted **\n");
        fclose($fp);
        echo "all done\n";
    }

    $fp = fopen("/tmp/done","w");
    for($i=0; $i<7; $i++) {
        fputs($fp,"i is $i\n");
        for($j=0;$j<1000;$j++) $a=sqrt($j);
        sleep(1);
        echo "$i
................................................................................<br>";
        flush();
    }
    exit;
?>

This should give you some ideas.


------------------------------------------------------------
What type of password does imap_open() expect?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/405
------------------------------------------------------------
Mark Musone

imap_open expects a plaintext password.

For more information see the manual:

    http://www.php.net/manual/function.imap-open.php3


------------------------------------------------------------
Are there any resources for Italian developers?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/406
------------------------------------------------------------
Michel Morelli

There is an Italian mailing list available for php3

Send an email with

    subscribe

as the subject to the address

    php3-it-request@michel.enter.it

to join.


------------------------------------------------------------
How can I get the users time?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/407
------------------------------------------------------------
Teodor Cimpoesu

You can try guessing his timezone (TZ) based on the country code given
by REMOTE_ADDR, and set the time acordingly.


------------------------------------------------------------
Why is my httpd binary very big with PHP installed?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/408
------------------------------------------------------------
M.Brands, Jerry Preeper

Your new version might still contain debugging information? You can
check this by doing 

    file <filename>

Ofcourse, <filename> needs to be replaced by the full name of you httpd
binary. If file says the file is not stripped (i.e. it still contains
debuginfo), you can strip that debuginfo by doing

    strip <filename>

Ofcourse, if you run into problems later, it will be impossible to debug
things. But it doesn't happen very often that you need to debug PHP
itself. That's more something for PHP developers (like Zeev and Andy) or
beta testers.


------------------------------------------------------------
How can I check the size of a file on the client side?
How can I limit the size of files uploaded to the server by a user?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/409
------------------------------------------------------------
Mitch Vincent, John Coggeshall

Javascript does not allow operations on files, and so it is not possible
to check the size of a file on the client side.

Most people checking the size of a file will want to do so before the
user uploads the file to their server.  You cannot actually do this
until the file upload is in progress.

You can put a MAXFILESIZE HTML tag in the <INPUT TYPE="file"> tag... Or
you can check the filesize once it's uploaded to PHP and simply not
process the upload if it's too big or too small (the file will be
automatically deleted after your script exits)....



Navigate in group php.kb at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by Zareef Ahmed
Powered By PHP Consultants