php-general Digest 14 Dec 2007 05:13:25 -0000 Issue 5180

Topics (messages 265844 through 265857):

Re: Session timeout
        265844 by: Richard Heyes

Re: temp tables mysql OT
        265845 by: Zoltán Németh

Re: safe_mode_include_dir
        265846 by: Nisse Engström
        265847 by: Daniel Brown
        265848 by: Tony Beyers
        265849 by: Andrés Robinet

Uploading a file through PHP form
        265850 by: Ron Piggott
        265851 by: Benjamin
        265854 by: Bastien Koert

Gathering data
        265852 by: Eduardo Vizcarra
        265855 by: Bastien Koert
        265856 by: Johny John

Re: // ?>
        265853 by: Johny John

Re: zlib and fopen and stream_filter_append, prebuffer read errors help
        265857 by: Casey

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 ---
You can simulate that, because not always you'll be able to do "init_set"

ini_set(), and when?

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **

--- End Message ---
--- Begin Message ---
2007. 12. 13, csütörtök keltezéssel 10.14-kor tedd ezt írta:
> At 12:20 PM +0100 12/13/07, Zoltán Németh wrote:
> >2007. 12. 12, szerda keltezéssel 20.13-kor tedd ezt írta:
> >  > I would like to create a temporary table to perform searches.
> >>
> >>   From my main table, I need to exclude records that have certain
> >>  fields that are null or empty; and then sort the final result.
> >
> >why do you need a temp table for that?
> >select * from blah where not isnull(checkfield) and checkfield <> ''
> >order by someotherfield
> 
> Zoltán:
> 
> Ok, here's the problem.
> 
> I have a table with over 5000 records.
> 
> There is no index (not my dB) and the records are not complete.
> 
> There is a numeric product_id field, but in the dB this is not in sequence.
> 
> Some records have a product_id, but no product_name.
> 
> I need to travel the dB showing each item in 
> order (product _id) and excluding those products 
> that have no product_name.
> 
> That sounds simple enough, but currently for each 
> step the entire table gets sorted (unless I'm 
> doing it wrong).
> 
> I was thinking that I could:
> 
> 1. Create a temporary table.
> 2. Sort the table once.
> 3. Remove the records that have no product_name
> 4. And then just travel the temporary table for the duration of the script.
> 5. Drop the table when done with it.
> 
> Now, what's wrong with my thinking?

well, sorting 5000 rows if it has some index is negligible time. so
first I would ADD INDEX, then go with my simple query above ;)

if that's not possible, e.g. you have read-only access to the database,
then you really need a temporary table. the fastest way in that case I
think would be something like this:

CREATE TEMPORARY TABLE whatever(
 //fields here
);

SELECT * FROM origtable WHERE product_name != '' ORDER BY product_id
INTO OUTFILE '/tmp/whatever';

LOAD DATA INFILE '/tmp/whatever' INTO TABLE whatever;

and then use table whatever. don't forget to delete the temporary file
after loading data, as it is writable by any user on the server ;)

greets
Zoltán Németh

> 
> Cheers,
> 
> tedd
> 
> 
> 
> 
> 
> 
> -- 
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> 

--- End Message ---
--- Begin Message ---
On Wed, 12 Dec 2007 15:43:28 -0500, "Daniel Brown" wrote:

>     Is there a specific reason you're using require_once() instead of
> include_once() ?  There actually is a difference.... include() and
> include_once() will only include the file if that line of code is
> executed, whereas require() and require_once() will include the file
> even if the line is inside of an if() {} block for which the
> condition(s) are never matched.

Is that still the case?

<http://se2.php.net/manual/en/function.require.php>:

   "require() and include() are identical in every way except
    how they handle failure."

   "Note: Prior to PHP 4.0.2, the following applies: require()
    will always attempt to read the target file, even if the
    line it's on never executes."


/Nisse

