php-general Digest 7 Mar 2011 23:37:26 -0000 Issue 7216
Topics (messages 311727 through 311740):
Re: $GLOBALS example script on php.net
311727 by: Ashim Kapoor
Re: $$var
311728 by: Colin Guthrie
Re: Returning a recordset to a desktop app
311729 by: Richard Quadling
Re: imap_search ?
311730 by: Alex
Help translating PHP5 code to PHP4.
311731 by: Marc Guay
311732 by: sexyprout
311737 by: Richard Quadling
311738 by: Marc Guay
Re: Regex for extracting quoted strings
311733 by: Shawn McKenzie
Re: Overriding session length in existing session?
311734 by: Scott Baker
311735 by: Scott Baker
311736 by: Scott Baker
Am I missing something about escapeshellarg
311739 by: Kevin Chadwick
Re: Somewhat OT - Stored Procedures
311740 by: Nathan Nobbe
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 ---
<?php
$globalvar1=1;
$globalvar2=2;
function globals() {
$globals = $GLOBALS;
var_dump($GLOBALS);
print_r("<br />Before...");
print_r($globals);
foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}
print("<br />After...");
print_r($globals);
return $globals;
}
globals();
?>
array(7) { ["GLOBALS"]=> array(7) { ["GLOBALS"]=> *RECURSION* ["_POST"]=>
array(0) { } ["_GET"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["_FILES"]=>
array(0) { } ["globalvar1"]=> int(1) ["globalvar2"]=> int(2) } ["_POST"]=>
array(0) { } ["_GET"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["_FILES"]=>
array(0) { } ["globalvar1"]=> int(1) ["globalvar2"]=> int(2) }
Before...Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET]
=> Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) [globalvar1] => 1
[globalvar2] => 2 )
After...Array ( [globalvar1] => 1 [globalvar2] => 2 )
Ok I see it now.
Thank you all,
Ashim.
--- End Message ---
--- Begin Message ---
'Twas brillig, and sexyprout at 06/03/11 15:16 did gyre and gimble:
> ∞
And beyond!
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mageia Contributor [http://www.mageia.org/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--- End Message ---
--- Begin Message ---
On 5 March 2011 13:48, Ken Watkins <[email protected]> wrote:
> On 3/5/2011 4:30 AM, Richard Quadling wrote:
>> On 4 March 2011 23:48, Ken Watkins <[email protected]> wrote:
>>> Hi All.
>>>
>>> I have a Windows desktop app that I created using Visual Foxpro (a database
>>> app).
>>> I want to write a PHP script that I will call from my desktop app. The
>>> script will simply
>>> query a MySQL database on my web server and return the recordset to the
>>> desktop app.
>>>
>>> My question is simply this: What is the preferred method for passing this
>>> recordset back
>>> to the desktop app? I'm assuming that there's no reasonable way to send a
>>> recordset back
>>> without converting it to an array or XML or an object or something? How do
>>> I return the
>>> data in the recordset to the desktop app?
>>>
>>> Thanks for your advice.
>>> Ken Watkins
>> In general terms, the output of a PHP script is going to be text
>> (html, xml, csv, etc.) or binary (images).
>>
>> Getting a PHP script to communicate natively with FoxPro is not going
>> to be trivial task. It MAY be able to be done, but hopefully FoxPro
>> has the capability of running a PHP script via the command line ...
>>
>> C:\PHP5\php.exe -f script.php -- script_arg1 script_arg2
>>
>> PHP can either output the result set (in an appropriate form) directly
>> and FoxPro could read it from STDIN (if it has that support) or PHP
>> can write the answer to a file and FoxPro can use normal file and
>> string functions to read the data.
>>
>> If FoxPro has XML support, then use it. It will be much cleaner in the
>> long run if the data changes. If not, then a tab separated data file
>> (rather than a CSV file). This assumes that your data does not contain
>> tabs. If so, choose another separator.
>>
>> Richard.
> Richard,
>
> Foxpro does have XML support, so you answered that part of my question,
> thanks.
> And it is capable of calling any other executable on the local machine
> through the
> local OS shell - which seems to be what you are advocating. But I'm not sure
> how
> I would do that over the internet. I just discussed this issue with Larry,
> and I assume
> that I would use HTTP? Or is there a way to call a command line script on a
> remote
> web server without using HTTP? Sorry if this is a stupid question.
>
> Thanks for your help!
> Ken
So, what you need to have is an HTTP Request from within FoxPro.
http://www.example-code.com/foxpro/http_post_form.asp
gives an example, but it seems to use a third party ActiveX component.
If FoxPro can load any locally resident/installed ActiveX component,
then maybe ...
http://fox.wikis.com/wc.dll?Wiki~ReadUrl
has better examples.
So, using something from that to get the data (XML) and then using
FoxPro's native support for XML and you should be on your way.
But at this stage, I'd be looking to ask for further help in a FoxPro
forum as this is really nothing to do with PHP.
Good luck.
Richard.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
Imap remains open after you search and doesn't close until you call imap_close.
Firstly the code shouldn't be written like that, while should not operate on a
fail condition of a function exec, that's just bad coding practice and that's
what causes a loop here. If there are no messages in the email box, imap search
will return false, and you will have a loop until it gets a message...
Here is what your scrip does:
First run:
Get all messages
Gets array of messages
Fails while condition
Fetch
Print
Delete all
Exit
Next time:
Get messages
Gets false (no messages)
Hits while loop where by it will continue to send imap requests until a message
hits the mail box (your almost infinite loop)
.....
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Tontonq Tontonq <[email protected]> wrote:
hi ! it works if there is / are emails in the box before script run (i use cli
not web based) but after it works 1 time it doesnt work again it enters to
infinite loop , at that line while(!$emails) { $emails =
imap_search($inbox,'ALL'); echo "email yok\n"; print_r($emails); }
imap_search($inbox,'ALL'); it doesn't try to research emails in $inbox, doesn't
it stay as connected or it's just for 1 time use :S ? should i reuse imap_open
everytime when i need to use imap_search ? $inbox =
imap_open($hostname,$usernamex,$password) or die('Cannot connect to domain:' .
imap_last_error()); function onayla() { global $inbox; $emails =
imap_search($inbox,'ALL'); while(!$emails) { $emails =
imap_search($inbox,'ALL'); echo "email yok\n"; print_r($emails); } echo
"\nyeaah"; print_r($emails); if($emails) { rsort($emails); echo "Number of
email:".imap_num_msg($inbox); foreach($emails as $email_number) { $overview =
imap_fetch_overview($inbox,$email_number,0);
if(stristr($overview[0]->subject,"Test")) { $message =
imap_fetchbody($inbox,$email_number,1); echo "$message\n\r";
//$link=arasi('activate:','-- The',$message); //echo "\n\r".$link;
#fwrite(fopen("deneme.txt",w),file_get_contents($link));
//imap_delete($inbox,'1:*'); //imap_expunge($inbox); } } }
imap_delete($inbox,'1:*'); imap_expunge($inbox); }
--- End Message ---
--- Begin Message ---
Hi folks,
I've stumbled into a project involving a server running PHP4 without
cURL. The script fetches data from an XML webservice and deals with
it. Is http://ca2.php.net/xml_parser_create the place to start? Any
tips (besides updating PHP)?
Here's an example of the PHP5 code:
$url = "http://www.domain.com/webservice.php?var=foo";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$val = curl_exec($ch);
curl_close($ch);
libxml_use_internal_errors(true);
$xml = simplexml_load_string($val);
$errors = libxml_get_errors();
if (!($errors)){
$myvariable = $xml->attributes()->value;
}
else{
// deal with errors
}
--- End Message ---
--- Begin Message ---
Just take another web host.
2011/3/7 Marc Guay <[email protected]>
> Hi folks,
>
> I've stumbled into a project involving a server running PHP4 without
> cURL. The script fetches data from an XML webservice and deals with
> it. Is http://ca2.php.net/xml_parser_create the place to start? Any
> tips (besides updating PHP)?
>
> Here's an example of the PHP5 code:
>
> $url = "http://www.domain.com/webservice.php?var=foo";
> $ch = curl_init($url);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> $val = curl_exec($ch);
> curl_close($ch);
> libxml_use_internal_errors(true);
> $xml = simplexml_load_string($val);
> $errors = libxml_get_errors();
>
> if (!($errors)){
> $myvariable = $xml->attributes()->value;
> }
> else{
> // deal with errors
> }
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
sexyprout
--- End Message ---
--- Begin Message ---
On 7 March 2011 16:16, Marc Guay <[email protected]> wrote:
> Hi folks,
>
> I've stumbled into a project involving a server running PHP4 without
> cURL. The script fetches data from an XML webservice and deals with
> it. Is http://ca2.php.net/xml_parser_create the place to start? Any
> tips (besides updating PHP)?
>
> Here's an example of the PHP5 code:
>
> $url = "http://www.domain.com/webservice.php?var=foo";
> $ch = curl_init($url);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> $val = curl_exec($ch);
> curl_close($ch);
> libxml_use_internal_errors(true);
> $xml = simplexml_load_string($val);
> $errors = libxml_get_errors();
>
> if (!($errors)){
> $myvariable = $xml->attributes()->value;
> }
> else{
> // deal with errors
> }
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Is it a SOAP service? If so, PHP supports SOAP natively using
SOAPClient (and you can create your own SOAPServers too).
Depending upon your requirement, you could use simplexml_load_string()
to convert an XML string into a native PHP object rather than manually
parsing the text of the XML string.
Can you give any more details?
Richard.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
Hi Richard,
It's not a SOAP service, and I've actually decided to have ask the
client to upgrade their server software before continuing. But for
the sake of study:
> Depending upon your requirement, you could use simplexml_load_string() to
> convert an XML string into a native PHP object rather than manually parsing
> the text of the XML string.
I looked up simplexml_load_string() and the manual seems to say that
it's only available in PHP5. Can you clarify?
Marc
--- End Message ---
--- Begin Message ---
On 03/05/2011 04:38 PM, Mark Kelly wrote:
> Hi.
>
> Thanks for all the replies.
>
> On Saturday 05 Mar 2011 at 22:11 Simon J Welsh wrote:
>
>> On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote:
>>> $regex = '/"([^"]+)"/';
>
> Shawn, this regex gets me two copies of each string - one with and one
> without
> the double quotes - as did the one Nathan posted earlier.
>
>> Also, you'll want preg_match_all rather than preg_match.
>
> Yeah, I realised that quite early on in my messing about.
>
> What I have ended up with is:
>
> $regex = '/".*?"/';
> $found = preg_match_all($regex, $sentence, $phrases);
>
> This still leaves the quotes in the phrases, but at least I only get one copy
> of each phrase. I'm just trimming the quotes afterwards.
>
> Thanks for all the advice.
>
> Mark
$sentence = 'Dave said "This is it". "Nope, that is the wrong colour"
she replied.';
$regex = '/"([^"]+)"/';
preg_match_all($regex, $sentence, $phrases);
print_r($phrases[1]);
--
Thanks!
-Shawn
http://www.spidean.com
--- End Message ---
--- Begin Message ---
On 03/04/2011 11:48 AM, Marc Guay wrote:
> I think that my suggestion is still a valid solution, someone correct
> me if I'm wrong. Let's say your code went like this:
>
> session_start();
I did a ton of digging and came up with session_regenerate_id()
In my header.php I start the session as normal, and IF the user selects
"public terminal" I use the call set the session cookie length as 0 and
then regenerate the session cookie.
if ($public_term) {
session_set_cookie_params(0);
session_regenerate_id();
}
This way it defaults to a cookie of X days, but if it's a public
terminal it resets the cookie to expire at browser close.
--- End Message ---
--- Begin Message ---
On 03/04/2011 11:48 AM, Marc Guay wrote:
> I think that my suggestion is still a valid solution, someone correct
> me if I'm wrong. Let's say your code went like this:
>
> session_start();
I did a ton of digging and came up with session_regenerate_id()
In my header.php I start the session as normal, and IF the user selects
"public terminal" I use the call set the session cookie length as 0 and
then regenerate the session cookie.
if ($public_term) {
session_set_cookie_params(0);
session_regenerate_id();
}
This way it defaults to a cookie of X days, but if it's a public
terminal it resets the cookie to expire at browser close.
--- End Message ---
--- Begin Message ---
On 03/04/2011 11:48 AM, Marc Guay wrote:
> I think that my suggestion is still a valid solution, someone correct
> me if I'm wrong. Let's say your code went like this:
>
> session_start();
I did a ton of digging and came up with session_regenerate_id()
In my header.php I start the session as normal, and IF the user selects
"public terminal" I use the call set the session cookie length as 0 and
then regenerate the session cookie.
if ($public_term) {
session_set_cookie_params(0);
session_regenerate_id();
}
This way it defaults to a cookie of X days, but if it's a public
terminal it resets the cookie to expire at browser close.
--- End Message ---
--- Begin Message ---
I just posted the following at
"http://stackoverflow.com/questions/3481880/what-php-extensions-are-preferred-and-what-about-security-preferences/5223539#5223539"
Am I missing anything or are all these guides and hosts either not
disabling enough functions or disabling security aids to give warning
messages with dangerous results.
_________________________________________________________________________
"Why do so many hosts and guides disable escapeshell[arg|cmd] which are
security aids!!!! and leave shell_exec enabled.
Leads to opening up your servers to untrusted execution due to things
like this.
"http://www.silverstripe.org/hosting-requirements/show/10777"
The only thing I can think of is using it twice might cause problems
and safe mode used to be widespread and so would apply escapeshellcmd
automatically And now the hosts just copy configs blindly and in error
and don't understand and so trust the 100s of threads that say you
should do this.
Yeah, use it as reference, I'm looking at it, but don't trust it
because some "good" host uses it"
__________________________________________________________________________
Surely this matters more than removing safe mode despite defence in
depth because users believe it to be a safety blanket and may not also
use chroot and permissions etc.
--- End Message ---
--- Begin Message ---
On Fri, Mar 4, 2011 at 7:29 AM, Richard Quadling <[email protected]>wrote:
> On 3 March 2011 18:30, Nathan Nobbe <[email protected]> wrote:
> > Hey gang,
> >
> > (Yes Tedd, I like your style, when it pertains to how you address the
> list
> > :))
> >
> > I have a new curiosity that's arisen as a result of a new contract I'm
> > working on, I'd like to bounce around some thoughts off the list and see
> > what you folks think if interested.
> >
> > The topic at hand is stored procedures. Frankly, I've hardly ever even
> seen
> > these in use, and what I'm trying to figure out are good rules of thumb
> as
> > to where / when / how they are best used in application development.
> >
> > Also, bear in mind that personally I tend to favor OO paradigms for
> > application development so would prefer feedback that incorporates that
> > tendency.
> >
> > Initial thoughts are
> >
> > Bad:
> > . Not well suited for ORM, particularly procedures which return multiple
> > result sets consisting of columns from multiple tables
> > . Greater potential for duplicated logic, I think this comes down to a
> well
> > defined set of rules for any given application, read: convention required
> > for success
> > . Scripting languages are vendor specific, and likely most application
> > developers have a limited understanding thereof
> >
> > Good:
> > . Better performance
> > . <Fill in blank on convincing bullets here>
> >
> > I've also done some reading on MSSQL vs. MySQL and found that the former
> > offers much more features. I've also read that most databases only see
> > roughly 40% of the feature sets being used for typical applications in
> the
> > wild, and would agree from personal experience it is accurate.
> >
> > From my standpoint MySQL is popular because the features it offers are
> the
> > features folks are really looking, one of those 80/20 things...
> >
> > I stumbled into this link on a google search, it's from '04 but looks to
> be
> > relevant to this day
> >
> >
> http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html
> >
> > Your thoughts appreciated,
> >
> > -nathan
> >
>
> Hello Nathan.
>
> I develop for and on Windows using IIS7 and MS SQL Server 7/2000/2005/2008.
>
i love how you preface many of your responses like this.
> Almost exclusively I use prepared statements to talk to stored
> procedures and views. I use triggers and constraints to enforce RDI. I
> _do_ have the occasional hacky script which includes SQL, but only
> 'cause I was being lazy and wanted to do a one off change.
>
this sounds as if you're doing next to 0 query generation from php, is that
correct?
At a fundamental level, my PHP code isn't concerning itself with any
> physical data structures. As much as possible my PHP code treats the
> sql data source as a processor ready to supply data in a standardized
> form (even hierarchical) and to accept data for storage (again
> hierarchical). My PHP code knows next to nothing about the table
> structure (why should it - it isn't a database). It does know that a
> "customer" object has a set of properties and a set of "instruments of
> change" which are passed to the SQL server to effect the data and are
> cached locally. PHP deals in objects/entities. Stored procedures
> provide the translation between the OOP and the RDBMS. This provides a
> nice clean interface between PHP and the data. The stored procedures
> and views are all pre-compiled - with their internal usage statistics
> to make best use of available indices and are tuned to the actual data
> rather than something I thought I knew about the data usage when I
> designed the DB. So speed is much more significant. Having every
> single SQL statement compiled from scratch for a 1 off use would seem
> wasteful.
>
> Multiple result sets are completely fine (at least for MS SQL Server)
> - Admittedly you have to currently process the result sets in
> sequential order (i.e. set 1 before moving to set 2 - can't move back
> to set 1). But that is something quite easy to work with when you know
> the limitation. And is the easiest way to get hierarchical data into
> PHP for me. I get all the relevant data in 1 hit rather than getting
> the data with potential mis-matching values due to the realtime
> multi-user environment.
>
i understand the ability to consume multiple result sets is available. the
issue i think would be raised with an orm would be getting result sets with
mixed columns from multiple tables. im not sure how capable an orm like
propel (for example) is of mapping those results back to objects. at a
glance of google results it appears the result is just an array which
sacrifices the abstraction the orm aims to provide.
-nathan
--- End Message ---