php-general Digest 27 Nov 2010 00:33:11 -0000 Issue 7056

Topics (messages 309680 through 309691):

MySQL database export to Excel
        309680 by: Sotiris Katsaniotis
        309681 by: Steve Staples

Re: Spoofing user_agent
        309682 by: Richard Quadling
        309683 by: Richard Quadling

Re: Possible issue in mail() function?
        309684 by: Richard Quadling
        309686 by: Tom Hendrikx
        309687 by: Tom Hendrikx
        309688 by: Richard Quadling

Re: preg_match fails to resolve variable as a subject
        309685 by: Richard Quadling
        309689 by: Tamara Temple

code quest
        309690 by: Kirk Bailey
        309691 by: Adam Richardson

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 ---
Greetings fellow PHP developers!

I am looking of a relatively simple way to export a whole database into an Excel file. I have several methods to export tables to Excel files but unfortunately I have failed to export a whole database!

Can someone be so kind to point me in the right direction?

Thanks a lot!

--- End Message ---
--- Begin Message ---
On Fri, 2010-11-26 at 15:21 +0200, Sotiris Katsaniotis wrote:
> Greetings fellow PHP developers!
> 
> I am looking of a relatively simple way to export a whole database into 
> an Excel file. I have several methods to export tables to Excel files 
> but unfortunately I have failed to export a whole database!
> 
> Can someone be so kind to point me in the right direction?
> 
> Thanks a lot!
> 
DISCLAIMER
  This is untested, and just off the top of my pointy head, do some
research, and know how much strain this COULD put on your system.
/DISCLAIMER

there are MANY MySQL commands that you can use, and combine them into 1
script, and then export them into excel, using multiple pages with
something like this:

http://www.codediesel.com/php/creating-excel-documents-in-php/

example mysql queries:
SHOW DATABASES; -- gets a lits of all the databases (skip MySQL and
information_schema)

SHOW TABLES FROM {tablename};  -- gets all the tables in a specific
database


SELECT column_name FROM information_schema.columns WHERE
table_name='{tablename}' AND table_schema='{databasename}'; -- gets you
a list of all the column headers (there are other ways you can avoid
doing this, but this works)


SELECT * FROM {databasename}.{tablename}; -- gets all the rows from a
table in the database


if you were to create a script, and providing your scipt has enough
"max_execution_time", and "memory_limit" (should prolly be done from the
CLI)  you can prolly get it done... 

and yeah, this is a pointer to how it *COULD* be done, but it's not the
only way, nor is it prolly the best either.

Good Luck, and if you need more MySQL related questions answered, try
the [email protected] mailing list.  they are really good over
there.


Steve



--- End Message ---
--- Begin Message ---
Please don't top post.

