Re: [PHP] Drop down list - persistant value

2005-04-13 Thread Peter H. Lemieux
I use a function to create select boxes:
function make_select($fieldname,$options,$selected,$opt=) {
# make a select box with option text $opt
# $fieldname = name of html field
# $options = associative array of select options
# $selected = field key of selected item
# $opt = optional attributes, e.g., styles, etc.
$output.=\nselect name=\$fieldname\ $opt ;
foreach ($options as $key=$val) {
$output.=\noption value=\$key\;
if ($key==$selected) {
$output.= selected;
}
$output.=$val;
}
$output.=\n/select\n;
return $output;
}
By passing the previously selected item as $selected it will 
automatically reselect the chosen item.  For instance,

?php echo make_select(myfield,$options,$_POST[myfield]) ?
I've written similar functions for check boxes and radio buttons. 
They've made form creation and handling enormously easier.

Peter
Jacques wrote:
I am using PHP. I have a registration page where the user has to select his 
country form a drop down list. If the username that the user selected for 
himself exists in the database I am sending him back to the registration 
form with all the fields completed with the values he previously entered. 
This is easy to do for a textfield but how do I indicate on the drop down 
list which country he originally selected?

Please help.
Jacques 

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


Re: [PHP] protecting downloads with php

2002-05-12 Thread Peter H. Lemieux

It can be tricky to write download wrappers that work with all browsers.
Some versions of Internet Explorer seem especially troublesome.

I've found wrappers like these seem to work fairly well:

initialization();
authorization($user,$pw);
$info=get_file_info($filepointer);
### SEND HEADERS ###
header(Content-Type: .$info[mimetype]);
header(Content-Disposition: inline; filename=.$info[filename]);
### NO TEXT CAN BE ECHOED BEFORE HERE ###

### Open the file and display it
$fp=fopen($filepath./.$info[filename],r);
fpassthru($fp);
fclose($fp);

### END

A few observations:

PHP will complain if you send any text to the browser before calling
header() (since HTTP headers can't be sent once the data segment begins).
Sometimes this problem can be hard to track down.  I've left invisible
whitespace after the closing ? tag in a file included above the calls to
the header function().  The PHP parser naturally views this whitespace as
HTML content and echoes it to the browser.

The filename portion of the second header usually points to the name of
the file itself without any leading path component.

Some versions of Internet Explorer fail to initiate the download unless a
separate window is opened.

Most modern *nix systems have a mime.types file.  A quick scan of one
RedHat Linux 7.1 machine finds the Apache mime.types file stored as
/etc/mime.types along with some sample mime.types files installed by
applications like lynx and mutt.  The file is delimited by white space
(usually a tab) between the type and list of extensions making it easy to
write a function that converts it into an array $mimetype[$extension].

If you collect inbound files by mail (as I do) or by HTTP upload, you'll
find the file's MIME type in the session headers.  Since most people's
mail or web client runs on the same machine as their application, these
headers are usually pretty accurate.

Peter


- Original Message -
From: Nick Wilson [EMAIL PROTECTED]
To: php-general [EMAIL PROTECTED]
Sent: Saturday, May 11, 2002 4:58 AM
Subject: [PHP] protecting downloads with php


 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Hi all
 I've been asked to protect an area containing 'course material' (pdf's
 etc) and have just thought of a gaping hole in what I've done.

 I use an class to handle all the auth stuff and each page checks the
 value of $obj-logged_in :: No problem.

 but what if someone links to www.thesite/theProtectedArea/file.tar.gz

 that file cannot check if the downloader is logged in can it.

 So, any suggestions or words of wisdom would be much appreciated :-)

 - --
 Nick Wilson //  www.explodingnet.com



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

 iD8DBQE83N09HpvrrTa6L5oRAlSZAJwNVHXfeP3w8aaJTtRUmPH2v/nvNwCfaqp4
 HpXVvWLn87rkhCQxnBtszAc=
 =St/c
 -END PGP SIGNATURE-

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



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




Re: [PHP] php4 on RedHat 7.1

2001-04-27 Thread Peter H. Lemieux

Take a look at /var/log/httpd/error_log.  Is there an entry for the very
first time the server was run (before you installed PHP 4.04pl)?  Does
it list PHP/4.0 as installed?  The initial entry in my error_log from
the Wolverine beta of 7.1 shows:

[Fri Apr 27 12:36:13 2001] [notice] Apache/1.3.14 (Unix) 
(Red-Hat/Linux) mod_ssl/2.7.1 OpenSSL/0.9.5a DAV/1.0.2 PHP/4.0.4pl1
mod_perl/1.24_01 configured -- resuming normal operations
[Fri Apr 27 12:36:13 2001] [notice] suEXEC mechanism enabled (wrapper:
/usr/sbin/suexec)

In my case the PHP module was loaded by default (along with ssl and
mod_perl) when I chose the install everything option in RedHat.

If it appears in the log, then the module is running.  Put a file called
info.php into /var/www/html with just the line 

? phpinfo() ? 

in it.  What happens when you view it from a browser?

If it's still not working, I suggest you try uninstalling your version
of PHP and installing the PHP4 rpm that comes with RedHat instead. 
Works fine for me.  

Peter 



. wrote:
 
 Yes, it has that in there right out of the box like this:
 
 IfDefine HAVE_PHP4
 LoadModule php4_modulemodules/libphp4.so
 /IfDefine
 #
 # AddType: allows you to tweak mime.types without actually editing it, or to
 # make certain files to be certain types.
 #
 # The following is for PHP4 (conficts with PHP/FI, below):
 IfModule mod_php4.c
   AddType application/x-httpd-php .php4 .php3 .phtml .php
   AddType application/x-httpd-php-source .phps
 /IfModule
 
 It comes like that from a clean install of RH 7.1, but why is it not
 working?  Any Ideas?
 
 Ralph Guzman wrote in message ...
 Your httpd.conf configuration should look something like this:
 
 AddType application/x-httpd-php .php .phtml .php3 .php4
 AddType application/x-httpd-php-source .phps
 
 -Original Message-
 From: j2n tech [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, April 26, 2001 8:42 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] php4 on RedHat 7.1
 
 
 I'm trying to get a webmail client to work under RH 7.1 with Apache 1.3.19.
 I downloaded php-4.0.4pl and configured and installed it.  Now when I try
 to
 bring up a php page it trys to download it instead of execute.  I added the
 AddType line for php4 in my httpd.conf but it made no difference.  I
 noticed Apache 1.3.19 with RH7.1 treats modules differently with the
 IfDefine functions...am i missing something here?  Anybody have any idea
 how
 I might be able to get this to work?
 
 Thanks.
 
 --j2n.
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]