--- End Message ---
--- Begin Message ---
On Dec 13, 2007 2:49 PM, Nisse Engström <[EMAIL PROTECTED]> wrote:
> On Wed, 12 Dec 2007 15:43:28 -0500, "Daniel Brown" wrote:
>
> >     Is there a specific reason you're using require_once() instead of
> > include_once() ?  There actually is a difference.... include() and
> > include_once() will only include the file if that line of code is
> > executed, whereas require() and require_once() will include the file
> > even if the line is inside of an if() {} block for which the
> > condition(s) are never matched.
>
> Is that still the case?
>
> <http://se2.php.net/manual/en/function.require.php>:
>
>    "require() and include() are identical in every way except
>     how they handle failure."
>
>    "Note: Prior to PHP 4.0.2, the following applies: require()
>     will always attempt to read the target file, even if the
>     line it's on never executes."

    D'oh!

    This is why it's a good idea to check the manual every so often,
just to re-read things.  :-\

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
No luck with these solutions. What does work is:

 require_once(dirname(__FILE__) . '/../php/support.php');

but I still don't understand why the relative link doesn't work.


On Dec 12, 2007 6:38 PM, Andrés Robinet <[EMAIL PROTECTED]> wrote:
>
> > -----Original Message-----
> > From: Tony Beyers [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, December 12, 2007 5:55 PM
> > To: PHP General list
> > Subject: Re: [PHP] safe_mode_include_dir
> >
> > Sorry about the double posting. I thought I sent the first email
> > before I was subscribed.
> >
> > I definitely should've pointed out that the code works with safe_mode
> > off so I know the paths are correct.
> >
> > I'm actually not the author of the code. I'm a sys admin trying to
> > upgrade the site with safe_mode on.
> >
> > The target directory is a real world readable directory.
> >
> > On Dec 12, 2007 3:43 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
> > >    Tony,
> > >
> > >    Calm down.  It may take us 21 minutes to respond sometimes, but we
> > > will.  No need to repost.  ;-P
> > >
> > > On Dec 12, 2007 3:26 PM, Tony Beyers <[EMAIL PROTECTED]> wrote:
> > > > I'm running php 5.2.5 with these settings in a virtualhost block in
> > > > apache 2.0.61:
> > > >         php_admin_flag safe_mode on
> > > >         php_admin_value include_path "/afs/msu.edu/.../web"
> > > >         php_admin_value safe_mode_include_dir
> > "/afs/msu.edu/.../web"
> > > > I've got an index.php file in web/support/ that does a
> > > > require_once("../includes/support.php");
> > >
> > >    Is there a specific reason you're using require_once() instead of
> > > include_once() ?  There actually is a difference.... include() and
> > > include_once() will only include the file if that line of code is
> > > executed, whereas require() and require_once() will include the file
> > > even if the line is inside of an if() {} block for which the
> > > condition(s) are never matched.
> > >
> > > > Being in afs with write access from multiple people, the uids of
> > the
> > > > files do not match and I get an error stating that. So I put the
> > > > safe_mode_include_dir line above in but it did not fix the problem
> > > > until I used the absolute path in the require_once line.
> > > > Is there a way to include files with relative paths?
> > >
> > >    Of course there is.  For example, say you're in a laterally-equal
> > > directory as one from which you want to include a file.
> > >
> > >    <? include('../otherdir/file.php'); ?>
> > >
> > >    As long as you have permissions to read the files, you're good to
> > > go.  My guess is that you may have done the relative linking
> > > improperly.  Is the file actually `web/includes/support.php` called
> > > from `web/index.php`?
> > >
> > >    The other thing I would suggest is making sure your target include
> > > directory is a real directory and not a symlinked directory.
> > >
> > > --
> > > Daniel P. Brown
> > > [Phone Numbers Go Here!]
> > > [They're Hidden From View!]
> > >
> > > If at first you don't succeed, stick to what you know best so that
> > you
> > > can make enough money to pay someone else to do it for you.
> > >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Hi Tony,
>
> Please keep in mind that the use of
>
>        php_admin_value include_path "/afs/msu.edu/.../web"
>
> ...will prevent a user from changing the include_path because of the "admin"
> part (this is ok for the safe mode include dir, but not for the include_path
> setting I think). So, I'd say you keep the safe_mode_include_dir, and change
> the include path to:
>
>        php_value include_path "/afs/msu.edu/.../web"
>
> Also, it is likely that while using relative paths you run into problems
> because the "current directory" can be anything except the expected one, so
> I'd rather use absolute paths (if it's my own code) or fix it using
> .htaccess files (this is your case as you are a sysadmin) like this:
>
>        php_value include_path "/one/path;/another/path;./"
>
> ... but for that to work you must not use php_admin_value in the virtualhost
> config (notice that this is not related to safe mode security, if safe_mode
> is well configured, it doesn't mind what you are using as include_dir).
>
> If anyone has more ideas... please throw them (and fix my errors).
>
> Rob
>
>
> Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
> 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
> | TEL 954-607-4207 | FAX 954-337-2695
> Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
> bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-diy.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tony Beyers [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 13, 2007 4:56 PM
> To: PHP General list
> Subject: Re: [PHP] safe_mode_include_dir
> 
> No luck with these solutions. What does work is:
> 
>  require_once(dirname(__FILE__) . '/../php/support.php');
> 
> but I still don't understand why the relative link doesn't work.
> 
> 
> On Dec 12, 2007 6:38 PM, Andrés Robinet <[EMAIL PROTECTED]>
> wrote:
> >
> > > -----Original Message-----
> > > From: Tony Beyers [mailto:[EMAIL PROTECTED]
> > > Sent: Wednesday, December 12, 2007 5:55 PM
> > > To: PHP General list
> > > Subject: Re: [PHP] safe_mode_include_dir
> > >
> > > Sorry about the double posting. I thought I sent the first email
> > > before I was subscribed.
> > >
> > > I definitely should've pointed out that the code works with
> safe_mode
> > > off so I know the paths are correct.
> > >
> > > I'm actually not the author of the code. I'm a sys admin trying to
> > > upgrade the site with safe_mode on.
> > >
> > > The target directory is a real world readable directory.
> > >
> > > On Dec 12, 2007 3:43 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
> > > >    Tony,
> > > >
> > > >    Calm down.  It may take us 21 minutes to respond sometimes,
> but we
> > > > will.  No need to repost.  ;-P
> > > >
> > > > On Dec 12, 2007 3:26 PM, Tony Beyers <[EMAIL PROTECTED]> wrote:
> > > > > I'm running php 5.2.5 with these settings in a virtualhost
> block in
> > > > > apache 2.0.61:
> > > > >         php_admin_flag safe_mode on
> > > > >         php_admin_value include_path "/afs/msu.edu/.../web"
> > > > >         php_admin_value safe_mode_include_dir
> > > "/afs/msu.edu/.../web"
> > > > > I've got an index.php file in web/support/ that does a
> > > > > require_once("../includes/support.php");
> > > >
> > > >    Is there a specific reason you're using require_once() instead
> of
> > > > include_once() ?  There actually is a difference.... include()
> and
> > > > include_once() will only include the file if that line of code is
> > > > executed, whereas require() and require_once() will include the
> file
> > > > even if the line is inside of an if() {} block for which the
> > > > condition(s) are never matched.
> > > >
> > > > > Being in afs with write access from multiple people, the uids
> of
> > > the
> > > > > files do not match and I get an error stating that. So I put
> the
> > > > > safe_mode_include_dir line above in but it did not fix the
> problem
> > > > > until I used the absolute path in the require_once line.
> > > > > Is there a way to include files with relative paths?
> > > >
> > > >    Of course there is.  For example, say you're in a laterally-
> equal
> > > > directory as one from which you want to include a file.
> > > >
> > > >    <? include('../otherdir/file.php'); ?>
> > > >
> > > >    As long as you have permissions to read the files, you're good
> to
> > > > go.  My guess is that you may have done the relative linking
> > > > improperly.  Is the file actually `web/includes/support.php`
> called
> > > > from `web/index.php`?
> > > >
> > > >    The other thing I would suggest is making sure your target
> include
> > > > directory is a real directory and not a symlinked directory.
> > > >
> > > > --
> > > > Daniel P. Brown
> > > > [Phone Numbers Go Here!]
> > > > [They're Hidden From View!]
> > > >
> > > > If at first you don't succeed, stick to what you know best so
> that
> > > you
> > > > can make enough money to pay someone else to do it for you.
> > > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > Hi Tony,
> >
> > Please keep in mind that the use of
> >
> >        php_admin_value include_path "/afs/msu.edu/.../web"
> >
> > ...will prevent a user from changing the include_path because of the
> "admin"
> > part (this is ok for the safe mode include dir, but not for the
> include_path
> > setting I think). So, I'd say you keep the safe_mode_include_dir, and
> change
> > the include path to:
> >
> >        php_value include_path "/afs/msu.edu/.../web"
> >
> > Also, it is likely that while using relative paths you run into
> problems
> > because the "current directory" can be anything except the expected
> one, so
> > I'd rather use absolute paths (if it's my own code) or fix it using
> > .htaccess files (this is your case as you are a sysadmin) like this:
> >
> >        php_value include_path "/one/path;/another/path;./"
> >
> > ... but for that to work you must not use php_admin_value in the
> virtualhost
> > config (notice that this is not related to safe mode security, if
> safe_mode
> > is well configured, it doesn't mind what you are using as
> include_dir).
> >
> > If anyone has more ideas... please throw them (and fix my errors).
> >
> > Rob
> >
> >
> > Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
> > 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale,
> FL 33308
> > | TEL 954-607-4207 | FAX 954-337-2695
> > Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
> > bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-
> diy.com
> >
> > --
> > 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

Hi Tony,

dirname(__FILE__) will always give you the script's directory, while
dirname(dirname(__FILE__)) would be equivalent to dirname(__FILE__).'/..'
which is what you are doing now.

Using relative paths is not a good idea, but if you have other people's code
to deal with, you'd better off creating an .htaccess file or editing the
virtualhost configuration than checking file by file for relative paths and
converting them to absolute paths (even with linux tools like sed or awk...
there's no warranty you'll do it right).

AFAIK, when you use relative paths, there are three things to take into
account:

1 - The script that's handling the request (the one that gets called first
and loads every other script). I think this can be queried through
$_SERVER['PHP_SELF'].
2 - The value for the PHP include path which you can obtain using
get_include_path().
3 - The current directory which you can obtain using getcwd(). Usually this
is the directory of the script that got called at first (but this is not
always the case).

However...this is a quote from my offline version of the extended PHP
manual... 

"Files for including are first looked for in each include_path entry
relative to the current working directory, and then in the directory of
current script. E.g. if your include_path is libraries, current working
directory is /www/, you included include/a.php and there is include "b.php"
in that file, b.php is first looked in /www/libraries/ and then in
/www/include/. If filename begins with ./ or ../, it is looked only in the
current working directory."

So... provided that you are using "./script.php" and/or "../script.php"
what's the value for the current directory before you throw the
"require_once"? can you do an "echo getcwd()" in the line above the
"require_once" for testing purposes? Is that what you expect?

Also, keep in mind that for the safe_mode_include_dir directive to work
properly for relative paths, you must also add the shared path to the
include_path directive. Another quote of my offline PHP manual...

"safe_mode_include_dir string 
UID/GID checks are bypassed when including files from this directory and its
subdirectories (directory must also be in include_path or full path must
including). 

As of PHP 4.2.0, this directive can take a colon (semi-colon on Windows)
separated path in a fashion similar to the include_path directive, rather
than just a single directory. 

The restriction specified is actually a prefix, not a directory name. This
means that "safe_mode_include_dir = /dir/incl" also allows access to
"/dir/include" and "/dir/incls" if they exist. When you want to restrict
access to only the specified directory, end with a slash. For example:
"safe_mode_include_dir = /dir/incl/" 

If the value of this directive is empty, no files with different UID/GID can
be included in PHP 4.2.3 and as of PHP 4.3.3. In earlier versions, all files
could be included."

Anyway... for the sake of simplicity you can live with adding
dirname(__FILE__) everywhere for now.... but you'll see how bad it will be
if you have to modify one thousand scripts in this way, with variations such
as require/include, once/not-once, parenthesized/not-parenthesized. And you
will risk breaking legitimate scripts.

So... for the future, think about it.

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-diy.com

--- End Message ---
--- Begin Message ---
How do you upload a file using PHP?  Also what is the web page which
describes the procedure on php.net ?  Thanks, Ron

--- End Message ---
--- Begin Message ---
Try checking out this manual page:
http://us3.php.net/features.file-upload
It includes pretty much everything you'll need to know.

--Ben
On Dec 13, 2007 9:03 PM, Ron Piggott <[EMAIL PROTECTED]> wrote:

> How do you upload a file using PHP?  Also what is the web page which
> describes the procedure on php.net ?  Thanks, Ron
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Benjamin
[EMAIL PROTECTED]

"Dream as if you'll live forever, live as if you'll die today." ~James Dean

--- End Message ---
--- Begin Message ---
Hi Ron,
 
http://www.php.net/manual/en/features.file-upload.php is the page
 
its pretty simple
 
Bastien> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Date: Thu, 13 Dec 2007 
21:03:00 -0500> Subject: [PHP] Uploading a file through PHP form> > How do you 
upload a file using PHP? Also what is the web page which> describes the 
procedure on php.net ? Thanks, Ron> > -- > PHP General Mailing List 
(http://www.php.net/)> To unsubscribe, visit: http://www.php.net/unsub.php> 
_________________________________________________________________
Exercise your brain! Try Flexicon!
http://puzzles.sympatico.msn.ca/chicktionary/index.html?icid=htmlsig

--- End Message ---
--- Begin Message ---
Hi,

I have a web site where the customer can look for some info based on a
destination either by making a click on a link or entering the destination
name in a field in a html form

What is the best way to store that sort of info ? meaning that I want to
store the event of making a click on a certain link OR entering the
destination in the field and hitting the search button, I would like to know
how many hits a link has or how many times the same (or similar) text was
entered

Any recommendation on how to make this happen ?

Regards,
Eduardo

--- End Message ---
--- Begin Message ---
Database...in either case the data that is being searched on makes it to the 
server...just store the search term in a table in the db
 
bastien> To: [EMAIL PROTECTED]> From: [EMAIL PROTECTED]> Date: Sat, 17 Nov 2007 
19:40:14 -0600> Subject: [PHP] Gathering data> > Hi,> > I have a web site where 
the customer can look for some info based on a> destination either by making a 
click on a link or entering the destination> name in a field in a html form> > 
What is the best way to store that sort of info ? meaning that I want to> store 
the event of making a click on a certain link OR entering the> destination in 
the field and hitting the search button, I would like to know> how many hits a 
link has or how many times the same (or similar) text was> entered> > Any 
recommendation on how to make this happen ?> > Regards,> Eduardo> > -- > PHP 
General Mailing List (http://www.php.net/)> To unsubscribe, visit: 
http://www.php.net/unsub.php> 
_________________________________________________________________
Read what Santa`s been up to! For all the latest, visit 
asksantaclaus.spaces.live.com!
http://asksantaclaus.spaces.live.com/

--- End Message ---
--- Begin Message ---
Hi Eduardo,

         From your requirement I understand you need a website with php and
mysql support. If you want to track or search something you need to store
the data in a database or some where else like txt file or xml file/
-- 
Regards,
Johny
www.phpshore.com

--- End Message ---
--- Begin Message ---
On Dec 6, 2007 10:33 PM, Richard Lynch <[EMAIL PROTECTED]> wrote:

> On Tue, December 4, 2007 7:41 pm, Kevin Schmeichel wrote:
> > Here's some unexpected behavior:
> >
> > <?php
> > // ?> what?
> > ?>
> >
> > This will output "what?" - I expected no output, as is the case if the
> > inline comment was a /* */ comment.  Is this a bug?
>
> The <?php and ?> are parsed first, and the // only applies to
> everything up TO the ?> bit.
>
> Don't do that. :-)
>
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/from/lynch
> Yeah, I get a buck. So?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hi All,

Its something interesting.

-- 
Regards,
Johny
www.phpshore.com

--- End Message ---
--- Begin Message ---
On Dec 13, 2007 7:44 AM, Bob Sabiston <[EMAIL PROTECTED]> wrote:
>
> On Dec 12, 2007, at 7:20 PM, Casey wrote:
>
> > Try gzuncompress();
>
> Correct me if I'm wrong, but isn't gzuncompress used for 'gzip'
> files?  Although they both use the same compression, gzip is specific
> to files and has header information not present in straight zlib
> data.  And as I've mentioned, this is a normal file, not compressed --
> I'm just trying to read and decompress pieces of data within the file,
> which according to the documentation is something zlib does.
>
> I assume that most people use these functions for entire files, but
> surely someone has used it the other way as well?
>
> Thanks for any info.
> Bob
>
>


Zlib compression is what's used in Gzip. Just try it ;)

$uncompressed = gzuncompress(file_get_contents("binaryfile.ext"));

-Casey

--- End Message ---

Reply via email to