On 25 November 2010 15:38, Ron Piggott <[email protected]> wrote:
>
> Is "User Agent" suppose to have a hyphen  "-"  ?   Ron
>
>
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
> -----Original Message----- From: Richard Quadling
> Sent: Thursday, November 25, 2010 9:16 AM
> To: Deva
> Cc: Shreyas Agasthya ; Ron Piggott ; [email protected] ;
> [email protected]
> Subject: Re: [PHP] Fw: Spoofing user_agent
>
> On 25 November 2010 11:32, Deva <[email protected]> wrote:
>>
>> Use curl
>> http://php.net/manual/en/book.curl.php
>>
>>
>> On Thu, Nov 25, 2010 at 4:41 PM, Shreyas Agasthya
>> <[email protected]>wrote:
>>
>>> I feel you should use more of the 4th method here as you are not trying
>>> to
>>> read the file but the header level  (7th layer) information of the HTTP
>>> protocol.
>>>
>>> http://php.net/manual/en/function.file-get-contents.php
>>>
>>>
>>> --Shreyas
>>>
>>> On Thu, Nov 25, 2010 at 4:11 PM, Ron Piggott <
>>> [email protected]
>>> > wrote:
>>>
>>> >   Will the header pass with using file_get_contents , or should I be
>>> using
>>> > another command, and if so, which one?  Ron
>>> >
>>> > <?php
>>> >
>>> >     header('User Agent: RonBot (http://www.example.com)');
>>> >     $url = "http://www.example.com";; <http://www.example.com%22;>
>>> >
>>> >         $input = file_get_contents($url);
>>> >
>>> >
>>> >
>>> > The Verse of the Day
>>> > “Encouragement from God’s Word”
>>> > http://www.TheVerseOfTheDay.info
>>> >
>>> >  *From:* Shreyas Agasthya <[email protected]>
>>> > *Sent:* Thursday, November 25, 2010 4:21 AM
>>> > *To:* Ron Piggott <[email protected]>
>>> > *Cc:* [email protected] ; [email protected]
>>> > *Subject:* Re: [PHP] Fw: Spoofing user_agent
>>> >
>>> > A standard HTTP Request headers is : User Agent (without the >
>>> > underscore).
>>> >
>>> > --Shreyas
>>> >
>>> > On Thu, Nov 25, 2010 at 2:36 PM, Ron Piggott <
>>> > [email protected]> wrote:
>>> >
>>> >>
>>> >> Is this what you are telling me to do:
>>> >>
>>> >> header('user_agent: RonBot (http://www.theverseoftheday.info)');
>>> >>
>>> >> Ron
>>> >>
>>> >> The Verse of the Day
>>> >> “Encouragement from God’s Word”
>>> >> http://www.TheVerseOfTheDay.info
>>> >>
>>> >> From: [email protected]
>>> >> Sent: Thursday, November 25, 2010 3:34 AM
>>> >> To: Ron Piggott ; [email protected]
>>> >> Subject: Re: [PHP] Fw: Spoofing user_agent
>>> >>
>>> >> You need to set it in the header request you make. Putting it in the
>>> >> script you're using as a spider with ini_set won't do anything because
>>> the
>>> >> Target site doesn't know anything about it.
>>> >>
>>> >> Thanks,
>>> >> Ash
>>> >> http://www.ashleysheridan.co.uk
>>> >>
>>> >> ----- Reply message -----
>>> >> From: "Ron Piggott" <[email protected]>
>>> >> Date: Thu, Nov 25, 2010 08:25
>>> >> Subject: [PHP] Fw: Spoofing user_agent
>>> >> To: <[email protected]>
>>> >>
>>> >> I have wrote a script to generate a sitemap of my web site.  It crawls
>>> all
>>> >> of the site web pages.  (About 30,000)
>>> >>
>>> >> I need help to spoof the user_agent variable so the stats program
>>> running
>>> >> in the background ( “AWSTATS” ) will treat the crawl as a bot, not
>>> browsing
>>> >> usage.
>>> >>
>>> >> The sitemap generator is a cron job.  I tried the syntax:
>>> >> ini_set('user_agent', 'RonBot (http://www.theverseoftheday.info)/'/);
>>> >>
>>> >> This didn’t work.  The browsing was attributed to the dedicated IP
>>> >> address.
>>> >>
>>> >> How do I get AWSTATS to access this, such as other entries under the
>>> >> “Robots/Spiders visitors” heading:
>>> >> Unknown robot (identified by 'bot*')
>>> >>
>>> >> I don’t mean any ill will by changing this setting.  Thanks for the
>>> help.
>>> >>
>>> >> Ron
>>> >>
>>> >> The Verse of the Day
>>> >> “Encouragement from God’s Word”
>>> >> http://www.TheVerseOfTheDay.info
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > Regards,
>>> > Shreyas Agasthya
>>> >
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Shreyas Agasthya
>>>
>>
>>
>>
>> --
>> :DJ
>>
>
> It is no use using header(). This sets a header for the client, not
> the server of any file_get_contents() requests.
>
> I use stream_contexts.
>
> $s_Contents = file_get_contents(
>  $s_URL,
>  False,
>  stream_context_create(
>   array(
>     'http' => array(
>       'method' => 'GET',
>       'header' => "User-Agent: RonBot (http://www.example.com)\r\n"
>     ),
>   )
>  )
> );
>
> You can supply cookies, or anything else, with the request. Make sure
> you add a \r\n to each of the headers and just concatenate them.
>
> If you are doing this in a loop, then I'd recommend creating a default
> stream context and then the request would just be ...
>
> $s_Contents = file_get_contents($s_URL);
>
> As the default stream context would be applied.
>
> I had to use a default stream context to route all http requests
> through an NTLM authentication proxy server because PHP doesn't deal
> with NTLM authentication.
>
> See my user notes on
> http://docs.php.net/manual/en/function.stream-context-get-default.php.
> Don't bother with the link at the bottom of the user note- it's not
> live.
>
> Richard.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>

http://en.wikipedia.org/wiki/User_agent "... the identity is
transmitted via the User-Agent request header, ... "



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
> On 25 November 2010 15:38, Ron Piggott <[email protected]> wrote:
>>
>> Is "User Agent" suppose to have a hyphen  "-"  ?   Ron
> http://en.wikipedia.org/wiki/User_agent "... the identity is
> transmitted via the User-Agent request header, ... "

