php-general Digest 9 Sep 2011 16:00:30 -0000 Issue 7471
Topics (messages 314724 through 314746):
Re: PHP sessions expiring early
314724 by: Nilesh Govindarajan
314725 by: Paul Waring
314726 by: Richard Quadling
314727 by: Richard Quadling
314728 by: vikash.iitb.gmail.com
314729 by: Paul Waring
314730 by: Paul Waring
314732 by: Paul Waring
314743 by: Paul Waring
Re: dev to production server
314731 by: James Yerge
314734 by: Mike Mackintosh
314741 by: Chris Stinemetz
314742 by: Chris Stinemetz
314744 by: Alex Nikitin
314745 by: Daevid Vincent
Re: mysql_fetch_object() equivalent for mongoDB
314733 by: Duken Marga
Opening Multiple Files
314735 by: Ron Piggott
314736 by: Florian Müller
314737 by: Stuart Dallas
314738 by: Alex Nikitin
314739 by: Frank Arensmeier
314740 by: Tim Streater
array problem
314746 by: Marc Fromm
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 ---
On 09/07/2011 03:50 PM, Paul Waring wrote:
> I'm having trouble with a PHP website which requires users to be logged
> in to access all content other than the home page and a couple of static
> pages (about us, contact us etc.). Several users have said they are
> being logged out every few minutes whilst using the site - they can
> login but will be shown the login form again after a few minutes. I
> can't confirm this myself as the site seems to work fine for me - even
> using the same browser as they are and under their accounts - but I'm
> wondering if this could be a problem with the session settings?
>
You have set gc_maxlifetime to 3600 seconds. How much expire time have
you set?
Because, every 3600 seconds, session data stored is considered as
garbage and php clears them out itself.
If your expiration time is more than 3600 seconds, then this will not
work. You need to increase gc_maxlifetime.
For the other case, I'm clueless.
--
Nilesh Govindarajan
http://nileshgr.com
--- End Message ---
--- Begin Message ---
On 07/09/11 11:47, Nilesh Govindarajan wrote:
On 09/07/2011 03:50 PM, Paul Waring wrote:
I'm having trouble with a PHP website which requires users to be logged
in to access all content other than the home page and a couple of static
pages (about us, contact us etc.). Several users have said they are
being logged out every few minutes whilst using the site - they can
login but will be shown the login form again after a few minutes. I
can't confirm this myself as the site seems to work fine for me - even
using the same browser as they are and under their accounts - but I'm
wondering if this could be a problem with the session settings?
You have set gc_maxlifetime to 3600 seconds. How much expire time have
you set?
Because, every 3600 seconds, session data stored is considered as
garbage and php clears them out itself.
Yes, I'm aware of that. However, users are being logged out after a few
minutes, not one hour of inactivity (which is what I'd expect with 3600
seconds).
If your expiration time is more than 3600 seconds, then this will not
work. You need to increase gc_maxlifetime.
If you mean the expiration time of the session cookie, it is set to 0,
which means it shouldn't be deleted until the browser is closed (or the
user logs out, at which point it is deleted immediately).
Paul
--
Paul Waring
http://www.phpdeveloper.org.uk
--- End Message ---
--- Begin Message ---
On 7 September 2011 11:20, Paul Waring <[email protected]> wrote:
> I'm having trouble with a PHP website which requires users to be logged in
> to access all content other than the home page and a couple of static pages
> (about us, contact us etc.). Several users have said they are being logged
> out every few minutes whilst using the site - they can login but will be
> shown the login form again after a few minutes. I can't confirm this myself
> as the site seems to work fine for me - even using the same browser as they
> are and under their accounts - but I'm wondering if this could be a problem
> with the session settings?
>
> The current settings I have are:
>
> session.auto_start Off
> session.bug_compat_42 On
> session.bug_compat_warn On
> session.cache_expire 180
> session.cache_limiter nocache
> session.cookie_domain no value
> session.cookie_httponly Off
> session.cookie_lifetime 0
> session.cookie_path /
> session.cookie_secure Off
> session.entropy_file no value
> session.entropy_length 0
> session.gc_divisor 100
> session.gc_maxlifetime 3600
> session.gc_probability 1
> session.hash_bits_per_character 4
> session.hash_function 0
> session.name PHPSESSID
> session.referer_check no value
> session.save_handler files
> session.save_path /shared/sessions
> session.serialize_handler php
> session.use_cookies On
> session.use_only_cookies Off
> session.use_trans_sid 0
>
> The only options I have changed from the defaults are gc_maxlifetime,
> gc_probability and save_path. There are several sites on the same server,
> some are https, others just plain http. They all use the same session
> options. session_start() is called once on every page.
>
> The PHP version we're running is: PHP 5.2.6-1+lenny13 with Suhosin-Patch
> 0.9.6.2 (cli) (built: Jul 1 2011 16:01:01). I'm aware it's an old version
> before anyone tells me to upgrade (it's the latest stable version in Debian
> Lenny). :)
>
> Potential problems I have already ruled out:
>
> 1. I don't think it's a browser problem as the users have a variety of
> browsers and versions (we log the user agent for each login, they're mostly
> IE7/8 on XP/Vista/7 with a few Chrome users), and I can't reproduce the
> problem using the same browsers on my machine.
>
> 2. The server time is correct.
>
> 3. The sessions aren't stored in a directory which is being regularly
> cleared out, such as /var/lib/php5 or /tmp.
>
> 4. The web server has permission to write to the save_path directory, and I
> can see session files being created.
>
> 5. No output buffering functions are being used.
>
> Can anyone suggest things which I could try? I cannot work out why this
> problem is happening for some users but not me.
>
> Thanks in advance.
>
> Paul
How do you handle multiple logins?
If I login using my laptop and get Session A for my account and then I
login using my desktop and get Session B for my account, does Session
A get killed?
Do you allow multiple, simultaneous logins per account?
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---
--- Begin Message ---
On 7 September 2011 11:20, Paul Waring <[email protected]> wrote:
> Can anyone suggest things which I could try? I cannot work out why this
> problem is happening for some users but not me.
For browsers/extensions that do automatic read ahead (I load page A
and linked pages B and C are also retrieved).
Is the potential for cached pages to be returned for a user NOT logged in?
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---
--- Begin Message ---
Just confirm once that you are not calling session_destroy somewhere.
Thanks,
Vikash Kumar
--
http://vika.sh
On 7 September 2011 16:46, Richard Quadling <[email protected]> wrote:
> On 7 September 2011 11:20, Paul Waring <[email protected]> wrote:
> > Can anyone suggest things which I could try? I cannot work out why this
> > problem is happening for some users but not me.
>
> For browsers/extensions that do automatic read ahead (I load page A
> and linked pages B and C are also retrieved).
>
> Is the potential for cached pages to be returned for a user NOT logged in?
>
>
>
> --
> Richard Quadling
> Twitter : EE : Zend : PHPDoc
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On 07/09/11 12:15, Richard Quadling wrote:
How do you handle multiple logins?
If I login using my laptop and get Session A for my account and then I
login using my desktop and get Session B for my account, does Session
A get killed?
Session A is killed, your last login is always the current one.
Do you allow multiple, simultaneous logins per account?
No, but then each user is accessing their account from a single machine
and browser anyway (i.e. they don't switch from desktop to laptop and
then back again), so we don't even have people trying to have
simultaneous logins.
--
Paul Waring
http://www.phpdeveloper.org.uk
--- End Message ---
--- Begin Message ---
On 07/09/11 12:20, [email protected] wrote:
Just confirm once that you are not calling session_destroy somewhere.
The only place session_destroy is called is in the logout function,
which itself is only called if a user clicks the logout link.
--
Paul Waring
http://www.phpdeveloper.org.uk
--- End Message ---
--- Begin Message ---
On 07/09/11 12:16, Richard Quadling wrote:
On 7 September 2011 11:20, Paul Waring<[email protected]> wrote:
Can anyone suggest things which I could try? I cannot work out why this
problem is happening for some users but not me.
For browsers/extensions that do automatic read ahead (I load page A
and linked pages B and C are also retrieved).
I hadn't thought of that. However, we audit all user logins and logouts,
as well as all page requests. If the browser was pre-fetching the logout
page, we'd have 'user logout' entries in our logs, but the only notices
we have are for users logging in. If users were being logged out because
of pre-fetching, I'd expect to see each login entry have a corresponding
logout entry.
Is the potential for cached pages to be returned for a user NOT logged in?
Any pages which a user has viewed whilst logged in shouldn't be cached,
assuming the browser is respecting the headers. They are all sent with:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
--
Paul Waring
http://www.phpdeveloper.org.uk
--- End Message ---
--- Begin Message ---
On 07/09/11 13:42, Richard Quadling wrote:
On 7 September 2011 12:32, Paul Waring<[email protected]> wrote:
On 07/09/11 12:16, Richard Quadling wrote:
On 7 September 2011 11:20, Paul Waring<[email protected]> wrote:
Can anyone suggest things which I could try? I cannot work out why this
problem is happening for some users but not me.
For browsers/extensions that do automatic read ahead (I load page A
and linked pages B and C are also retrieved).
I hadn't thought of that. However, we audit all user logins and logouts, as
well as all page requests. If the browser was pre-fetching the logout page,
we'd have 'user logout' entries in our logs, but the only notices we have
are for users logging in. If users were being logged out because of
pre-fetching, I'd expect to see each login entry have a corresponding logout
entry.
Is the potential for cached pages to be returned for a user NOT logged in?
Any pages which a user has viewed whilst logged in shouldn't be cached,
assuming the browser is respecting the headers. They are all sent with:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
How is your code determining if they need to be redirected back to the
login page?
The test is whether two $_SESSION elements are set and match ones in the
database, plus whether the last page view by the user (stored in the
database, updated on each request) was less than one hour ago.
What changes that information?
A page load changed the 'last page view time'. Nothing changes the other
session data, except an explicit logout (which sets $_SESSION = array()
and calls session_destroy).
Can you monitor it externally?
I'm not sure what you mean by 'externally'. Most of the site requires a
login, so it's not possible for a third-party to monitor it if that's
what you mean.
--
Paul Waring
http://www.phpdeveloper.org.uk
--- End Message ---
--- Begin Message ---
On 09/07/2011 12:24 AM, Chris Stinemetz wrote:
> Does anyone have a procedure or know of any tutorials that explain how
> to take a mac/apache/php/mysql dev environment and converting it to
> production environment?
>
> Basically I want to host my own web site on my local machine now that
> I have finished developing it.
>
> Thanks in advance!
>
I'm not familiar with MAC, however, there are projects out there that
provide everything you need, for the most part. Look up XAMPP, I used to
use this in the past before I setup my own personal server.
http://www.apachefriends.org/en/xampp-macosx.html
This should provide you with an environment necessary for development
and production. I currently run Arch Linux on my personal server and
have installed Apache, PHP, MySQL and so on via the package manager. For
my dev/prod process, I'm using Boilerplate, which provides a default
HTML5/CSS3 template. However, the nice thing about it is, they've also
provided a small build process using ANT. I've modified the ANT build
script to my needs and simply build my production environment using
that, keeping my dev code in tact and readable :) They've integrated the
YUI Compressor into their build process is simply minifies all CSS and
JavaScript.
Anyway, enough about that, just an example of what can be done. There's
always the option of compiling everything from source as well :)
James
--- End Message ---
--- Begin Message ---
On Sep 7, 2011, at 0:24, Chris Stinemetz <[email protected]> wrote:
> Does anyone have a procedure or know of any tutorials that explain how
> to take a mac/apache/php/mysql dev environment and converting it to
> production environment?
>
> Basically I want to host my own web site on my local machine now that
> I have finished developing it.
>
> Thanks in advance!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
By local, do you mean a local dedicated box, or an everyday use box?
The checklist varies quite a bit depending on the results.
Also, is your site to be served by standard port 80 traffic? Does your Internet
host allow inbound port 80?
--- End Message ---
--- Begin Message ---
>
> By local, do you mean a local dedicated box, or an everyday use box?
It is an everyday use box.
>
> The checklist varies quite a bit depending on the results.
>
> Also, is your site to be served by standard port 80 traffic? Does your
> Internet host allow inbound port 80?
Yes it will be served by standard port 80 traffic and yes my Internet
host allows inbound port 80.
--- End Message ---
--- Begin Message ---
On Wed, Sep 7, 2011 at 6:23 AM, James Yerge <[email protected]> wrote:
> On 09/07/2011 12:24 AM, Chris Stinemetz wrote:
>
> Does anyone have a procedure or know of any tutorials that explain how
> to take a mac/apache/php/mysql dev environment and converting it to
> production environment?
>
> Basically I want to host my own web site on my local machine now that
> I have finished developing it.
>
> Thanks in advance!
>
>
> I'm not familiar with MAC, however, there are projects out there that
> provide everything you need, for the most part. Look up XAMPP, I used to use
> this in the past before I setup my own personal server.
>
> http://www.apachefriends.org/en/xampp-macosx.html
>
> This should provide you with an environment necessary for development and
> production. I currently run Arch Linux on my personal server and have
> installed Apache, PHP, MySQL and so on via the package manager. For my
> dev/prod process, I'm using Boilerplate, which provides a default HTML5/CSS3
> template. However, the nice thing about it is, they've also provided a small
> build process using ANT. I've modified the ANT build script to my needs and
> simply build my production environment using that, keeping my dev code in
> tact and readable :) They've integrated the YUI Compressor into their build
> process is simply minifies all CSS and JavaScript.
>
> Anyway, enough about that, just an example of what can be done. There's
> always the option of compiling everything from source as well :)
>
> James
>
Thank you James. I appreciate your advise.
Chris
--- End Message ---
--- Begin Message ---
If you have to ask these questions, i don't think you should be the person
to do it, i'm sorry.
I wouldn't recommend doing it on a mac, or even one single box, i wouldnt
recommend doig it on non-server hardware, infact most of the time i would
recommend you just buy already pre-sertup servers so that all you have to do
is set up your database, upload your application and be done with it, VPS or
a ded box will serve the purpose quite nicely depending on your needs.
It's not rocket science, but building a production server requires some
know-how and a bit of experience. You need to know each component to
configure it well, you need to know the OS, you need to secure it, and you
may need to tweak it to perform better and you need to know your application
to maximize performance of all of the components, and you need to be up to
date on current trends and technology to again, maximize your throughput.
You need to know systems and you need to think solutions, unless you really
dont care, but that's how you end up with a 5rps website that's about as
secure as a taped carboard box. Infact, in my practice, i took a poorly
implemented box that could only serve 5rps at 128M mem usage (and climbing)
and 100% cpu utilization, and got it to serve 340rps using 14MB memory with
no visible cpu load (like sub 2% spikes) and with no code modifications; and
i could take it farther, infact i did on the testing server where i got it
to over 600rps, but i only had 4 hours to find, tweak and test before
pushing to production and i wasn't allowed to tweak the bone-stock OS or
build anything (held true for the 600+ mark)... Some day i wanna take the
smallest ec2 instance and see how far i can really push it, though the
people i did the above for found it pretty impressive that they could click
on any page on the site (it was a social media experiment and so parts were
constantly updated) and have it loaded instantly, even when i was pounding
on the server...
Anyways not trying to stroke my ego by any means, or tell you that you
shouldn't do it, infact you should do it, its a lot of fun and great
perplexing headache for a while, all i'm trying to say is that you should
think about either buying a production environment, or you should really
start learning yourself some advanced OS and lots of layer 7...
Just my $.02
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
On Wed, Sep 7, 2011 at 12:24 AM, Chris Stinemetz
<[email protected]>wrote:
> Does anyone have a procedure or know of any tutorials that explain how
> to take a mac/apache/php/mysql dev environment and converting it to
> production environment?
>
> Basically I want to host my own web site on my local machine now that
> I have finished developing it.
>
> Thanks in advance!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Alex Nikitin [mailto:[email protected]]
> Sent: Wednesday, September 07, 2011 8:47 AM
> To: Chris Stinemetz
> Cc: PHP General
> Subject: Re: [PHP] dev to production server
>
> If you have to ask these questions, i don't think you should be the person
> to do it, i'm sorry.
>
> [snip]
>
> or tell you that you shouldn't do it,
> infact you should do it, its a lot of fun and great
> perplexing headache for a while, all i'm trying to say is that you should
> think about either buying a production environment, or you should really
> start learning yourself some advanced OS and lots of layer 7...
Now there's a contradiction. ;-)
Anyways, I do agree with Alex though. Setup and maintenance of a five nines
server is non-trivial. You might look into one of the cheap hosting services
that use VMs to start with. If you out-grow that, it's pretty easy to
migrate your VM to iron. A buddy of mine just joined http://www.linode.com
and seems to really like it.
Having said that, I would STRONGLY suggest you ditch the whole XAMP, WAMP,
MAMP, WTF? they call it these days. Setup VirtualBox (it's free and cross
platform). Then setup a VM to be as close to EXACTLY as your production
environment as possible (sans hardware specs of course). I mean, same
distro, same tools, same versions, same configs, same directory structures.
Develop on that. Setup a repository (subversion is easy, well supported and
battle tested). Then just do an export from SVN to your PROD box.
I have some code snippets that you may find useful here:
http://daevid.com/content/examples/snippets.php
(And the first person that gives me grief that the page doesn't work in some
obscure browser like Safari or something I will bitch-slap. I *know* this. I
don't CARE. This is what happens when you use a Framework - and why I have
such distain for them. Ceiton went (.)(.) up and so now I'm stuck with
minified code in German no less. Use Firefox or IE, or change your
user-agent string to trick the page if you insist on using
Chrome/Safari/Opera/etc. .... or don't go to the page at all, it's no sweat
off my ____ )
So I digress... back on task...
You also should setup a test VM too. So deploy from DEV to TEST first, let
someone (preferably besides yourself) hammer away at that, and once you feel
it's stable -- in a few days or week -- push to PROD. You have to let the
code 'bake' on test to make sure there are no regression bugs or new bugs.
I work for a company now where the CTO (by default since it's his company
;-) ) constantly pushes to PROD too early IMHO. It's bitten us more than
once. He's so eager to get the new features in front of customers, he
doesn't see the potential damage it's doing to the reputation. Granted our
customers are pretty forgiving, but still, I would prefer to see a longer
DEV-TEST-PROD cycle...
d
--- End Message ---
--- Begin Message ---
Actually, there is no statement in PHP that can return data from
MongoDB as object (CMIIW). Data are returned as array.
You can convert this array to object using (object).
Look an example at
http://www.richardcastera.com/blog/php-convert-array-to-object-with-stdclass
$posts = (object) $mongo->find();
echo 'Id: ' . $posts->Id;
--
Duken Marga
On Wed, Sep 7, 2011 at 1:28 PM, chamila gayan <[email protected]> wrote:
> hi all,
>
> Is anybody aware of mysql_fetch_object() equivalent/similar implementation
> for mongoDB?
> thanks..
>
> ~Chamila Gayan
>
--- End Message ---
--- Begin Message ---
Hi Everyone
I am trying to load an HTML book into mySQL. The book was distributed with
each chapter being it’s own HTML file.
The only way I know how to open a file is by specifying the file name. Such as:
$myFile = "B01C001.htm";
$lines = file($myFile);
foreach ($lines as $line_num => $theData) {
Is there a way PHP will open each file in the directory ending in “.htm”, one
file at a time, without me specifying the file name?
When the file is open I need the FOREACH (above) to parse the content which
ends with an “INSERT INTO” for a mySQL table.
Thank you in advance for any help you are able to give me.
Ron
The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info
--- End Message ---
--- Begin Message ---
Why don't u solve it by iterating through all files and getting their filenames
and then execute your file?
> From: [email protected]
> To: [email protected]
> Date: Wed, 7 Sep 2011 10:21:18 -0400
> Subject: [PHP] Opening Multiple Files
>
>
> Hi Everyone
>
> I am trying to load an HTML book into mySQL. The book was distributed with
> each chapter being it’s own HTML file.
>
> The only way I know how to open a file is by specifying the file name. Such
> as:
>
> $myFile = "B01C001.htm";
> $lines = file($myFile);
> foreach ($lines as $line_num => $theData) {
>
> Is there a way PHP will open each file in the directory ending in “.htm”, one
> file at a time, without me specifying the file name?
>
> When the file is open I need the FOREACH (above) to parse the content which
> ends with an “INSERT INTO” for a mySQL table.
>
> Thank you in advance for any help you are able to give me.
>
> Ron
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
--- End Message ---
--- Begin Message ---
On 7 Sep 2011, at 15:21, Ron Piggott wrote:
> Hi Everyone
>
> I am trying to load an HTML book into mySQL. The book was distributed with
> each chapter being it’s own HTML file.
>
> The only way I know how to open a file is by specifying the file name. Such
> as:
>
> $myFile = "B01C001.htm";
> $lines = file($myFile);
> foreach ($lines as $line_num => $theData) {
>
> Is there a way PHP will open each file in the directory ending in “.htm”, one
> file at a time, without me specifying the file name?
>
> When the file is open I need the FOREACH (above) to parse the content which
> ends with an “INSERT INTO” for a mySQL table.
Look at the manual pages for glob and readdir - both will do what you need.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--- End Message ---
--- Begin Message ---
On Wed, Sep 7, 2011 at 10:21 AM, Ron Piggott <[email protected]
> wrote:
>
> Hi Everyone
>
> I am trying to load an HTML book into mySQL. The book was distributed with
> each chapter being it’s own HTML file.
>
> The only way I know how to open a file is by specifying the file name.
> Such as:
>
> $myFile = "B01C001.htm";
> $lines = file($myFile);
> foreach ($lines as $line_num => $theData) {
>
> Is there a way PHP will open each file in the directory ending in “.htm”,
> one file at a time, without me specifying the file name?
>
> When the file is open I need the FOREACH (above) to parse the content which
> ends with an “INSERT INTO” for a mySQL table.
>
> Thank you in advance for any help you are able to give me.
>
> Ron
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
>
opendir/closedir and readdir/rewinddir functions come to mind, you can
easily iterate through files in a directory that way...
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
--- End Message ---
--- Begin Message ---
7 sep 2011 kl. 16.21 skrev Ron Piggott:
>
> Hi Everyone
>
> I am trying to load an HTML book into mySQL. The book was distributed with
> each chapter being it’s own HTML file.
>
> The only way I know how to open a file is by specifying the file name. Such
> as:
>
> $myFile = "B01C001.htm";
> $lines = file($myFile);
> foreach ($lines as $line_num => $theData) {
>
> Is there a way PHP will open each file in the directory ending in “.htm”, one
> file at a time, without me specifying the file name?
>
http://se.php.net/manual/en/function.glob.php
/frank
> When the file is open I need the FOREACH (above) to parse the content which
> ends with an “INSERT INTO” for a mySQL table.
>
> Thank you in advance for any help you are able to give me.
>
> Ron
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
--- End Message ---
--- Begin Message ---
On 07 Sep 2011 at 15:21, Ron Piggott <[email protected]> wrote:
> Hi Everyone
>
> I am trying to load an HTML book into mySQL. The book was distributed with
> each chapter being it’s own HTML file.
>
> The only way I know how to open a file is by specifying the file name. Such
> as:
>
> $myFile = "B01C001.htm";
> $lines = file($myFile);
> foreach ($lines as $line_num => $theData) {
>
> Is there a way PHP will open each file in the directory ending in “.htm”,
> one file at a time, without me specifying the file name?
You can use opendir() and readdir() to get the filenames one by one.
--
Cheers -- Tim
--- End Message ---
--- Begin Message ---
I am reading a csv file into an array. The csv file.
users.csv file contents:
w12345678,a
w23456789,b
w34567890,c
$csvfilename = "users.csv";
$handle = fopen($csvfilename, "r");
if($handle) {
while (($line =
fgetcsv($handle, 1000, ",")) !== FALSE) {
$arrUsers[] =
$line;
}
fclose($handle);
}
When I echo out the elements in the elements in the array $arrUsers I get:
Array
Array
Array
foreach ($arrUsers as $user){
echo $user . "<br />";
}
I can't figure out why the word Array is replacing the actual data.
--- End Message ---