http://tools.ietf.org/html/rfc1945#section-10.15

       User-Agent     = "User-Agent" ":" 1*( product | comment )

   Example:

       User-Agent: CERN-LineMode/2.15 libwww/2.17b3


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 25 November 2010 21:30, Tom Hendrikx <[email protected]> wrote:
> Hi,
>
> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
> a warning when used. A simple debug script with the contents:
>
> <?php
> // recipient, subject, body
> mail("[email protected]", "mail() test", "This is a test");
> ?>
>
> does send mail, but it also raises a warning:
>
> Warning: mail(1): failed to open stream: Permission denied in
> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>
> After some googling [1] and fiddling with permissions, the message
> disappears when php has write permissions to the file
> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
> following data:
>
> ==8<==
> mail() on [/var/www/www.example.com/htdocs/test-mail/index.php:5]: To:
> [email protected] -- Headers:
> ==8<==
>
> Is this some debug output that someone forgot to remove?
>
> When relevant, the sendmail_path used is "/usr/sbin/sendmail -t -i",
> which is a regular Postfix sendmail.
>
> [1] http://stackoverflow.com/questions/1906403
>
> --
> Kind regards,
>        Tom Hendrikx

Are you logging your emails via the ini setting mail.log? Maybe this
is the issue.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 26/11/10 15:54, Richard Quadling wrote:
> On 25 November 2010 21:30, Tom Hendrikx <[email protected]> wrote:
>> Hi,
>>
>> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
>> a warning when used. A simple debug script with the contents:
>>
>> <?php
>> // recipient, subject, body
>> mail("[email protected]", "mail() test", "This is a test");
>> ?>
>>
>> does send mail, but it also raises a warning:
>>
>> Warning: mail(1): failed to open stream: Permission denied in
>> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>>
>> After some googling [1] and fiddling with permissions, the message
>> disappears when php has write permissions to the file
>> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
>> following data:
> 
> Are you logging your emails via the ini setting mail.log? Maybe this
> is the issue.
> 

Erh, actually, yes I am. Documentation of the setting is rather sparse,
but I enabled it some time ago, expecting it to send the data to the
logging facility (syslog in my case), after which I forgot to check if
that actually happens. The current implementation is rather useless (to
me), so I turned it off again.

Thanks for the tip, but I think that this is actually a bug? Current way
of logging is not very useful, since the file '1' is overwritten (in
stead of appended to) with new data at every run of the mail() function.

--
Regards,
        Tom

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---
--- Begin Message ---
On 26/11/10 15:54, Richard Quadling wrote:
> On 25 November 2010 21:30, Tom Hendrikx <[email protected]> wrote:
>> Hi,
>>
>> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
>> a warning when used. A simple debug script with the contents:
>>
>> <?php
>> // recipient, subject, body
>> mail("[email protected]", "mail() test", "This is a test");
>> ?>
>>
>> does send mail, but it also raises a warning:
>>
>> Warning: mail(1): failed to open stream: Permission denied in
>> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>>
>> After some googling [1] and fiddling with permissions, the message
>> disappears when php has write permissions to the file
>> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
>> following data:
>>
>> ==8<==
>> mail() on [/var/www/www.example.com/htdocs/test-mail/index.php:5]: To:
>> [email protected] -- Headers:
>> ==8<==
>>
>> Is this some debug output that someone forgot to remove?
>>
>> When relevant, the sendmail_path used is "/usr/sbin/sendmail -t -i",
>> which is a regular Postfix sendmail.
>>
>> [1] http://stackoverflow.com/questions/1906403
>>
>> --
>> Kind regards,
>>        Tom Hendrikx
> 
> Are you logging your emails via the ini setting mail.log? Maybe this
> is the issue.
> 
> 

Erh, actually, yes I am. Documentation of the setting is rather sparse,
but I enabled it some time ago, expecting it to send the data to the
logging facility (syslog in my case), after which I forgot to check if
that actually happens. The current implementation is rather useless (to
me), so I turned it off again.

Thanks for the tip, but I think that this is actually a bug? Current way
of logging is not very useful, since the file '1' is overwritten (in
stead of appended to) with new data at every run of the mail() function.

--
Regards,
        Tom



--- End Message ---
--- Begin Message ---
On 26 November 2010 15:12, Tom Hendrikx <[email protected]> wrote:
> On 26/11/10 15:54, Richard Quadling wrote:
>> On 25 November 2010 21:30, Tom Hendrikx <[email protected]> wrote:
>>> Hi,
>>>
>>> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
>>> a warning when used. A simple debug script with the contents:
>>>
>>> <?php
>>> // recipient, subject, body
>>> mail("[email protected]", "mail() test", "This is a test");
>>> ?>
>>>
>>> does send mail, but it also raises a warning:
>>>
>>> Warning: mail(1): failed to open stream: Permission denied in
>>> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>>>
>>> After some googling [1] and fiddling with permissions, the message
>>> disappears when php has write permissions to the file
>>> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
>>> following data:
>>
>> Are you logging your emails via the ini setting mail.log? Maybe this
>> is the issue.
>>
>
> Erh, actually, yes I am. Documentation of the setting is rather sparse,
> but I enabled it some time ago, expecting it to send the data to the
> logging facility (syslog in my case), after which I forgot to check if
> that actually happens. The current implementation is rather useless (to
> me), so I turned it off again.
>
> Thanks for the tip, but I think that this is actually a bug? Current way
> of logging is not very useful, since the file '1' is overwritten (in
> stead of appended to) with new data at every run of the mail() function.
>
> --
> Regards,
>        Tom
>
>

I'm on windows and my mail.log shows me all the mail I've sent using
the mail() command since I turned it on.

But according to
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/standard/mail.c?view=markup#l227,
the mail.log file is opened in append mode.

I'm guessing PHP isn't responsible here.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 26 November 2010 00:07, Da Rock <[email protected]> wrote:
> preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command), &$matches)

Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---

On Nov 25, 2010, at 6:07 PM, Da Rock wrote:
preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command), & $matches)

it looks like you're failing to account for the newline that comes back in a command execution. Add trim() around the exec() call and try again.
--- End Message ---
--- Begin Message --- Hello all, my name is Kirk Bailey, and I am new to php, so please be forbearing. I code in python, and am trying to learn this language as our new client runs a web business based in it.

I need a routine that will return a list of every directory immediately under the current directory- but nothing else, just a list of directories, 1 level deep, NO FILES, no listing of current dir or prior dir either.

Now in python, I would use os.walk, and use the list of dirs and throw the other 2 lists away, but this ain't Kansas anymore. Does php even DO lists?

Um, a list is a 1 dimenional array, if have a list ALIST and you plug in 3, you get back the contents of cell 3 in the list, whaqtever that content is. so if cell 3 in a 6 celled list was "Ruby" then ALIST[3] would return the string "ruby".

It's easy to iterate lists. For instance:

   print '<ul>'
   for dir in ALIST:
       print '<li><a href=\"/dir>",dir,'</a>
   print '</ul>

This would let me produce an ordered list of directories, each a link to that directory. This way, when a client installs a new product, the home page area listing products offered automatically updates.

Further embellishment would let me replace the dir name with a BRIEF description from a descriptor file read from that dir. Now how to do this in php?

--
end

Very Truly yours,
                - Kirk Bailey,
                  Largo Florida

kniht +-----+ | BOX | +-----+ think
--- End Message ---
--- Begin Message ---
On Fri, Nov 26, 2010 at 7:03 PM, Kirk Bailey <[email protected]>wrote:

> Hello all, my name is Kirk Bailey, and I am new to php, so please be
> forbearing. I code in python, and am trying to learn this language as our
> new client runs a web business based in it.
>
> I need a routine that will return a list of every directory immediately
> under the current directory- but nothing else, just a list of directories, 1
> level deep, NO FILES, no listing of current dir or prior dir either.
>
> Now in python, I would use os.walk, and use the list of dirs and throw the
> other 2 lists away, but this ain't Kansas anymore. Does php even DO lists?
>
> Um, a list is a 1 dimenional array, if have a list ALIST and you plug in 3,
> you get back the contents of cell 3 in the list, whaqtever that content is.
> so if cell 3 in a 6 celled list was "Ruby" then ALIST[3] would return the
> string "ruby".
>
> It's easy to iterate lists. For instance:
>
>   print '<ul>'
>   for dir in ALIST:
>       print '<li><a href=\"/dir>",dir,'</a>
>   print '</ul>
>
> This would let me produce an ordered list of directories, each a link to
> that directory.
> This way, when a client installs a new product, the home page area listing
> products offered automatically updates.
>
> Further embellishment would let me replace the dir name with a BRIEF
> description from a descriptor file read from that dir. Now how to do this in
> php?
>
> --
> end
>
> Very Truly yours,
>                - Kirk Bailey,
>                  Largo Florida
>
>                      kniht                        +-----+
>     | BOX |                       +-----+                        think
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
To get you started:

function get_directories($path)
{
   $files_and_dirs = scandir($path);
   $dirs = array_filter($files_and_dirs, function($elem) { return
is_dir($elem); });
   // $dirs also contains "." and "..", but you can get rid of them quite
easily
   return $dirs;
}

Happy coding :)

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---

Reply via email to