Re: [PHP] COM - Assigning to method.

2013-07-15 Thread Andrew Ballard
On Mon, Jul 15, 2013 at 4:21 AM, Adam Nicholls inkysp...@gmail.com wrote:
 Hi Andrew

 Thanks for this.

 But I'm still getting errors. I think I need to explain a bit more.

 Unfortunately there isn't a PHP API for this application I'm trying to
 interact with, my goal really is to be able to expose the COM
 functionality over a web-service such as SOAP so I can use it in a
 CMS. The application I'm trying to integrate with is Blackbuad's
 Raiser's Edge - API documentation here:
 https://www.blackbaud.com/files/support/guides/re7ent/api.pdf

 I think part of the problem is that the field names are also
 represented by an integer. So to get data out I would do:

 $oBank-Fields(22);   // which maps to BANK_fld_BRANCH_NAME.

 When I do:

 $oBank-22 = 'blah blah';

 I get an error because a property can't be numeric, it has to start as
 alpha character. If I use:

 $oBank-BANK_fld_BRANCH_NAME = 'blah blah blah';

 I get the following error:

 Fatal error: Uncaught exception 'com_exception' with message 'Unable
 to lookup `BANK_fld_BRANCH_NAME': Unknown name.

 I've also tried using your Value property returned by Fields():

 $oBank-Fields(22)-Value = 'Blah Blah blah blah';

 Which I then get:
 PHP Warning:  Creating default object from empty value in [C:\Users]
 Fatal error: Call to undefined method variant::Save()

 Soo seems nearly impossible to implement a safe way to write to the COM API.


 At the moment, I'm still in the scoping/prototype stage of my project,
 so I'm beginning to think that using this COM API for this project is
 a no-go, which is unfortunate. I'm also guessing even if we did
 implement this API, exposing it as a Web Service is going to be tricky
 for performance sake (given that I've read that COM doesn't
 multithread very well??)

 Many Thanks
 Adam.

It's definitely possible to do, once you figure out the syntax you
need for this object.

I'm guessing you must have gotten past the $oBank-Init() method call
without issues.

What happens if you just use this for the value assignment?

$oBank-Fields(BANK_fld_ACCOUNT_NAME) = Test account;
$oBank-Fields(BANK_fld_ACCOUNT_NO) = 12345;
$oBank-Fields(BANK_fld_BANK) = Bank of the Nation;
$oBank-Fields(BANK_fld_BRANCH_NAME) = State Street Branch;

It also looks like you're getting errors from the call to
$oBank-Save() saying that the method is not defined.

Andrew

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



Re: [PHP] COM - Assigning to method.

2013-07-14 Thread Andrew Ballard
On Sun, Jul 14, 2013 at 3:18 PM, Adam Nicholls inkysp...@gmail.com wrote:

 Richard - I've tried that I get an error about it not being defined as
 property of the object.

 Andrew - do you mean try using the method Richard has shown?

 Cheers
 Adam.

 On 13 July 2013 17:11, Richard Quadling rquadl...@gmail.com wrote:
 
 
 
  On 13 July 2013 01:24, Andrew Ballard aball...@gmail.com wrote:
 
  On Jul 12, 2013 4:53 AM, Adam Nicholls inkysp...@gmail.com wrote:
  
   Hi Guys/Gals,
  
   I'm doing some integration work with a COM API and according to their
   documentation to save data in the API, you have to assign to the
   method.
  
   This is their example in Visual Basic:
  
  
 
  -
   Set oBank = New CBank
   oBank.Init Application.SessionContext
   With oBank
   .Fields(BANK_fld_ACCOUNT_NAME) = Test account
   .Fields(BANK_fld_ACCOUNT_NO) = 12345
   .Fields(BANK_fld_BANK) = Bank of the Nation
   .Fields(BANK_fld_BRANCH_NAME) = State Street Branch
   End With
   oBank.Save
  
 
  -
  
   Obviously in PHP is isn't possible to assign to a method in this way
   (thats what parameters are for!) So I'm at a bit of a loose end. I'm
   wondering if anyone else has come across this? Or am I missing
   something obvious in PHP's implementation of the COM that allows me to
   work around this?
  
   My PHP Code is looks like this:
  
 
  -
   $API = new COM('API7.API');
   $API-Init($SerialNo, $Login, '', 1, '', 1);
   $API-SignOutOnTerminate = True;
  
   $Record = new COM(Data.Record);
   $Record-Init($API-SessionContext);
  
   $Record-Fields('BANK_fld_ACCOUNT_NAME') = 'Test Account';//doesn't work
  
 
  -
  
   I've also tried (below) but the API says wrong number of parameters
   $Record-Fields('BANK_fld_ACCOUNT_NAME', 'Test Account');
  
   I've also tried something crazy like this (below) but that overwrites
   the $Record object.
   $_R = $Record-Fields('BANK_fld_ACCOUNT_NAME');
   $_R = 'Test Account';
  
  
   Any ideas? Is it possible?
  
  
   Many Thanks
   Adam Nicholls
  
 
  That example isn't assigning values to method return value. Fields is a
  collection of ADO Field objects. The default property of a Field object is
  its Value property, so the shorthand is simply assigning the values of the
  variables to the value of each field in a record within a Recordset.
 
  Andrew
 
 
  So ..
 
  $oBank-BANK_fld_ACCOUNT_NAME = Test account;
 
  sort of thing.
 
  --
  Richard Quadling
  Twitter : @RQuadling



 --
 Adam Nicholls

Richard has the general idea correct, but as I recall it is a little
more involved because it's COM. I've never done that much with COM in
PHP because it was always such a pain. The example you posted probably
used to require com_set() in PHP 4, although it looks like that has
been deprecated in favor of a more typical OO syntax in PHP 5. Is
there any chance there is a PHP version of the library that you can
work with to avoid COM? If not, hopefully what follows will help start
you on the right direction.

A more explicit version of your original VBScript example looks like this:

Set oBank = New CBank
oBank.Init Application.SessionContext

Set oField = oBank.Fields(BANK_fld_ACCOUNT_NAME)
oField.Value = Test account
Set oField = oBank.Fields(BANK_fld_ACCOUNT_NO)
oField.Value = 12345
Set oField = oBank.Fields(BANK_fld_BANK)
oField.Value = Bank of the Nation
Set oField = oBank.Fields(BANK_fld_BRANCH_NAME)
oField.Value = State Street Branch

oBank.Save


I'm not familiar with your CBank COM class, but the rest of it looks
like it is similar to the COM('ADODB.Recordset'). If so, a rough
translation of your original example should resemble this:

?php
// I'm not familiar with this object, so I'm guessing on the call to
instantiate it here.
$oBank = new COM('CBank');

/**
Application.SessionContext in the original refers to an object that is
global to every request in an application. PHP does not have such a
global registry, so I'm not sure where you're $config needs to come
from.
*/
$oBank-Init($config);

/**
I am assuming that BANK_fld_ACCOUNT_NAME and such are constant names
that were already defined with the names of the actual column names in
a recordset returned by $oBank.
*/
$oBank-Fields(BANK_fld_ACCOUNT_NAME)-Value = Test account;
$oBank-Fields(BANK_fld_ACCOUNT_NO)-Value = 12345;
$oBank-Fields(BANK_fld_BANK)-Value = Bank of the Nation;
$oBank-Fields(BANK_fld_BRANCH_NAME)-Value = State Street Branch;

$oBank-Save();

?

I don't know if you could leave out the -Value part of the syntax in
PHP like you can in the VBScript example you posted. If so, then
Richard's syntax would have been pretty

Re: [PHP] COM - Assigning to method.

2013-07-12 Thread Andrew Ballard
On Jul 12, 2013 4:53 AM, Adam Nicholls inkysp...@gmail.com wrote:

 Hi Guys/Gals,

 I'm doing some integration work with a COM API and according to their
 documentation to save data in the API, you have to assign to the
 method.

 This is their example in Visual Basic:


-
 Set oBank = New CBank
 oBank.Init Application.SessionContext
 With oBank
 .Fields(BANK_fld_ACCOUNT_NAME) = Test account
 .Fields(BANK_fld_ACCOUNT_NO) = 12345
 .Fields(BANK_fld_BANK) = Bank of the Nation
 .Fields(BANK_fld_BRANCH_NAME) = State Street Branch
 End With
 oBank.Save

-

 Obviously in PHP is isn't possible to assign to a method in this way
 (thats what parameters are for!) So I'm at a bit of a loose end. I'm
 wondering if anyone else has come across this? Or am I missing
 something obvious in PHP's implementation of the COM that allows me to
 work around this?

 My PHP Code is looks like this:

-
 $API = new COM('API7.API');
 $API-Init($SerialNo, $Login, '', 1, '', 1);
 $API-SignOutOnTerminate = True;

 $Record = new COM(Data.Record);
 $Record-Init($API-SessionContext);

 $Record-Fields('BANK_fld_ACCOUNT_NAME') = 'Test Account';//doesn't work

-

 I've also tried (below) but the API says wrong number of parameters
 $Record-Fields('BANK_fld_ACCOUNT_NAME', 'Test Account');

 I've also tried something crazy like this (below) but that overwrites
 the $Record object.
 $_R = $Record-Fields('BANK_fld_ACCOUNT_NAME');
 $_R = 'Test Account';


 Any ideas? Is it possible?


 Many Thanks
 Adam Nicholls


That example isn't assigning values to method return value. Fields is a
collection of ADO Field objects. The default property of a Field object is
its Value property, so the shorthand is simply assigning the values of the
variables to the value of each field in a record within a Recordset.

Andrew


Re: [PHP] Webpage Persistence Load balancing

2013-05-29 Thread Andrew Ballard
On May 29, 2013 8:04 AM, Al n...@ridersite.org wrote:

 I'm having a webpage Persistence problem, it is intermittent.  I suspect
it is caused by load-balancing.

 Specifically:

 Users are connected to a webpage form to complete.  Generally, everything
is OK if they take a minute or even more to complete the form. However,
sometimes they report to me, and I've seen it myself, the connection has
been dropped by the server in a short time.  They enter the data and Submit
it to the server, and the page just reloads and their data is lost.

 I have the PHP ignore_user_abort(true); etc.

 Is there anything I can do to fix this or is it a server issue that you
must fix?

 Thanks, Al.


Are you using sessions for persistence? If so, is your session storage in a
location that is shared between servers behind the load balancer? (Shared
network path, database, etc.)

Andrew


Re: [PHP] Saving session to database

2013-05-17 Thread Andrew Ballard
I've found database session storage requires extra diligence in error
handling. When I see that error at 0 it is usually because something blew
up either before the session handler was ready or after it was torn down.

Andrew
On May 17, 2013 2:42 PM, Matijn Woudt tijn...@gmail.com wrote:

 On Fri, May 17, 2013 at 8:07 PM, Lester Caine les...@lsces.co.uk wrote:

  Matijn Woudt wrote:
 
 
  It seems to me the session functions are failing, probably due to
  problems with
  the database. Have you checked that there actually is a ##session table
  in your
  database?
  You might want to add some debugging code to these functions, to check
 if
  errors
  occur with inserting or retrieving the sessions from the database.
 
 
  Well past that stage without making any progress.
  Using the write function outside of the session_set_save_handler() it
  works perfectly, and then the read can see the saved sessions and can
 load
  them.
 
  I am convinced that something is wrong with the general setup which is
  preventing the write and close from firing when it should. I can not
 trace
  any attempt to call the write function in the session handling.
 
  I'm currently checking out the adodb-session handler which WAS working in
  PHP5.3 but seems to be showing similar problems in PHP5.4
 
 
 Well, I'm not sure what would be the problem here, but some general
 comments:
 There have been various changes in session handling between 5.3 and 5.4, so
 most likely it is in there. Check if there are any references to
 register_shutdown_function, and replace them with
 session_register_shutdown.
 Second, check the return value of session_set_save_handler, it is a bad
 habit not checking return value of a function, just because it works.
 If that doesn't help, take the session piece out of the big framework, and
 test it in a separate file. If that also fails, you've got a small piece of
 code you can post here which will encourage others to have a look at it at
 their box.

 - Matijn



Re: [PHP] array_map() with multiple callback functions

2013-05-08 Thread Andrew Ballard
On Tue, May 7, 2013 at 5:43 PM, Alex Nikitin niks...@gmail.com wrote:
 On Tue, May 7, 2013 at 4:29 PM, George Langley george.lang...@shaw.ca wrote:
 Hi all. I want to apply strtolower() AND trim() to all items in an array. 
 But I don't see a way to call multiple callbacks with the array_map() 
 function.
 Are my two choices the following:

 // 1) nesting two array_map() calls
 $cleanData = array_map('trim',(array_map('strtolower',$rawData)));


 // 2) call my own function with array_walk()
 $cleanData = array_walk('myCleaner',$rawData);

 function myCleaner($passedData){
 $cleanData = array_map('strtolower',$passedData);
 $cleanData = array_map('trim',$cleanData);
 }
 //(Of course, wouldn't bother with a function, just to call array_map 
 twice...)

 Just seeing if there's a better way than having to go through the array 
 twice to apply each callback separately. Thanks,
 Something like:

 $cleanData = array_map(function($str){return strtolower(trim($str));},
 $passedData);

I'd go with this general approach, whether you use a named function or
an anonymous function for the callback. I don't know how large the
array is, but option #1 iterates the input array twice and option #2
iterates the array three times. If you eventually need to add
additional functions to clean the input, they would add even more
iterations. This approach only iterates once.

Andrew

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



Re: [PHP] Load testing an app

2013-04-24 Thread Andrew Ballard
On Apr 24, 2013 9:46 PM, tamouse mailing lists tamouse.li...@gmail.com
wrote:

 On Tue, Apr 23, 2013 at 8:04 AM, Andrew Ballard aball...@gmail.com
wrote:
  On Tue, Apr 23, 2013 at 2:29 AM, Adam Richardson simples...@gmail.com
wrote:
  On Mon, Apr 22, 2013 at 10:41 PM, Andrew Ballard aball...@gmail.com
wrote:
  The other developer in our office spent some time profiling the site
with
  xdebug and found that an exec() call to netsh used on a couple pages
seems
  to take 2-4 seconds to complete. Unfortunately, those exec() calls
are the
  one function that we cannot test in our development environment.

 I'm wondering if it would be possible to carve out the part doing the
 netsh calls so they're not part of your web application's stack, and
 make them an asynchronous part?

Possibly, but it needs to be as close as possible to real time. We've been
looking into caching the results for a short time (15sec?) so concurrent
requests can share results. The problem right now is that we can't seem to
duplicate the issue we were having, so it's impossible to know for sure
whether any solution we try actually solves the problem.

Andrew


Re: [PHP] Load testing an app

2013-04-23 Thread Andrew Ballard
On Tue, Apr 23, 2013 at 2:29 AM, Adam Richardson simples...@gmail.com wrote:

 On Mon, Apr 22, 2013 at 10:41 PM, Andrew Ballard aball...@gmail.com wrote:

 The other developer in our office spent some time profiling the site with
 xdebug and found that an exec() call to netsh used on a couple pages seems
 to take 2-4 seconds to complete. Unfortunately, those exec() calls are the
 one function that we cannot test in our development environment. We are
 considering some optimizations, but since load on the production server is
 at a seasonal low we want to duplicate the problem so we can measure the
 impact of any changes we make. We spent most of today hammering the site
 with JMeter today in an attempt to reproduce the issue. While we were
 easily able to slow the site to a crawl (some samples taking over 2 minutes
 to complete), the server returned to normal as soon as the test concluded
 and it never became totally unresponsive like it did this past fall.


 If you can't test the exec calls, directly, I'd refactor the functionality 
 that calls exec() so you could pass in replacement functionality that creates 
 that artificially creates the pause in your development environment:


I'm not sure the issue is solely because of the delay. At any rate, we
were running the load test yesterday against the production system
that was having problems last fall. I wish we had a test system where
we could test everything end-to-end, but unfortunately we can't
duplicate the DHCP part of the production environment.

 2 quick notes:

 If you have a linux box available, I like the simplicity of siege, but jmeter 
 is nice, too:
 http://www.joedog.org/siege-home/


Hahahaha. This system AND the DHCP both USED to run on linux boxes.
This task was much simpler then, because the DHCP table was a text
file that we parsed and updated directly from PHP. It was decided to
standardize on a single platform to make system maintenance and
security management simpler, and most of our client/server stack was
already Windows. If necessary, I could probably spin up a virtual box
for testing though.

 The site is running PHP 5.3 on IIS/Windows Server 2003. The netsh calls are
 to a DHCP server on a separate Windows server, and the database is SQL
 Server 2008 (previously 2000).


 PHP 5.4 offers performance improvements. I don't suspect the migration from 
 SQL Server 2003 to 2008 caused any of these issues.


I can't imagine the DB upgrade would have caused it. I think at the
same time he switched to using Zend_Db (not the full framework, just
the DB library) over top of the SQL Server driver for PHP for database
queries.


 So, any ideas we can try?


 We'd probably have to know more about what the netsh calls were doing.


This particular call is querying DHCP for a list of leases within a
specific scope so we can get the MAC address of the client. Once we
authenticate the user, calls on later pages expire the current lease
for that MAC address on a private subnet and create a semi-permanent
lease on the public subnet.

Our testing yesterday stepped through the process beginning with this
initial DHCP query (which was the long running process identified in
profiling) and the next few very simple pages but stopped short of
actually making any changes to the network assignment. With a single
user, the first page takes a couple seconds and the next few pages are
50ms. During testing yesterday, we had the system stressed enough to
stretch those times out past a couple minutes.

It looks like we're going to have to continue the test into the next
part of the sign-up process, but that will take some time to learn
about JMeter conditional logic. I suspect we'll have to wait a couple
weeks until students are gone before we can actually run that level of
testing.

Andrew

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



[PHP] Load testing an app

2013-04-22 Thread Andrew Ballard
I'm looking for ideas to help load test a PHP site my office wrote and
maintains. Peak usage for this site is during the fall when new students
arrive, and for the first time this past fall the traffic rendered the web
server completely unresponsive, almost as quickly as we could restart it.
The only major change to the site last year was to upgrade the database
server the site uses, but the curious thing is that it was the web server
rather than the database that became unresponsive. Other apps could
continue to use the database without any performance issues, and the
database server performance counters suggest it wasn't even breaking a
sweat.

The other developer in our office spent some time profiling the site with
xdebug and found that an exec() call to netsh used on a couple pages seems
to take 2-4 seconds to complete. Unfortunately, those exec() calls are the
one function that we cannot test in our development environment. We are
considering some optimizations, but since load on the production server is
at a seasonal low we want to duplicate the problem so we can measure the
impact of any changes we make. We spent most of today hammering the site
with JMeter today in an attempt to reproduce the issue. While we were
easily able to slow the site to a crawl (some samples taking over 2 minutes
to complete), the server returned to normal as soon as the test concluded
and it never became totally unresponsive like it did this past fall.

We're both new to JMeter. I know a single test server may not be able to
create enough simultaneous requests to accurately simulate real traffic,
but I'm fairly confident that our tests involved far more (roughly-)
simultaneous connections than we were experiencing live. (The first test
used 20 threads; we gradually increased the threads for each test to 500
threads before we quit for the day.) The site is on a private subnet, so
distributed and/or cloud-based testing are probably not options.

The site is running PHP 5.3 on IIS/Windows Server 2003. The netsh calls are
to a DHCP server on a separate Windows server, and the database is SQL
Server 2008 (previously 2000).

So, any ideas we can try?

Andrew


Re: [PHP] Looking for complete entered URL

2013-04-21 Thread Andrew Ballard
Correct. Just to expand on that, a browser will not send the hash fragment
part of a URL with the request. If you ever receive that part at the web
server, that's a pretty good sign the request came from a robot.

Andrew
On Apr 21, 2013 3:29 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:



 tamouse mailing lists tamouse.li...@gmail.com wrote:

 On Sat, Apr 20, 2013 at 1:51 PM, Angela Barone
 ang...@italian-getaways.com wrote:
  I've written a script that logs all visits to a web site,
 complete with referrer and IP address.  It also logs all 4xx errors.
 What I'd like to add to this is, if someone adds extra code after the
 page_name.php, to be able to capture any extra code and log that.
 
  I've tried:
 
  $_SERVER['QUERY_STRING']
  $_SERVER['REDIRECT_QUERY_STRING']
  $_SERVER['REDIRECT_URL']
 
 So, since I wasn't exactly sure what got put into $_SERVER, and since
 I'm lazy, I tapped out the following script:
 
 ?php
 header(Content-type: text/plain);
 echo '$_SERVER:'.PHP_EOL;
 var_dump($_SERVER);
 ?
 
 When I called it with the following URL:
 
 http://localhost/~tamara/teststuffout/logger.php/one/two?a=true#fragment
 
 It showed all the stuff in $_SERVER as a result of that, including:
 
  [REQUEST_URI]=
   string(47) /~tamara/teststuffout/logger.php/one/two?a=true
 
   [PATH_INFO]=
   string(8) /one/two
 
   [QUERY_STRING]=
   string(6) a=true
 
 Interestingly, it appears nothing reports #fragment...
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 It wont, the fragment is always local. You'd need javascript to handle that

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk

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




Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Andrew Ballard
On Mar 16, 2013 6:14 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 On Fri, 2013-03-15 at 22:32 -0400, Andrew Ballard wrote:

  Guess regex are the only useful solution here. When you consider to use
  built-in functions, just remember, that for example '0xAF' is an
integer
  too, but '42.00' isn't.

 Shoot...I hadn't considered how PHP might handle hex or octal strings
when
 casting to int. (Again, not in front of a computer where I can test it
 right now. )

 Regexes have problems with more than 9 digits for 32-bit ints. I guess to
 some degree it depends on how likely you are to experience values that
 large.

 Andrew


 Do they? Regex's deal with strings, so I don't see why they should have
such issues. I've certainly never come across that problem, or heard of it
before.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



Sure. If the string is nine or fewer digits, they can all be 0-9. If it is
10 digits, the first digit can only be 1-2. If it's 1, the remaining nine
digits can still be 0-9, but if the first digit is 2, the second digit can
only be 0-1. If the second digit is 0, the remaining eight digits can still
be 0-9, but if it is 1, the third digit can only be 0-4. If the third digit
is 0-3, the remaining seven digits can still be 0-9, but if it is 4, the
fourth digit can only be 0-7.

This pattern would continue for each of the remaining digits. Hopefully you
get the idea. When you get to the final digit, its range depends not only
on the nine preceding digits, but also the sign. If this is 64-bit, that
adds even more wrinkles (including being aware of whether your
implementation supports 64-bit ints). It may be possible to do with regular
expressions, but it would definitely be complex and probably a time sink.

As I said, if you KNOW you won't be dealing with integers that are more
than nine digits, the regex should work fine.

Remember, the OP didn't ask if it was an integer in the realm of infinite
pure integers; he asked how to tell if a string was a number that could be
converted to an int (presumably without loss).

Andrew


Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Andrew Ballard
On Sat, Mar 16, 2013 at 12:21 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:

 On Sat, 2013-03-16 at 11:46 -0400, Andrew Ballard wrote:

 On Mar 16, 2013 6:14 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:
 
  On Fri, 2013-03-15 at 22:32 -0400, Andrew Ballard wrote:
 
   Guess regex are the only useful solution here. When you consider to use
   built-in functions, just remember, that for example '0xAF' is an
 integer
   too, but '42.00' isn't.
 
  Shoot...I hadn't considered how PHP might handle hex or octal strings
 when
  casting to int. (Again, not in front of a computer where I can test it
  right now. )
 
  Regexes have problems with more than 9 digits for 32-bit ints. I guess to
  some degree it depends on how likely you are to experience values that
  large.
 
  Andrew
 
 
  Do they? Regex's deal with strings, so I don't see why they should have
 such issues. I've certainly never come across that problem, or heard of it
 before.
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 

 Sure. If the string is nine or fewer digits, they can all be 0-9. If it is
 10 digits, the first digit can only be 1-2. If it's 1, the remaining nine
 digits can still be 0-9, but if the first digit is 2, the second digit can
 only be 0-1. If the second digit is 0, the remaining eight digits can still
 be 0-9, but if it is 1, the third digit can only be 0-4. If the third digit
 is 0-3, the remaining seven digits can still be 0-9, but if it is 4, the
 fourth digit can only be 0-7.

 This pattern would continue for each of the remaining digits. Hopefully you
 get the idea. When you get to the final digit, its range depends not only
 on the nine preceding digits, but also the sign. If this is 64-bit, that
 adds even more wrinkles (including being aware of whether your
 implementation supports 64-bit ints). It may be possible to do with regular
 expressions, but it would definitely be complex and probably a time sink.

 As I said, if you KNOW you won't be dealing with integers that are more
 than nine digits, the regex should work fine.

 Remember, the OP didn't ask if it was an integer in the realm of infinite
 pure integers; he asked how to tell if a string was a number that could be
 converted to an int (presumably without loss).

 Andrew


 Ah, I see. I think that's not an issue as such with regular expressions
 having problems, more that bit limitations has a problem with numbers!

ANY computer system is going to have limitations with numbers -- you
can't store infinity in a finite system. LOL

 Bearing that in mind, this does the trick:

 $string1 = '9';
 $string2 = '99';
 $string3 = '99';

 var_dump($string === (intval($string1).''));
 var_dump($string === (intval($string2).''));
 var_dump($string === (intval($string3).''));

That's the same thing I posted, just different syntax. You are still
converting the string to an int, converting the int back to a string,
and comparing the resulting value to the original string using the
identical (===) operator. Depending on one's needs, it could be
tweaked a little to handle leading/trailing spaces, leading zeroes,
etc.

function is_int_hiding_as_string($value)
{

if (is_string($value)) {

// remove any spaces around the value.
$value = trim($value);

// check for a sign :-)
$sign = (substr($value, 0, 1) === '-') ? '-' : '';

// strip off the sign, any additional leading spaces or zeroes
$value = ltrim($value, ' 0-');

// I didn't strip off trailing zeroes after the decimal because
// I consider that a loss of precision, but you could do so
// if necessary.

return ($value === $sign . (int)$value);

}

return false;
}


 I'm getting the expected results on my machine (32-bit) but a 64-bit machine 
 would get the correct results for larger numbers.


As I understood the original post, these ARE the correct results on
ANY system. If the string value can be safely converted to an int *in
the environment under which the script is executing* without loss of
precision, this will return true; if it cannot, it returns false.


Sorry for getting carried away, but it is SO much easier to respond on
an actual keyboard than my phone. :-)

Andrew

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



Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Andrew Ballard
I suppose one could try something like this:

if (is_string($val)  $val === (string)(int)$val) 

If $val is an integer masquerading as a string, it should be identical to
the original string when cast back to a string, shouldn't it? (I can't try
it right now.)

Andrew


Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Andrew Ballard
On Mar 15, 2013 9:54 PM, Sebastian Krebs krebs@gmail.com wrote:

 2013/3/16 Andrew Ballard aball...@gmail.com

 I suppose one could try something like this:

 if (is_string($val)  $val === (string)(int)$val) 

 If $val is an integer masquerading as a string, it should be identical to
 the original string when cast back to a string, shouldn't it? (I can't
try
 it right now.)


 It is semantically equivalent to

 $val == (int) $val

 and as far as I remember (I didn't read everything completely) this were
mentioned. I didn't read, whether or not, it was accepted as solution ;)


Not quite. That method will massage both values to the same type for the
comparison. Whoever shot it down said they both go to int. If that's the
case,

if ($val == (int)$val)

is more like saying

if ((int)$val === (int)$val)

What I suggested converts the string to an int, the resulting int back to a
string, then does a type-specific comparison to the original string value.

Andrew


Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Andrew Ballard
 Guess regex are the only useful solution here. When you consider to use
 built-in functions, just remember, that for example '0xAF' is an integer
 too, but '42.00' isn't.

Shoot...I hadn't considered how PHP might handle hex or octal strings when
casting to int. (Again, not in front of a computer where I can test it
right now. )

Regexes have problems with more than 9 digits for 32-bit ints. I guess to
some degree it depends on how likely you are to experience values that
large.

Andrew


Re: [PHP] Re: Switch - Case Statement Questions

2012-11-19 Thread Andrew Ballard
On Sat, Nov 17, 2012 at 4:13 PM, Sebastian Krebs krebs@gmail.com wrote:
 2012/11/17 Andrew Ballard aball...@gmail.com

 On Nov 16, 2012 10:24 PM, tamouse mailing lists tamouse.li...@gmail.com
 wrote:
 
  On Fri, Nov 16, 2012 at 12:41 PM, Sebastian Krebs krebs@gmail.com
 wrote:
   Beside this it can be rewritten as
  
   switch ((int) (($count-1) / 7) {
 case 0: // 1-7
 case 1: // 8 - 14
 default: // above 15
   }
 
  Nice code refactoring :) Just a tad obscure for someone coming along
  later

 Not only obscure, but depending on the rule being processed could be plain
 wrong. It works for the values shown so far, but what if another test is
 added to the use case in the future that doesn't fit the clever solution?

 Like so often in our developers world many things breaks, when it comes to
 new requirements.

 Without knowing the intent of the code, it could be a headache to maintain.

 Interesting, that you see 5 lines of code and assume, that nobody will ever
 get the intent of this code ;) Of course the context is missing. I guess,
 that $count is something like remaining days, or such, because 7 and
 14 look like one week and two weeks, respectively. Thus I wouldn't
 name the variable $count [1], but $remainingDays and voila: Context is
 back and so is the intent :)

 Of course the above code has a quite limited use-case, but that was the
 requirement (for now, see KISS). If you need more, refactor/rewrite it.


That's precisely my point. If the solution you posted, complete with
your assumptions about the significance of the values 7 and 14,
matches the requirements then use it. If your assumptions were wrong,
and a future revision may potentially require special handling for
certain values like 3 or 8 that cannot be evaluated using your
equation, then the whole block may have to be refactored rather than
simply adding a couple lines for the case. In the spirit of keeping
it simple, I would prefer the code that requires less refactoring.

I'm not assuming that nobody will ever get the [coder's] intent of a
segment of code at all. It's not so much about what the code does, as
WHY it is doing it.

 [1] Even further: I was taught, that if I ever want to name a variable like
 count, status, type, ... I should stop and probably don't use this
 name. In most cases they are used wrong. This example here is quite good:
 $count what?

It depends. Generally I agree with you, but if it is a simple loop
counter in a small block of code where variable scope issues and
overall readability of the code is not diminished I'm fine with names
like $count or $n.

Andrew

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



Re: [PHP] Re: Switch - Case Statement Questions

2012-11-17 Thread Andrew Ballard
On Nov 16, 2012 10:24 PM, tamouse mailing lists tamouse.li...@gmail.com
wrote:

 On Fri, Nov 16, 2012 at 12:41 PM, Sebastian Krebs krebs@gmail.com
wrote:
  Beside this it can be rewritten as
 
  switch ((int) (($count-1) / 7) {
case 0: // 1-7
case 1: // 8 - 14
default: // above 15
  }

 Nice code refactoring :) Just a tad obscure for someone coming along
 later

Not only obscure, but depending on the rule being processed could be plain
wrong. It works for the values shown so far, but what if another test is
added to the use case in the future that doesn't fit the clever solution?
Without knowing the intent of the code, it could be a headache to maintain.

Just my 2 cents.

Andrew


Re: [PHP] Session data lost in Firefox

2012-10-26 Thread Andrew Ballard
On Fri, Oct 26, 2012 at 8:49 AM, John Boy serv...@greenholdings.co.ukwrote:

 Hi

 I have a wesite where PHP session data is passed page to page then shells
 out to Paypal for payment then back to my website for completion of
 transaction and update of mysql file. When using Firefox our session data
 and POST data from Paypal is lost. This has happend only recently and has
 worked happily in the past. Works in other browsers too. Anyone heard of
 same problems?

 mywebpage - session data-mywebpage2-session data-paypal page-POST data
 + session data-mywebpage3

 --
 Johniboy


Just a thought - does this depend on using third party cookies between your
site and PayPal? If so, do you have them disabled in Firefox?

Andrew


Re: [PHP] Session data lost in Firefox

2012-10-26 Thread Andrew Ballard
On Fri, Oct 26, 2012 at 12:12 PM, John Boy serv...@greenholdings.co.ukwrote:

 Looks like it was a corrupted Paypal cookie lurking about on my test
 machine. Clearing all Paypal cookies cured the problem.
 Hours can be spent looking for needles like this in a very complex haystack
 and it turns out to be the simplest solution that's not even related
 directly to the programming. Thanks, Andrew for the prompting!
 However if this happened on a punter's computer the same would happen - so
 is there a way of coding the removal of third party cookies to avoid this
 problem?


As far as I know, if you can set a cookie you can also clear it. I don't
like the approach, though. I have 3rd party cookies disabled on purpose.

Andrew


RE: [PHP] MS SQL server connection problem.

2012-09-05 Thread Andrew Ballard
On Sep 5, 2012 7:14 AM, Jeff Burcher j...@allredmetal.com wrote:

 Hi,

 I am relatively new as well. I tried both of those methods with no luck. I
 finally had success using odbc_connect(). See below:

 $conn = odbc_connect(Driver={SQL
 Server};Server=$server;Database=$database;, $user, $password);

 Thanks,

 Jeff Burcher - IT Dept

ODBC may work for you, but it has issues if you need to work with text
longer than 4k if I recall.

The SQLSRV library really is the way to go. Just make sure you have the
correct SQL client library installed and use the SQL for PHP driver that
matches your PHP installation. (Threaded, non-threaded, etc.)

Andrew


Re: [PHP] Help with MSSQL and Stored Procs

2012-08-29 Thread Andrew Ballard
On Wed, Aug 29, 2012 at 3:14 PM, Phillip Baker phil...@freewolf.net wrote:
 I am trying to access a MSSQL DB on another system.
 I am having trouble executed a stored proc and debugging the problem./

 I have included the code below.
 I can connect to the DB just fine.
 I also can run regular queries on the DB and get a result set.
 We can also run the stored proc manually with the data in $xmlstring and
 that runs fine.

 However the mssql_execute is failing.
 I am getting the Execute failed die message however I am not getting
 anything for mssql_get_last_message

 So I have no idea what is happening.
 And ideas for solutions or at least to get more debugging information would
 be awesome.

 I know SQLSRV is a more recent option however we do not have it installed
 on the server and will likely not get that to happen so I need to get this
 debugged.

 $link = mssql_connect($myServer, $myUser, $myPass)
 or die(Couldn't connect to SQL Server on $myServer);
 mssql_select_db($myDB, $link)
 or die(Couldn't select database $myDB);
 if(!$link){
 die('Error connecting to MSSQL database at '.$myServer);
 } else {
 $version = mssql_query('SELECT @@VERSION');
 $row = mssql_fetch_array($version);
 mssql_free_result($version);

 echo $row[0].'br /br /';
 }
 $storedproc = Sp_DialerValidLead;
 $param = ValidLeadText;

 $stmt = mssql_init('Sp_DialerValidLead', $link)
 or die(Unable to initialize);

 mssql_bind($stmt, @.$param, $xmlstring, SQLVARCHAR)
 or die(Unable to bind
 @ValidLeadText:$storedprocbr.mssql_get_last_message());

 $result = mssql_execute($stmt)
 or die (Execute failed. Message:.mssql_get_last_message());

 var_dump($result);


 Blessed Be

 Phillip

I had to go to an old server that we are phasing out to find something
that had php_mssql installed on it, but once I got everything set up
it everything worked fine for me. I tested it with everything correct
as well as with a variety of forced errors (procedure doesn't exist,
user does not have permission to execute, parameter name different
than passed by PHP, etc.) and they all displayed error messages using
the code you posted above.

The server is running PHP 5.2.12, and this one can only connect to our
SQL Server 2000 instance, so I can't test it against SQL 2008.

Andrew

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



Re: [PHP] MSSQL Stored Proc

2012-08-28 Thread Andrew Ballard
On Tue, Aug 28, 2012 at 1:03 PM, Phillip Baker phil...@freewolf.net wrote:
 Greetings all,

 I am having some trouble with running a stored proc on an MSSQL DB.
 I am new to using MSSQL.



 $link = mssql_connect($server, $db, $password);



 if(!$link){

 die('Error connecting to MSSQL database at '.$server);

 } else {
 $storedproc = SP_DialerValidLead;

 $param = ValidLeadText;



 $stmt = mssql_init($storedproc, $link)

 or die(Unable to initialize);



 mssql_bind($stmt, @.$param, $xmlstring, SQLTEXT, FALSE)

 or die(Unable to bind
 $param:$storedprocbr.mssql_get_last_message());



 $result = mssql_execute($stmt);



 var_dump($result);
 mssql_close($link);

 }


 Apparently there is no data getting passed to the stored proc.

 The $xmlstring is a valid xml string and the variable is properly set in
 the code above.

 Is there something obvious in how I am trying to call the stored proc with
 the PHP code?
 Any ideas or further questions?


I just skimmed your code, but the only thing that sticks out is your
call to mssql_connect(). The second parameter should be the username,
not the database. To select a specific database, you use
mssql_select_db() after mssql_connect() returns a valid resource.

However, if you have the choice, you really should switch to the SQL
Server driver for PHP developed by Microsoft. The mssql library has
been phased out.

Andrew

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



Re: [PHP] Cost of redirect and site domain switch? Good Practice/ Bad Practice / Terrible Practice

2012-08-19 Thread Andrew Ballard
On Mon, Aug 20, 2012 at 12:19 AM, Jim Lucas li...@cmsws.com wrote:
 On 8/17/2012 6:35 PM, Jim Giner wrote:

 On 8/17/2012 7:16 PM, Jim Lucas wrote:


 You could simply remove all full domain+path URL links and replace
 them with absolute path urls only.

 turn http://www.somedomain.com/path/to/my/webpage.html

 into /path/to/my/webpage.html

 This would work with either domain.

 Those would be relative paths, ..o?


 No.

 Quick Google search turns up this:

 http://www.uvsc.edu/disted/decourses/dgm/2120/IN/steinja/lessons/06/06_04.html

 I have three description or types of paths that I use normally.

 I feel the first two generally get grouped together by most persons.

 Full or complete path:
 a href=http://www.cmsws.com/index.php;Home/a

 Absolute Path:
 a href=/index.phpHome/a

 Relative:
 a href=index.phpHome/a

 --
 Jim Lucas
 http://cmsws.com

Actually, from what I've seen most people consider your first example
an absolute path and your last example relative. The middle example,
which you have called absolute, seems to be oft ignored in the
explanations I found in my own quick Google search. Even the example
you cited seems to ignore the variant that you call an absolute path.
A page I found on About.com
(http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm)
does group the first two examples together as absolute paths, but the
definition of a URI on Wikipedia
(http://en.wikipedia.org/wiki/Uniform_resource_identifier) disagrees
-- under the section titled Examples of URI references, note this
example:

/relative/URI/with/absolute/path/to/resource.txt

The most authoritative resource I found was from the IETF (RFC 3986).
Section 4.3, as I understand it, says that an absolute URI includes
the scheme part (e.g. http, ftp, tel, mailto), which would imply that
your middle example is NOT an absolute path.

http://tools.ietf.org/html/rfc3986#section-4.3

Andrew

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



Re: [PHP] Two ways to obtain an object property

2012-08-15 Thread Andrew Ballard
On Wed, Aug 15, 2012 at 11:33 AM, Paul M Foster pa...@quillandmouse.com wrote:
 On Wed, Aug 15, 2012 at 09:28:28AM +0100, phplist wrote:

 This relates to a minor dilemma I come across from time and time,
 and I'm looking for advice on pros and cons and best practice. Last
 night I encountered it again.

 Within a site I have a User object, and within page code would like to have
 if ($crntUser-isASubscriber) {...}

 There seems to be two ways to handle this:

 I can have a User object method getSubscriberStatus() which sets
 $this-isASubscriber. But to use this I would have to run the method
 just before the if statement.

 Or I could have a method isASubscriber() which returns the result,
 meaning the if statement should be
 if ($crntUser-isASubscriber()) {...}

 While this is last night's specific example, I seem to face the
 method-setting-variable or the method-returning-result-directly
 decision quite often.

 Is either of these approaches preferable, or does it simply not matter?

 If I read you correctly, the latter would be preferable, primarily
 because it involves one less step. But if you're going to have to make
 that decision in an if statement repeatedly, I'd probably say:

 $isSubscribed = $crntUser-isASubscriber();

 just because in subsequent code, you're not suffering the (admittedly
 small) repeated overhead of the function call.

 But in answer to your question, isASubscriber() would be a pretty
 standard getter method to expose internal object properties.

 Paul

I generally use this getter method as well. If it bothers the OP
that isASubscriber() is a method rather than a property, one could
use the magic __get method:

?php

class User
{
private $isASubscriber = false;

public function __get($property)
{
if ('isASubscriber' === $property) {
return $this-isASubscriber;
}
}
}

?

In the end, it is still a function call either way though. The
advantage I see to both of these method-based approaches versus
exposing the property as public is that these methods prevent code
outside your class from doing something stupid:

?php

$u = new User();

$u-isASubscriber = 'rutabaga';

// Fatal error: Cannot access private property User::$isASubscriber
?

(Yes, I have seen proof that it is TECHNICALLY possible to get around
this in PHP, for example with unserialize.)

Andrew

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



Re: [PHP] PHP session variables

2012-08-15 Thread Andrew Ballard
On Fri, Aug 10, 2012 at 11:56 AM, Tedd Sperling t...@sperling.com wrote:
 On Aug 10, 2012, at 11:45 AM, Tedd Sperling t...@sperling.com wrote:

 On Aug 9, 2012, at 5:16 PM, Jim Lucas li...@cmsws.com wrote:
 You are relying on PHP's loose typing.  This is a poor check.

 session_id() returns a string, not boolean.

 You should do this instead.

 if ( session_id() === '' )
 


 --
 Jim Lucas

 Thanks Jim -- you're right.

 What about?

 if (!defined(SID))
   {
   session_start();
   }

 Before you answer, the (!defined(SID)) is over 50 times slower than ( 
 session_id() === '' )

 Your way is better.

 Cheers,

 tedd

tedd,

I think this is because you passed SID to defined() as a constant
rather than a string, so the if test always returns true. When I
changed this to

if (!defined('SID'))
{
session _start();
}

it worked as expected, and I got much more similar results. I also
added a call to session_destroy() between the two tests so that each
loop initialized the session once. (In your test, the second loop
never initializes the session since it was already started by the
first loop.)

This is your code with my modifications:

?php

  $starttime = microtime(true);


  // whatever you want timed, you do here.



  for($i=1; $i  1000; $i++)
{
if (!defined('SID'))
  {
  echo __LINE__, '::session_start()br';
  session_start();
  }
}

  session_destroy();

  $endtime = microtime(true);
  $totaltime = $endtime - $starttime;
  $totaltime = round($totaltime,5);
  echo pFirst in $totaltime seconds./p;

  $starttime = microtime(true);


  // whatever you want timed, you do here.

  for($i=1; $i  1000; $i++)
{
if (session_id() ==='')
  {
  echo __LINE__, '::session_start()br';
  session_start();
  }
}

  $endtime = microtime(true);
  $totaltime = $endtime - $starttime;
  $totaltime = round($totaltime,5);
  echo pSecond in $totaltime seconds./p;

  session_destroy();

?

Andrew

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



Re: [PHP] PHP session variables

2012-08-15 Thread Andrew Ballard
On Wed, Aug 15, 2012 at 3:24 PM, Tedd Sperling t...@sperling.com wrote:
 Your points are well taken -- thanks.

I've seen a lot of people code that way, so it's easy to miss. In your
original code, that first statement was calling session_start() 1,000
times. This is because the first time through, SID is undefined so
defined(SID) was equivalent to defined('SID') and both would have
returned false. After the first session_start(), though, SID WAS
defined, but would have had some pseudo-random session identifier as
its value. As a result, the last 999 times through your loop, you were
actually scanning the defined constants to see if there was one named
something like '7cjubadsh5lkq80opemht2ea03'. Obviously, it would never
exist.

 However, my only concern is given this:

  for($i=1; $i  1000; $i++)
{
if (!defined('SID'))
  {
  echo __LINE__, '::session_start()br';
  session_start();
  }
}

 The php manual ( http://us3.php.net/manual/en/function.session-start.php )

 First Note states that session_start() must be called *before* anything sent 
 to the Browser.

 So, to rewrite your code --

  for($i=1; $i  1000; $i++)
{
if (!defined('SID'))
  {
  session_start();
  echo __LINE__, '::session_start()br';
  }
}

 -- should work better, right?

 Cheers,

 tedd


Yes, that is more correct. I think we have output buffering enabled on
most of our servers (a lot of our legacy stuff really depends on it)
so I didn't notice any errors, but you are correct. You really don't
need the echo lines that I added in your test at all though. I just
threw it in there to be able to see when the function was being
called. However, due to the nature of your test page you are still
sending output from the first loop before you call session_start() in
the second loop. To be absolutely correct, you'd have to remove those
echo statements I added for debugging, store all of your timings in
separate variables and then output them at the end of the script.

Andrew

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



Re: [PHP] Creating drop-down menus

2012-07-17 Thread Andrew Ballard
On Tue, Jul 17, 2012 at 4:58 PM, Paul M Foster pa...@quillandmouse.com wrote:
 On Wed, Jul 18, 2012 at 08:45:34AM +1200, James Newman wrote:

 Just to put my 2cents in, you might want to try jQuery if you're going to
 go down the AJAX road.

 JQuery is a LOT of code to include if you're just going to do an AJAX
 call or two. There are examples of doing straight AJAX with Javascript
 on the 'Net. Once you work through them, you find that there's a
 static part that you can include in all the files you want to make
 AJAX calls. And then there's the part that deals directly with the data
 you get back from whatever PHP or other script is feeding you data from
 outside the website. That's the part that needs custom work. I *hate*
 Javascript, but I managed to figure it out.

 Another point: I'm not sure if it's the same for other people. I'm on a
 crappy little computer running Linux. I've got a little CPU meter in my
 taskbar. And nothing jacks that meter up like Javascript. I don't know
 why, but Javascript just devours CPU on my computer. The more
 javascript, the worse. And like I said, JQuery is a LOT of code. This is
 one of the reasons I tend to code things in PHP instead of Javascript.

 Paul


I found some time ago that a lot of those simple little AJAX examples
actually cause Javascript memory leaks. You can search the web to
learn how to handle the resources correctly yourself, but the
libraries like jQuery and YUI that are available do it for you and
seem to eliminate most of the leaks that I've seen. YMMV.

Andrew

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



Re: [PHP] Unexpected Notice message

2012-07-05 Thread Andrew Ballard
On Thu, Jul 5, 2012 at 3:10 AM, Arno Kuhl a...@dotcontent.net wrote:
 -Original Message-
 From: Tim Streater [mailto:t...@clothears.org.uk]
 Sent: 04 July 2012 06:56 PM
 To: Marc Guay; php-general@lists.php.net
 Subject: Re: [PHP] Unexpected Notice message

 On 04 Jul 2012 at 16:51, Marc Guay marc.g...@gmail.com wrote:

 Notice: Use of undefined constant QUERY_STRING - assumed 'QUERY_STRING' in

 I would guess that it's asking you to add quotes around QUERY_STRING...?

 As in:
 if (strlen($_SERVER['QUERY_STRING'])  0) {


 Cheers  --  Tim
 

 Excellent, a bit surprised but that was it, thanks a lot.

 Cheers
 Arno

Why does this surprise you? $_SERVER is an array with string indices,
one of which happens to be the string 'QUERY_STRING'. However, your
code is trying to reference a constant named QUERY_STRING that does
not exist. The code will work because PHP will assume you meant to use
a string instead of a constant, but this will also generate a notice
to let you know that the code should be fixed.

Andrew

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



Re: [PHP] Simple XML, (x)html, and xpath

2012-05-25 Thread Andrew Ballard
On Fri, May 25, 2012 at 3:57 AM, Gary listgj-phpgene...@yahoo.co.uk wrote:
 If I use simplexml_load_string to create an XML object with the
 following XHTML
 ,
 | ?xml version=1.0?
 | !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
 | http://www.w3.org/TR/
 | xhtml1/DTD/xhtml1-strict.dtd
 | html xmlns=http://www.w3.org/1999/xhtml;
 | headmeta http-equiv=Content-Type content=text/html; charset=UTF-8
 | /
 | titletest title/title
 | /head
 | body
 | !-- comment --
 | /body
 | /html
 `

 I get this SimpleXMLElement back
 ,
 | object(SimpleXMLElement)#1 (2) {
 |   [head]=
 |   object(SimpleXMLElement)#2 (1) {
 |     [title]=
 |     string(10) test title
 |   }
 |   [body]=
 |   object(SimpleXMLElement)#3 (1) {
 |     [comment]=
 |     object(SimpleXMLElement)#4 (0) {
 |     }
 |   }
 | }
 `

 but I cannot seem to get anything out of an xpath expression, no matter
 what I try.

 If, however, I remove the 'xmlns=http://www.w3.org/1999/xhtml;' in the
 html element, it works fine. So yeah, I can just remove that text,
 but... is there something wrong here, in my expectation or in the xpath
 function?

 TIA.

 --
 Gary        Please do NOT send me 'courtesy' replies off-list.

Gary,

I am not sure what you have tried, but namespaces change everything in
XPath compared to documents without them. This isn't exact, but XPath
without namespaces is often simple such as:

/html/head/title

Once you add a namespace, though, the XPath becomes something like

/*[namespace-uri()='http://www.w3.org/1999/xhtml' and
local-name()='html']/*[namespace-uri()='http://www.w3.org/1999/xhtml'
and local-name()='head']/*[namespace-uri()='http://www.w3.org/1999/xhtml'
and local-name()='title']


(I'm not sure of the exact syntax since I don't have something open
right now that I can test it in.

However, I think SimpleXML has some features that make this easier.
Take a look at this:

http://www.php.net/manual/en/simplexmlelement.registerxpathnamespace.php

Andrew

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



Re: [PHP] Sunset/Sunrise

2012-03-20 Thread Andrew Ballard
On Tue, Mar 20, 2012 at 9:23 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 Hi gang:

 What's wrong with this?

 echo date(D M d Y). ', sunrise time : ' .date_sunrise(time(), 
 SUNFUNCS_RET_STRING, 42.57, 84.3320, 90, -5);
 echo('br');
 echo date(D M d Y). ', sunset time : ' .date_sunset(time(), 
 SUNFUNCS_RET_STRING, 42.57, 84.3320, 90, -5);

 It gives exactly the wrong time -- Sunset is reported as Sunrise and vice 
 versa. What's up?

 Thanks,

 tedd

tedd,

I think you used the incorrect longitude. Did you want a location in
northern China (as you entered above) or near Dansville, MI (in which
case I believe your longitude above should be negative rather than
positive)?

http://maps.google.com/maps?q=42.57,84.3320hl=ensll=42.57,-84.332sspn=0.023008,0.038581t=mz=8

http://maps.google.com/maps?q=42.57,-84.3320hl=ensll=42.554092,-84.324188sspn=0.736459,1.234589t=mz=15

Andrew

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



Re: [PHP] Sunset/Sunrise

2012-03-20 Thread Andrew Ballard
On Tue, Mar 20, 2012 at 6:00 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 That's what I get for not checking it myself. I was assured by one of my 
 students that was our correct lat/long. Boy, will he hear from me -- he's 
 going to find his next assignment in China. :-)

 Thanks,

 tedd

That's the spirit! Truly world-class education!

Andrew

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



Re: [PHP] fgetcsv doesn't return an array?

2012-03-15 Thread Andrew Ballard
On Thu, Mar 15, 2012 at 1:29 PM, Jay Blanchard
jay.blanch...@sigmaphinothing.org wrote:
 On 3/15/2012 12:23 PM, Matijn Woudt wrote:

 On Thu, Mar 15, 2012 at 6:09 PM, Jay Blanchard
 jay.blanch...@sigmaphinothing.org  wrote:

 I thought that fgetcsv returned an array. I can work with it like an
 array
 but I get the following warning when using it

 |Warning:  implode(): Invalid arguments passed on line 155

 154     $csvCurrentLine = fgetcsv($csvFile, 4096, ',');
 155     $currentLine = implode(,, $csvCurrentLine);
 |

 Everything that I have read online indicates that it is because
 $csvCurrentLine is not declared as an array. Adding a line to the code

 153 |$csvCurrentLine = array();

 Does not get rid of the warning. The warning isn't interfering with the
 script working, but it us annoying. Does anyone know the solution?

 Thanks!

 Jay
 |

 Are you using this in a loop or something? fgetcsv returns FALSE on
 errors, including End Of File.

 [/snip]

 I am using it in a loop. End Of File is an error?

Yes.  fgetcsv() returns NULL if an invalid handle is supplied or
FALSE on other errors, including end of file.

I usually use it in a while loop like this:

?php

while ($row = fgetcsv($csvFilePointer)) {
// ... process the row
}

?

Andrew

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



Fwd: [PHP] Function mktime() documentation question

2012-03-09 Thread Andrew Ballard
And again to the list, since for some reason Reply-to-all did not do
as intended this time.


-- Forwarded message --
From: Andrew Ballard aball...@gmail.com
Date: Fri, Mar 9, 2012 at 12:53 PM
Subject: Re: [PHP] Function mktime() documentation question
To: Tedd Sperling tedd.sperl...@gmail.com


On Fri, Mar 9, 2012 at 12:07 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:

[snip]

 I am just looking for one that is easy to explain to students.

 Cheers,

 tedd

tedd,

Since you are teaching this to students, I would recommend sticking
with the internal date functions and avoiding any solution that
includes adding or subtracting multiples of the magic number 86400.*
Many such solutions fail to take into consideration Daylight Saving
Time and are therefore guaranteed to be wrong at least twice a year
(if not several months out of the year). Sure, you can write your code
to handle the differences correctly, but since the rules governing the
time shift are mostly arbitrary and differ across time zones the world
over, it seems safer to me to rely on the internal functions when
working with dates.


Andrew


* Even if the internal functions base their calculations on the number
of seconds per day, they have at least already handled all the varied
time zones and DST rules and been tested in environments all over the
world. When those rules change, the internal functions will be
adjusted to reflect the changes and should be much more reliable than
thousands of instances of multiple strategies that get copied and
pasted into projects.

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



RE: [PHP] debugging PHP memory corruption

2012-01-05 Thread Andrew Morum
Hi Andy,
Have you tried running it with valgrind? (See [1] for tips).
Otherwise, you might have more luck at php-internals mailing list,
since it is related to PHP development if you intend to fix either PHP
or the plugin.

Matijn
[1] https://bugs.php.net/bugs-getting-valgrind-log.php

Thanks Matijn,

We have tried running Valgrind against it, but there is nothing obvious
(to us at least) in the output.

I'll try the Internals mailing list.

Andy


The information contained in this email is intended for the personal and 
confidential use
of the addressee only. It may also be privileged information. If you are not 
the intended
recipient then you are hereby notified that you have received this document in 
error and
that any review, distribution or copying of this document is strictly 
prohibited. If you have
received  this communication in error, please notify Brendata immediately on:

+44 (0)1268 466100, or email 'techni...@brendata.co.uk'

Brendata (UK) Ltd
Nevendon Hall, Nevendon Road, Basildon, Essex. SS13 1BX  UK
Registered Office as above. Registered in England No. 2764339

See our current vacancies at www.brendata.co.uk

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



[PHP] debugging PHP memory corruption

2012-01-04 Thread Andrew Morum
We've got a problem with PHP 5.3.8 and a third party (open source)
library (WSo2 SOAP).



At some point during the request to the PHP script, some structures seem
to be getting corrupted causing PHP to crash.



Depending on the code in the PHP script, it's either crashing during in
a print_r/var_export or crashing when the PHP shuts down (the exact
location of the crash moves around when we alter the code).



We can reprod this on Win32 and Linux now. But how can we go about
debugging where the corruption occurred? The address of the corrupted
data is not known until the segfault/access violation occurs so we can't
set a watch on it (as far as we can tell).



Here's what we see in the debugger on Win32:



Unhandled exception at 0x1008eb45 (php5ts.dll) in php-cgi.exe:

Access violation reading location 0x4cac5400



php5ts.dll!_zval_ptr_dtor(_zval_struct * * zval_ptr=0x4cab5400)  + 0x5
bytes

php5ts.dll!zend_hash_destroy(_hashtable * ht=0x034cc0f0)  + 0x27 bytes


php5ts.dll!zend_objects_free_object_storage(_zend_object *
object=0x03489fa0, void * * * tsrm_ls=0x003f42b0)  + 0x2b bytes

php5ts.dll!zend_objects_store_free_object_storage(_zend_objects_store *
objects=0x003f685c, void * * * tsrm_ls=0x003f42b0)  + 0x9c bytes   

php5ts.dll!shutdown_executor(void * * * tsrm_ls=0x003f42b0)  + 0x2fe
bytes

php5ts.dll!zend_deactivate(void * * * tsrm_ls=0x003f42b0)  + 0x91 bytes

php5ts.dll!php_request_shutdown(void * dummy=0x)  + 0x31f bytes


php-cgi.exe!main(int argc=1, char * * argv=0x003f31d0)  + 0xe89 bytes

php-cgi.exe!__tmainCRTStartup()  + 0x10f bytes



Any tips welcomed.



Andy.



The information contained in this email is intended for the personal and 
confidential use
of the addressee only. It may also be privileged information. If you are not 
the intended
recipient then you are hereby notified that you have received this document in 
error and
that any review, distribution or copying of this document is strictly 
prohibited. If you have
received  this communication in error, please notify Brendata immediately on:

+44 (0)1268 466100, or email 'techni...@brendata.co.uk'

Brendata (UK) Ltd
Nevendon Hall, Nevendon Road, Basildon, Essex. SS13 1BX  UK
Registered Office as above. Registered in England No. 2764339

See our current vacancies at www.brendata.co.uk

[PHP] Namespaced code with SabreDAV

2011-10-06 Thread Andrew Mason
Hello all,
I am trying to use the wonderful SabreDAV library to create a webdav
share. I have a demo up and running however the framework / class i'm
using is namespaced, and SabreDAV unfortunately does not have a 5.3
style namespace declaration.

I have an spl_autoload function registered in my base controller and
so long as I prefix the classname with a \ it all works:


 $rootDirectory = new \Sabre_DAV_FS_Directory($rootDir);

// The server object is responsible for making sense out of the WebDAV protocol
$server = new \Sabre_DAV_Server($rootDirectory);


However, SabreDAV it's self has a large amount of other PHP classes
which it calls which obviously aren't prefixed with '\'

Is there a way i can tell PHP any class name that get's instanciated
with 'Sabre_' should resolve to '\Sabre' ?

Many thanks
Andrew

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



Re: [PHP] innerHTML triple quotes issue

2011-09-15 Thread Andrew Ballard
On Thu, Sep 15, 2011 at 5:01 AM, Grega Leskovšek legr...@gmail.com wrote:

 h3My Heavenly profession is being span class=see
 onmouseover='?php echo this.innerHTML=' img
 src=\http://imagecache2.allposters.com/images/PF_New/102008/3070943.jpg\;
 alt =\close to my heavenly face\ /';?'
 onmouseout=this.innerHTML='an angel'an angel/span,


 I first tried this but got a mistake and then I tried to use php to
 settle this look above, but got parsing mistake.


It's easy to forget that, although you are embedding JavaScript in the
onmouseover and onmouseout attributes of the element, the content of
those attributes is still technically HTML, so the single and double
quotes as well as the tag angle brackets inside the attribute should
probably be the HTML entities (quot; apos; lt; and gt;) instead of
the literal characters. This avoids the issue with nesting and
escaping quotes across three languages (PHP - HTML - Javascript).


Of course, when testing this, my first attempt worked in Firefox,
Opera, Safari and Chrome but failed in IE (version 8). (Go figure)

span class=see
onmouseover=this.innerHTML=apos;lt;brgt;lt;img
src=quot;http://imagecache2.allposters.com/images/PF_New/102008/3070943.jpgquot;
/apos;
onmouseout=this.innerHTML=apos;an angelapos;

an angel/span



So then I tried a mixed approach and it seems to work in all of them:

span class=see
onmouseover=this.innerHTML='lt;brgt;lt;img
src=quot;http://imagecache2.allposters.com/images/PF_New/102008/3070943.jpgquot;
/'
onmouseout=this.innerHTML='an angel'

an angel/span


YMMV

Andrew

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



Re: [PHP] Secure vs httpOnly cookie flag: is one better?

2011-08-16 Thread Andrew Ballard
On Tue, Aug 16, 2011 at 1:01 PM, Jen Rasmussen j...@cetaceasound.com wrote:
 Thank you in advance for your input on my question here .



 I am currently running PHP 5.1.6 and would prefer to set both the secure and
 httpOnly flags for a session cookie,

 however, httpOnly is not added until PHP 5.2. I have found an elegant way to
 set it ( courtesy of : http://www.youtube.com/watch?v=UW0UhYfs1es ) but I am
 unable to set both the secure and the httpOnly flags. I realize the post is
 quite old, but doh!, so is my version of PHP J



 My guess is that if forced to choose, I should opt for secure but would
 prefer to do so with any opinions you may offer in mind.

I don't see the relevance of the address you cited above, but if you
are referring to the workaround that I showed you last week --

http://marc.info/?l=php-generalm=131281548332245w=2

-- you can easily extend the technique to set both flags.


header('Set-Cookie: cookie_name=value; secure; HttpOnly');


Andrew

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



Re: Fwd: [PHP] Keeping session info in $_SESSION or in database?

2011-08-15 Thread Andrew Ballard
On Mon, Aug 15, 2011 at 4:33 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:


 On Mon, 2011-08-15 at 14:12 -0500, Philip Thompson wrote:
 Crap! I wish this list would have a reply-to list automatically

 It does, just hit the reply to all or reply to list button on your email
 client. I know Gmail has both these options, and the client I use
 (Evolution) does and is available for a variety of different platforms.


I don't see a Reply-to-List in Gmail, and haven't seen it any any of
the other mail clients I have used either. Reply-All is a pretty
standard option, though.

Andrew

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



Re: [PHP] Problem with inserting numbers...

2011-08-11 Thread Andrew Ballard
On Wed, Aug 10, 2011 at 9:22 PM, Jason Pruim pru...@gmail.com wrote:
 So here I am attempting to generate some numbers to be inserted into a 
 database... eventually they will make up a phone number (Which I've emailed 
 about before and know about the bad ideas with it.. But it's the customer :))

 Here is the code I am working with:

 ?PHP
 function number_pad($number,$n) {
 return str_pad((int) $number,$n,0,STR_PAD_LEFT);
 }

 $SQL = SELECT * FROM Test WHERE `areacode` = '907' AND `prefix` = '200' 
 LIMIT 5;

 $result = mysql_query($SQL);
 //$num = ;
 //foreach ($result as $key = $value) {
 //    echo $key . - . $value . - . number_pad($num, 4) . BR;
 //    $num++;
 //}

 while ($num != 1) {
    while($row = mysql_fetch_assoc($result)) {
        $padnum = number_pad($num, 4);
        echo $row['areacode'] . - . $row['prefix'] . - . $padnum . BR;
        $num++;
    }


 }

 ?

 basically all I'm trying to do is generate the last 4 digits starting at  
 and going up to . for testing purposes I'm just echoing back but will 
 eventually insert the complete number back into the database as a 7 digit 
 string.

 The error I'm getting is:

 Fatal error: Maximum execution time of 30 seconds exceeded in 
 /home/pruimpho/public_html/jason/dev/clients/flewid/Phone/config/phoneareacodes.php
  on line25

 which is where the second while starts...

 Does anyone know a better way to do this?

 I'm off to finish searching google while waiting for some good news :)

 Thanks Everyone!


 Jason Pruim
 pru...@gmail.com

You could always push it off to MySQL. I don't have a MySQL instance
available to test right now, but I ran this on SQL Server and it
should be generic enough to port without much change. Basically, you
just load a table with a single tinyint column with the digits between
0 and 9, and then allow the database to cross join that table 4 times
to get 1 resulting rows numbered  through .
The cross join on this database server executes in around 44ms.


-- Create a temporary table containing the digits 0 through 9
CREATE TABLE Digits (
n   tinyint NOT NULL PRIMARY KEY
CHECK (n BETWEEN 0 AND 9)
)

INSERT INTO Digits
VALUES
(0),
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8),
(9)



-- Cross join the digits table 4 times to load into a table called numbers.

SELECT  CONVERT(char(1), Thousands.n) +
CONVERT(char(1), Hundreds.n) +
CONVERT(char(1), Tens.n) +
CONVERT(char(1), Ones.n) AS Number
INTONumbers
FROMDigits AS Thousands,
Digits AS Hundreds,
Digits AS Tens,
Digits AS Ones
ORDER BY
Thousands.n, Hundreds.n, Tens.n, Ones.n


SELECT  *
FROMNumbers

-- Drop the temporary digits table
DROP TABLE Digits



Andrew

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



Re: [PHP] Struggling with MySQL query

2011-08-09 Thread Andrew Ballard
On Tue, Aug 9, 2011 at 10:14 AM, David Green simp...@gmail.com wrote:
[snip]
 $data = mysql_query(SELECT * FROM news_items WHERE upper('headline') LIKE
 '%$find%');

A couple things to consider.

First, as a few others have pointed out, you probably want to remove
the single quotes around the word headline in your query. The quotes
cause the query to compare the wildcard string '%{$find}%' to the
literal string 'headline' instead of the contents of a column named
headline. That would cause your query to return either no results for
ordinary search terms, or else return the entire table if the value of
$find is the word 'headline' or any sequence of characters within that
word.

You also probably don't need upper(...) function at all. Unless you
used a case-sensitive collation for that column/table (or are storing
it as binary data rather than text) the condition

'My Article Title' LIKE '%article%'

would return a match even though the case is different.

Andrew

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



Re: [PHP] PHP Security: Best Practices

2011-08-08 Thread Andrew Ballard
On Mon, Aug 8, 2011 at 10:08 AM, Jen Rasmussen j...@cetaceasound.com wrote:
[snip]

 On a side note, PHP versions prior to 5.3+ do not allow to set the httponly
 flag as a cookie parameter, is there any acceptable alternative for this?


I believe that has been supported since 5.2.0. As for a workaround for
versions before that, I found this pretty quickly through Google:

http://stackoverflow.com/questions/36877/how-do-you-set-up-use-httponly-cookies-in-php

Andrew

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



Re: [PHP] Complex (or not so) array data form submission?

2011-08-04 Thread Andrew Ballard
On Thu, Aug 4, 2011 at 1:18 PM, Jamie Krasnoo jkras...@gmail.com wrote:

 Hey all,

 I get the basics of submitting a form and organizing the $_POST data within
 arrays (name[], name[key], etc). But if I wanted to submit something like
 multiple addresses and have it end up organized in array form like this from
 submission is this possible?

 $addresses = array(
    0 = array(
        'id'             = '1',
        'address1' = '...',
        'address2' = '...',
        'city'          = '...',
        'state'        = '...',
        'zip'           = '...'
    ),
    1 = array(
        'id'             = '2',
        'address1' = '...',
        'address2' = '...',
        'city'          = '...',
        'state'        = '...',
        'zip'           = '...'
    )
 );

 For some reason I can't seem to come up with the right naming schema in
 forms in order to get this structure.

 Jamie

It should be pretty straight foward. Your fields would have name such as these:

name=addresses[0][id]
name=addresses[0][address1]
name=addresses[0][address2]
name=addresses[0][city]
name=addresses[0][state]
name=addresses[0][zip]

And so on.

Andrew

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



Re: [PHP] Complex (or not so) array data form submission?

2011-08-04 Thread Andrew Ballard
On Thu, Aug 4, 2011 at 2:04 PM, Jamie Krasnoo jkras...@gmail.com wrote:
 Thanks. I think what I got hung up on was that I was trying this:

 name=addresses[][id]
 name=addresses[][address1]
 name=addresses[][address2]
 name=addresses[][city]
 name=addresses[][state]
 name=addresses[][zip]

 Which wouldn't have given the end result I sought, I don't think. Clear case
 of not seeing the forest for the trees.

 Jamie

It probably would have worked just fine. Not specifying the numeric
index means that PHP will depend on the order that the browser sends
the values, but they are generally sent in the order they appear on
the form. If the numeric index is important, it's better to provide it
explicitly.

Andrew

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



Re: [PHP] How to install pecl_http into a web hosting service

2011-07-25 Thread Andrew Ballard
On Mon, Jul 25, 2011 at 12:26 PM, Jamie Krasnoo jkras...@gmail.com wrote:
[reordered and snipped]

 On Thu, Jul 21, 2011 at 8:52 PM, gato chalar dany...@gmail.com wrote:
 Hi list,

 I need to perform http requests (GET,POST) , I have readed about pecl_http
 package, so it seem to be what I need. Reading further I sow some ways to
 install this package to a server where you have all rights and privilegies,
 and that's the problem; I don't know if I will be able to install pecl_http
 in a php hosting service. Currently I have a free php hosting account. Is
 that posible?

 You should be using cURL for making requests.

If the pecl HTTP extension is unavailable, cURL is the next simplest
choice, but I've used HTTP when it was available and it worked just
fine. I'm curious as to your reason (other than general availability)
for stating that one *should* use cURL (as opposed to something else
like HTTP).

Andrew

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



Re: [PHP] static variables inside static methods

2011-07-06 Thread Andrew Williams
I think you are confusing  scope visibility  level of the variable within
method and the class.

Variable within the method is going to 1 because it was declare within the
test method and there no link to the one declared outside the test method.
The second case is referencing the varible of the class.



2011/7/6 Дмитрий Степанов dmit...@stepanov.lv

 Hello, everybody.

 While working with static variables inside static class' methods, I have
 found this very interesting (at least for me) behavior of PHP.

 Consider the following class definitions (example #1):

 class X {
 public final static function test() {
 static $i;
 return ++$i;
 }
 }

 class Y extends X {
 }

 By executing this code:

 echo X::test();
 echo Y::test(); // note Y class here

 one would expect to see 12 as output, but apparently I get 11.

 That's a bit confusing if you logically assume that static vars are tied
 to the scope they're defined in. Since this static variable is
 defined in a specific static method test(), that is NOT overloaded by class
 Y, in my opinion it shoul've preserved it's value across static calls.

 Let's look at another example (example #2):

 class X {
 public static $x =0;
 public final static function test() {
 return ++static::$x; // note static keyword here
 }
 }

 class Y extends X {
 }

 If you run this code:

 echo X::test();
 echo Y::test();

 you get 12 as output - the expected output. Notice that the
 ++static::$x
 expr. is taking advantage of late static binding. Now, if you change
 body of test() to the following code:

 public final static function test() {
 return ++self::$x;
 }

 then you also get 12 as output.

 Is this a bug that static context of $i is not preserved in example #1 or
 do
 I misunderstand something?

 I could not find any hints on this in the PHP documentation.

 Dmitry.



Re: [PHP] Re: Date validation

2011-05-23 Thread Andrew Ballard
On Mon, May 23, 2011 at 9:55 AM, Tamara Temple tamouse.li...@gmail.com wrote:
 Isn't this typically why date selectors are used on the front end?


Not really. Date selectors are intended to make data entry easier on
the front end while allowing only valid date selections, but you can't
really rely on them.

* Most date selectors rely on Javascript, which may not be available
on the client.

* From a usability perspective, using a date selector is slower than
typing the date into a text field. Accessibility is also a concern.

* Above all, your code should still validate the correctness of input
on the server regardless of anything you are doing to make things
easier in the client. There are ways around using date selectors.

Andrew

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



Re: [PHP] PHP intreprets trailing slashes incorrectly?

2011-05-20 Thread Andrew Ballard
On Fri, May 20, 2011 at 6:35 AM, Richard Quadling rquadl...@gmail.com wrote:

[snip]


 At a #, the fragment_id doesn't seem to reach PHP.


Correct. Since the hash symbol (fragment identifier) signals the
beginning of the name of an internal bookmark within the document
returned by the server, browsers don't even send this as part of the
request, so it is not available to PHP. (I have seen it arrive as part
of a request, but that is a pretty good indication that the request
was submitted by a script rather than a browser.)


From section 3.5 of RFC 3986 (http://www.ietf.org/rfc/rfc3986.txt)

   ...the fragment identifier is not used in the scheme-specific
   processing of a URI; instead, the fragment identifier is separated
   from the rest of the URI prior to a dereference, and thus the
   identifying information within the fragment itself is dereferenced
   solely by the user agent, regardless of the URI scheme.


Andrew

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



Re: [PHP] Is 5.3.5 really that much slower than 5.2?

2011-03-06 Thread Andrew Mason
 Is anyone else out there in the same boat?

Actually we have found the complete opposite so there might be some
people who are in the same boat as you but certainly not all.

Andrew

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



Re: [PHP] Disk IO performance

2010-11-28 Thread Andrew Mason
On Mon, Nov 29, 2010 at 12:09 PM, Larry Garfield la...@garfieldtech.com wrote:
 There are many things that everybody knows about optimizing PHP code.  One
 of them is that one of the most expensive parts of the process is loading code
 off of disk and compiling it, which is why opcode caches are such a bit
 performance boost.  The corollary to that, of course, is that more files =
 more IO and therefore more of a performance hit.

I'd just organise them how you think makes most sense and then
optimize if you run into issues.

Kind regards
Andrew M

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



Re: [PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread Andrew Ballard
On Mon, Nov 1, 2010 at 11:13 AM, Richard Quadling rquadl...@gmail.com wrote:
 Hi.

 I have an abstract base class (call it genericServiceHandler).

 I have concrete classes (FaxService, EmailService).

 The genericServiceHandler is watching for commands from an external
 source. The commands will always be one of a fixed set, no matter what
 the concrete service is. They are Pause, Continue, Start, Stop,
 Shutdown, PreShutdown.

 The genericServiceHandler has no need to process the commands. It only
 receives them and maybe dispatches them to the concrete class.


Right up to here, it sounded more like an interface than an abstract base class.


 The concrete class doesn't have to implement handlers for all of the
 commands, though, at a minimum, onStart() would be pretty much
 essential.

[snip]

And then it didn't.  :-/


Andrew

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



Re: [PHP] Sessions only work in SSL

2010-10-19 Thread Andrew Ballard
On Mon, Oct 18, 2010 at 8:46 PM, Daniel Houle drho...@hotmail.com wrote:
 I have a strange issue here.  I am running a CentOS machine, with

 apache 2.2.3
 php 5.1.6
 kernel 2.6.18-194.8.1.el5xen

 My sessions will work using https, but not using simple http.  I've compared
 my configs with another identical machine which works with both, and I can't
 figure out why.  Anyone got an idea?

 Here's the simple script I run to test.

 ?php

 session_start();

 echo 'session started';

 if (isset($_SESSION['name'])) {
  echo 'br /' . $_SESSION['name'];
  session_destroy();
 } else {
  echo 'br /No session found';
  $_SESSION['name'] = 'My session';
 }

 phpinfo();
 ?

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



Are you sure session.cookie_secure is not turned on somewhere?

Andrew

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



Re: [PHP] RegExp question: how to add a number?

2010-10-15 Thread Andrew Ballard
On Fri, Oct 15, 2010 at 5:52 AM, Richard Quadling rquadl...@gmail.com wrote:
 On 15 October 2010 10:16, Ford, Mike m.f...@leedsmet.ac.uk wrote:
 -Original Message-
 From: Andre Polykanine [mailto:an...@oire.org]
 Sent: 14 October 2010 21:42

 Hi everyone,
 I hope you're doing well (haven't written here for a long time :-)).
 The question is as follows: I have a regexp that would do the
 following. If the string begins with Re:, it will change the
 beginning to Re[2]:; if it doesn't, then it would add Re: at the
 beginning. But (attention, here it is!) if the string starts with
 something like Re[4]:, it should replace it by Re[5]:.
 Here's the code:

 $start=mb_strtolower(mb_substr($f['Subject'], 0, 3));
 if ($start==re:) {
 $subject=preg_replace(/^re:(.+?)$/usi, re[2]:$1, $f['Subject']);
 } elseif ($start==re[) {
 // Here $1+1 doesn't work, it returns Re[4+1]:!
 $subject=preg_replace(/^re\[(\d+)\]:(.+?)$/usi, re[$1+1]:$2,
 $f['Subject']);
 } else {
 $subject=Re: .$f['Subject'];
 }

 I know there actually exists a way to do the numeral addition
 (Re[5]:, not Re[4+1]:).
 How do I manage to do this?

 This looks like a job for the e modifier (see 
 http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example 
 #4 at http://php.net/preg_replace). Something like:

  $subject = preg_replace(/^re\[(\d+)\:](.+?)$/eusi, 
 're['.(\\1+1).']:\\2', $f['Subject']);

 Cheers!

 Mike

 Watch out for the missing '[1]'. This needs to become '[2]' and not '[1]'.

 The callback seems to be the only way I could get the regex to work.


How about preg_replace_callback()?

Andrew

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



Re: [PHP] RegExp question: how to add a number?

2010-10-15 Thread Andrew Ballard
On Fri, Oct 15, 2010 at 11:07 AM, Richard Quadling rquadl...@gmail.com wrote:
 On 15 October 2010 15:45, Andrew Ballard aball...@gmail.com wrote:
 On Fri, Oct 15, 2010 at 5:52 AM, Richard Quadling rquadl...@gmail.com 
 wrote:
 On 15 October 2010 10:16, Ford, Mike m.f...@leedsmet.ac.uk wrote:
 -Original Message-
 From: Andre Polykanine [mailto:an...@oire.org]
 Sent: 14 October 2010 21:42

 Hi everyone,
 I hope you're doing well (haven't written here for a long time :-)).
 The question is as follows: I have a regexp that would do the
 following. If the string begins with Re:, it will change the
 beginning to Re[2]:; if it doesn't, then it would add Re: at the
 beginning. But (attention, here it is!) if the string starts with
 something like Re[4]:, it should replace it by Re[5]:.
 Here's the code:

 $start=mb_strtolower(mb_substr($f['Subject'], 0, 3));
 if ($start==re:) {
 $subject=preg_replace(/^re:(.+?)$/usi, re[2]:$1, $f['Subject']);
 } elseif ($start==re[) {
 // Here $1+1 doesn't work, it returns Re[4+1]:!
 $subject=preg_replace(/^re\[(\d+)\]:(.+?)$/usi, re[$1+1]:$2,
 $f['Subject']);
 } else {
 $subject=Re: .$f['Subject'];
 }

 I know there actually exists a way to do the numeral addition
 (Re[5]:, not Re[4+1]:).
 How do I manage to do this?

 This looks like a job for the e modifier (see 
 http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example 
 #4 at http://php.net/preg_replace). Something like:

  $subject = preg_replace(/^re\[(\d+)\:](.+?)$/eusi, 
 're['.(\\1+1).']:\\2', $f['Subject']);

 Cheers!

 Mike

 Watch out for the missing '[1]'. This needs to become '[2]' and not '[1]'.

 The callback seems to be the only way I could get the regex to work.


 How about preg_replace_callback()?

 Andrew


 Already provided an example using that : 
 http://news.php.net/php.general/308728

 It was the 'e' modifier I couldn't get to work, though I suppose, as
 the code is eval'd, I should have been able to do it.

 The callback just seems a LOT easier.


Sorry - I missed the callback function in there. The loop threw me off
because I thought that was part of the solution rather than a test
container.

Andrew

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



Re: [PHP] Casting from parent class to child

2010-10-08 Thread Andrew Ballard
On Fri, Oct 8, 2010 at 12:50 PM, Nathan Rixham nrix...@gmail.com wrote:
 David Harkness wrote:

 Casting does not change an object. You must copy the relevant value(s)
 from
 the object returned into a new DateTimePlus. Since DateTime's constructor
 takes only a string, and I assume it won't accept your format directly,

 unless you implement __toString I believe (not tested)


IMO, that would be a truly useful feature to add if you were extending
DateTime anyway.

Andrew

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



Re: [PHP] Re: Which PHP 5.3 documentation generators have you found?

2010-09-30 Thread Andrew Mason
On Fri, Oct 1, 2010 at 6:44 AM, David Harkness
davi...@highgearmedia.com wrote:
 While we don't use any 5.3 specific features such as namespaces yet, we set
 up our continuous integration system to use Doxygen. It runs significantly
 faster than phpDocumentor, though we put zero effort into tuning either
 system.


I started patching Doxygen a while ago but got sort of side tracked.
Out of PHPDocumentor and Doxygen, Doxygen seemed to be the closest as
it had namespace support already for other languages. only the tokens
needed changing. It uses Flex /Bison as the lexer and scanner so it's
pretty flexible. YMMV.

I have a bunch of FaiF code to release but i won't do so until i have
adequate documentation so I'll get around to adding support one of
these days.

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



Re: [PHP] Database Administration

2010-09-24 Thread Andrew Ballard
On Fri, Sep 24, 2010 at 6:19 AM, Tom Barrett t...@miramedia.co.uk wrote:
[snip]
 I'm not actually that familiar with DB admin to that extent. I have either
 app users with lock+crud on specific databases, or root. As a an aside,
 would you know if there is a level of permissions for a user between app and
 root that would be 'sensibly secure' (it will be MySQL 5)?

It depends on the app, but phrases like 'sensibly secure' raise
caution flags for me.

I tend to go with the principle of least privilege. Where I currently
work, the admin functions for a web application are usually on an
intranet site that is completely separate from the public site.
Because of this, I have a different database user for each site. In
this case, these are database-only logins unrelated in any way to the
actual machine account used by the web servers.

On our newer development, nearly all table access is managed strictly
through stored procedures (we use SQL Server, but the same would work
for MySQL if you were so inclined), and each database user is only
granted execute permission on the specific procedures necessary for
that role. The only time we grant access directly to a table is in
cases where we just can't get a procedure to do what we need
efficiently or effectively. And, in those cases where I do need to
grant access to a table, I grant permission to only the
columns/operations necessary for that user.

If I encountered a case where I needed to allow a user to make schema
changes as you mentioned in your original post, I would create a
totally separate account -- again with no more permission than
necessary for its intended task. Depending on the needs of the
application, I'd decide whether that account was used by the web
server or via a script scheduled to execute at intervals as several
others have suggested in this thread.

I've not tried this, but you could probably write the logic needed to
create the database objects into a stored procedure. Then, you might
only need to grant permission to that procedure and not grant
permission to CREATE/ALTER anything. That would pretty well guarantee
that the only objects created are the ones you intended.

Andrew

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



Re: [PHP] Session Vars loaded from MSSQL Query drop, those loaded from MYSQL Query stick

2010-09-17 Thread Andrew Ballard
);


                                //get form info for this employee
                                $cnx = 
 mysql_connect(localhost,appsuser,abc123);
                                $db = mysql_select_db(wrii_report);
                                $q1 = sprintf(select * from tblmainempreport 
 where empUUID = '553920090528131');
                                //print $q1 .br;
                                $result = mysql_query($q1);
                                $recArray = mysql_fetch_array($result);
                                $_SESSION['empFName'] = $recArray['EmpFName'];
                                ?
                form name=frmGoToEmpForm ID=frmGoToEmpForm method=post 
 action=empForm.php
                input type=hidden id=hdnSSN name=hdnSSN value=?php 
 print $rs_emp_info-fields(emp_ssn);? /
                 input type=hidden id=hdnCostCenter name=hdnCostCenter 
 value=?php print $rs_emp_info-fields(emp_costcenter);? /
                /form
                script language=javascriptfrmGoToEmpForm.submit();/script
            ?php
                                //header(Location: 
 http://webapps/injury/empForm.php;);
                                //exit();





 ?
 div id=mainContainer
  div id=topHeader/div
        div id=middle
        div class=helpNoteFor information or questions for this system, 
 please contact Linda Williams x5984
        /div
        div id=contentContainer
                div id=contentTextcenter?php print $rtnMsg?br /
            span class=nonRequiredTexta href=http://shhsnet/;Return to 
 SHH Intranet/a/span/center
            /div
         /div
        div id=footer/div
        /div

 /div
 /body
 /html
 empForm.php
  - code
 ---

 ?php session_start(); ?
 ?php

 //get avail ee info from ee database
 print session_SSN = .$_SESSION['SSN'].br;
 print session_CostCenter = .$_SESSION['CostCenter'].br;
 print hidden_SSN = .$_POST['hdnSSN'].br;
 print hidden_CostCenter = .$_POST['hdnCostCenter'].br;
 print session_empFName = .$_SESSION['empFName'].br;
 print session_userLastName = .$_SESSION['UserLastName'].br;
 print session_BadgeID = .$_SESSION['BadgeID'].br;

 ?
 
 Output from empForm.php
 ---
 session_SSN =
 session_CostCenter =
 hidden_SSN = 60 (it is displaying my actual SSN)
 hidden_CostCenter = 1604
 session_empFName = CHERYL
 session_userLastName = sullivan
 session_BadgeID = 401337


I'm not sure if this is it or not, but what happens if you change
these two lines:

$_SESSION['SSN'] = $rs_emp_info-fields(emp_ssn);

$_SESSION['CostCenter'] = $rs_emp_info-fields(emp_costcenter);

to this:

$_SESSION['SSN'] = (string) $rs_emp_info-fields(emp_ssn);

$_SESSION['CostCenter'] = (string) $rs_emp_info-fields(emp_costcenter);


My theory is that since you are using COM to query SQL Server, it is
returning COM variants, and the actual value of
$rs_emp_info-fields(emp_ssn) is not a scalar value - it's a COM
variant of something like an ADODB.Field. The default property of that
datatype is the object's value, so when you use print to write its
value in the form, it is probably implicitly converting the object to
its default property which is a string. However, when you assign it to
$_SESSION['SSN'], it may be that it is assigned as a COM variant that
cannot be correctly serialized in the session. By explicitly
typecasting the value to a string when you assign it to the session,
you'll get the value rather than its wrapper.

For what it's worth, it is probably also worthwhile to plan at some
point soon on changing from COM to a native PHP library to get data
from SQL Server. Since you are already running on Windows, Microsoft's
SQL Server Driver for PHP should be a great replacement for you. It
returns values as the correct native PHP type rather than wrapped
inside those COM variants.

Andrew

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



Re: [PHP] Session Vars loaded from MSSQL Query drop, those loaded from MYSQL Query stick

2010-09-16 Thread Andrew Ballard
On Thu, Sep 16, 2010 at 10:26 AM, Cheryl Sullivan csull...@shh.org wrote:
 Absolutely -

 This is from the first page

 ?php

 $_SESSION['UserLastName'] = strtolower(trim($_POST['txtLastName']));

 $_SESSION['BadgeID'] = trim($_POST['txtBadgeID']);

 //access MS SQL Server database

 $q1 = select * from emps where emp_last =
 '.$_SESSION['UserLastName'].' and emp_badge =
 '.$_SESSION['BadgeID'].';

 $rs_emp_info = hitMSSQL($q1,_sql,database,table,password,1);

 $_SESSION['SSN'] = $rs_emp_info-fields(emp_ssn);

 $_SESSION['CostCenter'] = $rs_emp_info-fields(emp_costcenter);

 //access mySQL database

 $cnx = mysql_connect(localhost,userID,password);

 $db = mysql_select_db(database_name);

 $q1 = select * from tblmainempreport where empUUID =
 'sdfsfs920090528131';

 $result = mysql_query($q1);

 $recArray = mysql_fetch_array($result);

 $_SESSION['empFName'] = $recArray['EmpFName'];

 ?



 When I echo all five $_SESSION vars from here, they are all populated.
 Then I can either redirect or form post to the next page.  In either
 case, the $_SESSION vars populated from SQL Server ( the SSN and Cost
 Center vars) are blank when I echo them on the destination page.

The fact that you can echo the $_SESSION information on the same page
and they contain the correct values suggest to me that the issue of
MySQL/MSSQL is a red herring. I would look into things like the value
for register_globals to make sure you don't have a global variable
stepping on some of your session variables.

Andrew

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



Re: [PHP] Session Vars loaded from MSSQL Query drop, those loaded from MYSQL Query stick

2010-09-16 Thread Andrew Ballard
On Thu, Sep 16, 2010 at 10:26 AM, Cheryl Sullivan csull...@shh.org wrote:
[snip]
 When I echo all five $_SESSION vars from here, they are all populated.
 Then I can either redirect or form post to the next page.  In either
 case, the $_SESSION vars populated from SQL Server ( the SSN and Cost
 Center vars) are blank when I echo them on the destination page.

On Thu, Sep 16, 2010 at 2:12 PM, Cheryl Sullivan csull...@shh.org wrote:
 Tommy  - I ran phpinfo() but I don't see anything in it referencing
 MSSQL or SQLSRV.  I have included all the references to sql I see
 below, but the only references I see to databases are to mySQL and
 SQLLite.  Unfortunately I don't have any control over how service-packed
 the database server is.  Is there something in SP 4 for SQL Server 2000
 that is supposed to fix the issue I'm having, I may be able to plead my
 case for getting the latest SP.  Is this the case, do you know?

[snip]

Again, I ask - based on what you said earlier - are you sure this is
even a database issue? You said that when you echo the values in your
$_SESSION array AFTER reading them from the database they are there,
and you only lose them on the next request after either a redirect or
a manual form POST. If the values are getting into $_SESSION correctly
within this page, your issue is not related to the database at all.

Am I misunderstanding you?

Andrew

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



Re: [PHP] Adjusting Session Times

2010-09-14 Thread Andrew Ballard
On Tue, Sep 14, 2010 at 10:26 AM, Floyd Resler fres...@adex-intl.com wrote:
 We just got a client whose requirement is that user sessions expire after 30 
 minutes of inactivity.  Our other clients are happy with not having their 
 sessions expire during the work day (i.e. life is 8 hours).  I am using a 
 MySQL database to store the session data.  My thought is to adjust the 
 session expiration in the table based on the client currently logged in.  Is 
 this a good approach or would there be better ways to do it?  And just to 
 clarify: all clients use the same Web site.

 Thanks!
 Floyd

I store the date and time of the last page access and the session
lifetime in minutes in the database. Then when I fetch the session
from the database, the WHERE clause includes a condition that the
number of minutes elapsed between the current date/time and the time
stored in the session table is less than the session lifetime (maximum
duration of inactivity for that session). That way, each individual
user could have his or her own session timeout period if needed.

Andrew

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



Re: [PHP] Show text without converting to html

2010-09-09 Thread Andrew Ballard
On Thu, Sep 9, 2010 at 9:52 AM, Jack jacklistm...@gmail.com wrote:

 Hello All,


 I have some code which converts to some html to ascii characters.  This
 basically obfuscates the html code, but shows it correctly on an page.


 I am trying to show the results of the obfuscation ( works correctly because
 it displays the html value ), but I want to then show the obfuscated html
 code so they can copy it.

 An example is I want to show them this below:

 a
 href=#x6d;#x61;#x69;#108;#x74;#111;#x3a;#x79;#x6f;#117;#114;#x4
 0;#101;#x6d;#00097;#x69;#x6c;#x2e;#97;#x64;#x64;#x72;#000101;#00
 0115;#115;?subject=cc=bcc=body= style= class=
 id=#x79;#000111;#x75;#000114;#x40;#x65;#x6d;#97;#105;#x6c;#000
 46;#x61;#x64;#x64;#000114;#x65;#000115;#x73;/a



 Which was created by the code, but I apparently can't seem to echo it and
 get it to display like above.. It converts it to html no matter what I do.


This should do it:

?php

$var = 'a 
href=#x6d;#x61;#x69;#108;#x74;#111;#x3a;#x79;#x6f;#117;#114;#x40;#101;#x6d;#00097;#x69;#x6c;#x2e;#97;#x64;#x64;#x72;#000101;#000115;#115;?subject=cc=bcc=body=
style= class=
id=#x79;#000111;#x75;#000114;#x40;#x65;#x6d;#97;#105;#x6c;#00046;#x61;#x64;#x64;#000114;#x65;#000115;#x73;/a';


echo  htmlspecialchars($var);

?

The obfuscation doesn't buy you much, though.

?php

var_dump(html_entity_decode($var, ENT_QUOTES, 'utf-8'));

?
string(106) a
href=mailto:y...@email.address?subject=cc=bcc=body=; style=
class= id=y...@email.address/a

The only people for whom the value will be obscure will be the humans
who actually try to read the HTML source code itself. Neither web
browsers nor harvesting scripts won't have any trouble reading it.

Andrew

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



Re: [PHP] Show text without converting to html

2010-09-09 Thread Andrew Ballard
On Thu, Sep 9, 2010 at 11:39 AM, Jack jacklistm...@gmail.com wrote:
 -Original Message-
 From: Andrew Ballard [mailto:aball...@gmail.com]


 The only people for whom the value will be obscure will be the humans who 
 actually try to read the HTML source code itself. Neither web browsers nor 
 harvesting scripts won't have any trouble reading it.

 Andrew


 Andrew,

 One other note, if the link doesn't say mailto: a harvester will have to 
 decode the entire page in order to find the mailto, do you think that’s 
 happening.  This could be one of those things where you help against a 
 percentage of harvesters, and not others.

 J

It will protect against a (possibly large?) percentage of those that
are looking for the lowest hanging fruit. I have a few reasons that
feed my doubts about its effectiveness:

- The most common answer you find when you search for e-mail
obfuscation is something similar to what you've shown, whether it uses
HTML character entities, numeric entities, or a combination of the
two.

- The overhead to convert frankly isn't that high. I realize that in
the case of a harvester you are multiplying that overhead by the sheer
volume of content being processed, but given the speed of processors I
don't think that matters much anymore.

- There are simple ways to minimize the overhead. For example, a
script does not have to decode an entire page; it only has to look for
anchor tags and decode the contents of the href attribute of each tag
found.


Combine these and I don't think this obfuscation technique adds enough
cost to be much of a barrier. Of course, this is just my opinion.
Those who write harvesters might be lazier than I give them credit.


Andrew

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



Re: [PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Andrew Ballard
On Fri, Aug 20, 2010 at 9:05 AM, Colin Guthrie gm...@colin.guthr.ie wrote:
 Thanks everyone for responses.

 'Twas brillig, and Nathan Rixham at 20/08/10 13:17 did gyre and gimble:
 if you use mysql you can seed rand() with a number to get the same
 random results out each time (for that seed number)

   SELECT * from table ORDER BY RAND(234)

 Then just use limit and offset as normal.

 This is a neat trick! Yeah that will avoid the need for the static
 lookup table with 32 randomised columns.

Would it work to return a list of some limited number of randomly
ordered featured listings/items on the page, while leaving the full
list ordered by whatever natural ordering (by date, order entered,
alphabetical, etc.)? That gives every owner a chance to appear in a
prominent spot on the page while solving the issue you cited about
page breaks (and SEO if that is a concern). You can still use any of
the suggestions that have been discussed to determine how frequently
the featured items list is reseeded to help make caching practical.

Just a thought.

Andrew

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



Re: [PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Andrew Ballard
On Fri, Aug 20, 2010 at 9:31 AM, Colin Guthrie gm...@colin.guthr.ie wrote:
 'Twas brillig, and Andrew Ballard at 20/08/10 14:24 did gyre and gimble:
 Would it work to return a list of some limited number of randomly
 ordered featured listings/items on the page, while leaving the full
 list ordered by whatever natural ordering (by date, order entered,
 alphabetical, etc.)? That gives every owner a chance to appear in a
 prominent spot on the page while solving the issue you cited about
 page breaks (and SEO if that is a concern). You can still use any of
 the suggestions that have been discussed to determine how frequently
 the featured items list is reseeded to help make caching practical.

 Yeah we've tried to push this as an option too, but so far our clients
 are not biting on this suggestion. They like the idea but in
 addition to randomised listings too!

 Speaking of SEO, that was one of our concerns about randomising listings
 too. What impact do you think such randomised listings will have on SEO?

 Obviously if a term is matched for a listing page that contains a thing
 and when the user visits that page, the thing itself is not on in the
 listing, then the user will be disappointed, but will this actually
 result in SEO penalties?

 Col

I'm not sure it would penalize you in the algorithms. I was thinking
more of the number of times I have followed a promising-looking link
and found that the site where I was directed was a page of and index
of article headings or post subjects showing results 1000-1500 out of
1+, and the item I was hoping to see is no longer on that page. Is
it on the next page? No. Next page? No. Oh, forget it - back go
[search engine].

In that case, even if the site's page rank doesn't decrease, the
search results are out-of-sync and thus inaccurate. The site can
definitely take a hit with regard to end-user perception and can cause
annoyed users to leave and/or ignore your site, which are more
important issues than a number from some search engine's algorithm.
After all, it doesn't matter how many people Google, Bing, Yahoo or
some other search engine sends your way if those users end up
frustrated by the experience and don't actually use the site once they
get there.

Andrew

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



Re: [PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Andrew Ballard
On Fri, Aug 20, 2010 at 10:19 AM, Colin Guthrie gm...@colin.guthr.ie wrote:
 The customer is always right - in his own mind (even if not in his RIGHT 
 mind) - after all!

Corrected that for you.  ;-)

Andrew

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



Re: [PHP] Can't read $_POST array

2010-08-18 Thread Andrew Mason
On Thu, Aug 19, 2010 at 7:41 AM, Daevid Vincent dae...@daevid.com wrote:
 You've got something jacked. DO NOT proceed with your coding using this
 hack.

 Put this in a blank file named whatever_you_want.php and hit it with your
 web browser.

 ---
 -
 ?php if ($_POST['action'] == 'Go') print_r($_POST); ?

 form action=?=$_SERVER['SCRIPT_NAME']? method=POST
        select name=my_select
                option value=foofoo/option
                option value=barbar/option
        /select
        input type=submit value=Go name=action class=button
 submit/
 /form
 ---
 -

 -Original Message-
 From: Brian Dunning [mailto:br...@briandunning.com]
 Sent: Wednesday, August 18, 2010 2:23 PM
 To: PHP-General
 Subject: Re: [PHP] Can't read $_POST array

 This was the complete code of the page (this is the POST
 version not the REQUEST version):

 ?php
 $response = print_r($_POST, true);
 echo $response;
 ?

 Returns an empty array no matter what POST vars are sent. We
 fixed it by changing it to this, which I've never even heard
 of, but so far is working perfectly:

 ?php
 $response = file_get_contents('php://input');
 echo $response;
 ?

 I have no idea what the problem was. Thanks to everyone for your help.


 --
 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


Does what your posting contain any content like '' '' my guess is
that you need to access the content using the filter_ functions.

Andrew

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



Re: [PHP] Variable variables into an array.

2010-08-10 Thread Andrew Ballard
On Tue, Aug 10, 2010 at 12:23 PM, Richard Quadling rquadl...@gmail.com wrote:
 On 10 August 2010 16:49, Jim Lucas li...@cmsws.com wrote:
 Richard Quadling wrote:

 Hi.

 Quick set of eyes needed to see what I've done wrong...

 The following is a reduced example ...

 ?php
 $Set = array();
 $Entry = 'Set[1]';
 $Value = 'Assigned';
 $$Entry = $Value;
 print_r($Set);
 ?

 The output is an empty array.

 Examining $GLOBALS, I end up with an entries ...

    [Set] = Array
        (
        )

    [Entry] = Set[1]
    [Value] = Assigned
    [Set[1]] = Assigned


 According to http://docs.php.net/manual/en/language.variables.basics.php,
 a variable named Set[1] is not a valid variable name. The [ and ] are
 not part of the set of valid characters.

 In testing all the working V4 and V5 releases I have, the output is
 always an empty array, so it looks like it is me, but the invalid
 variable name is an issue I think.

 Regards,

 Richard.

 NOTE: The above is a simple test. I'm trying to map in nested data to
 over 10 levels.

 For something like this, a string that looks like a nested array reference,
 you might need to involve eval for it to derive that nested array.


 I'm happy with that.

 It seems variable variables can produce variables that do not follow
 the same naming limitations as normal variables.


It would seem so. If eval() works, can you rearrange the strings a
little to make use of parse_str() and avoid the use of eval()?

Andrew

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



Re: [PHP] Quotes vs. Single Quote

2010-08-06 Thread Andrew Ballard
On Fri, Aug 6, 2010 at 8:31 AM, tedd tedd.sperl...@gmail.com wrote:
 While it may not be obvious, the statement:

 table border=1

 is flawed (IMO).

 The best way to handle this is to define a class (or id) for the table in
 a css file and then set the border (i.e., styling) to whatever you want. For
 example, your HTML would look like:

 table class=my_table

 And your CSS would contain:

 .my_table
   {
   border: 1px solid black;
   }


I more or less agree with you, but sometimes it's technically a little
more difficult than that. The border attribute on the table tag
affects not only the table itself, but also the cells inside it. The
CSS attribute only draws a border around the table. I believe the CSS
equivalent of how most browsers (I tested Fx 3.6.8, IE 7, Google
Chrome 5, Opera 10.53, and Safari (Windows) 5.0.1) render table
border=1 takes a little more:

table.my_table,
table.my_table  thead  tr  th,
table.my_table  tbody  tr  th,
table.my_table  tfoot  tr  th,
table.my_table  thead  tr  td,
table.my_table  tbody  tr  td,
table.my_table  tfoot  tr  td
{
border: solid 1px black;
}

And, of the browsers listed above, IE7 did not render the table
correctly. (I'm guessing it must not properly handle the child CSS
selectors.) If you do it without the child selectors:

table.my_table,
table.my_table th,
table.my_table td
{
border: solid 1px black;
}

All the browsers render it the same, but it has the side effect that
cells in nested tables also inherit the borders unless you do
something to exclude them:

table.my_table,
table.my_table th,
table.my_table td
{
border: solid 1px black;
}

table.my_table table,
table.my_table table th,
table.my_table table td
{
border: none;
}

As is often the case with CSS, that's a good bit more text to
accomplish the same effect as an older, smaller attribute.  :-)

Andrew

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



Re: [PHP] Question about SQL and Graph nodel trees

2010-07-21 Thread Andrew Ballard
On Wed, Jul 21, 2010 at 11:04 AM, Tim Gallagher tgallag...@danati.com wrote:
 I cannot be the only one that is having this problem, what are you using for 
 DAG (Direct Acrylic Graph)?  I need to have a mesh node edge graph and am 
 having trouble with this?  I see that Neo4j has a rest server and I can do 
 this in Java but I want to do it in PHP with a MYSQL or postgresql.  If you 
 are doing something like this, can you please tell me how you are doing this. 
  I can do a relationship with a parent child or a nested tree, but I need to 
 do a DAG.

 Thanks for the help,
 timgerr


A basic approach would be to use two tables - one to store the nodes
and second table to store the edges between the nodes. As far as
traversing the graph, the best approach I have seen expands this a bit
to store the full transitive closure of the graph, rather than just
the direct edges:

http://www.codeproject.com/KB/database/Modeling_DAGs_on_SQL_DBs.aspx

It is written for SQL Server, but the idea works OK (and I
successfully tested it once) in MySQL. (I imagine the same would be
true for PostgreSQL.)

The idea is to store the transitive closure (every possible path) of
the entire graph. For instance, if you have a basic graph

A - B - C - D

it stores these paths:

A - B
B - C
C - D
A - C
B - D
A - D

The obvious downside is that edge table can get incredibly large
depending on the nature of the graph you are modeling. (The article
provides much more detail.) I did, however, import a good chunk of an
Active Directory tree (just users and groups, not the full list of
attributes) into this pattern just to test the concept, and I found
that in that case the size of the transitive closure table did not get
out of hand.


Andrew

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



Re: [PHP] access violation

2010-07-19 Thread Andrew Ballard
On Mon, Jul 19, 2010 at 9:54 AM, SteveW stevewa...@btinternet.com wrote:
 I have various database / php apps running on a hosted windows machine.

 All apps run ok.

 We have installed a windows 2003 server machine and the apps run fine.
 However if 2 users hit the Search button at the same time we get a PHP
 access violation and I have to restart IIS.

 This is not happening on the hosted service.


 Where do I start to trace this error please?


 Cheers


 SteveW


We had frequent access violations using Windows/IIS/SQL Server, but
there was no observable pattern and we never were able to trace it to
a specific cause. It did seem to be related to traffic/load, but it
wasn't as specific as simply having two simultaneous requests. Often
the error messages would begin to appear intermittently, but
eventually the server would freeze to the point that any request
parsed by PHP would throw an access violation.

We changed things around based on advice we found on the web and have
found the following to be pretty stable:

PHP: fast-cgi instead of the ISAPI (even though the manual was still
recommending ISAPI)
Database library: Microsoft SQL Server driver for PHP
Cache: WinCache

Since we settled on these items, things have been pretty stable.

Andrew

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



Re: [PHP] Determining the similarity between a user supplied short piece of text (between 5 and 15 characters) and a list of similar length text items.

2010-07-19 Thread Andrew Ballard
On Mon, Jul 19, 2010 at 2:46 PM, tedd tedd.sperl...@gmail.com wrote:
 At 12:39 PM +0100 7/19/10, Richard Quadling wrote:

 I'm using MS SQL, not mySQL.

 Found a extended stored procedure with a UDF.

 Testing it looks excellent.

 Searching for a match on 30,000 vehicles next to no additional time -
 a few seconds in total, compared to the over 3 minutes to search using
 SQL code.

 That seems a bit slow.

 For example, currently I'm searching over 4,000 records (which contains
 4,000 paragraphs taken from the text of the King James version of the Bible)
 for matching words, such as %created% and the times are typically around
 0.009 seconds.

 As such, searching ten times that amount should be in the range of tenths of
 a second and not seconds -- so taking a few seconds to search 30,000 records
 seems excessive to me.

 Cheers,

 tedd

I would be surprised if a Levenshtein or similar_text comparison in a
database were NOT slower than even a wildcard search because of the
calculations that have to be performed on each row in the column being
compared. That, and the fact that user-defined functions in SQL Server
often have a performance penalty of their own.

Just for kicks, you could try loading the values in that column into
an array in PHP and then time iterating the array to calculate the
Levenshtein distances for each value to see how it compares.

Andrew

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



Re: [PHP] ldap_search filter filter?

2010-07-16 Thread Andrew Ballard
On Fri, Jul 16, 2010 at 11:42 AM, Richard Lynch c...@l-i-e.com wrote:
 Any Best Practice suggestions for potentially hostile user input being
 sent to ldap_search($ldap, (username=$_POST[username]));

 Something like an ldap_escape?

 Please cc me on replies. Thanks.


Long time no see, Richard. There are a couple ldap_escape() functions
in the comments here. I don't know enough about ldap to know how
robust they are. I have used one of them, but only on a few intranet
sites where the probability of malicious activity is fairly low.

http://www.php.net/manual/en/function.ldap-search.php


Andrew

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



Re: [PHP] XML parser

2010-07-13 Thread Andrew Ballard
On Tue, Jul 13, 2010 at 10:14 AM, ppps...@gmail.com ppps...@gmail.com wrote:
 Hello. I have html:
 h3Header/h3
 pParagraph 1/p
 
 pParagraph n/p

 div
 h3Header/h3
 pParagraph 1/p
    
 pParagraph n/p
 /div

 need to parse it like this array:
 array(
 [0] = array(
 'h3' = 'header' ,
 'p' = array(
 [0] = 'Paragraph 1' ,
 [n-1] = 'Paragraph N'
 )
 [1] = array(
 ['div'] = array (
 'h3' = 'header' ,
 'p' = array(
 [0] = 'Paragraph 1' ,
 [n-1] = 'Paragraph N'
 )
 ) ;

 maybe simple other. Which pear class i can use for this task ?




Why PEAR? That looks almost exactly like SimpleXML.

Andrew

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



Re: [PHP] MSSQL failing.

2010-07-09 Thread Andrew Ballard
On Fri, Jul 9, 2010 at 7:10 AM, Paul Halliday paul.halli...@gmail.com wrote:
 On Fri, Jul 9, 2010 at 7:12 AM, Paul Halliday paul.halli...@gmail.com wrote:
 It was a typo :) The installation is running on FreeBSD. I am looking
 at TDS right now as a possible cause.


 Got it:

 In /usr/local/etc/freetds.conf:

 [global]
       host = 10.x.x.x
       port = 1433
       client charset = UTF-8
       tds version = 8.0
       text size = 20971520

 Thanks.


I'm glad you got it working. That's pretty much what I found when I
tried to set it up here as well. I left the host and port out of my
freetds.conf file, though.


Andrew

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



Re: [PHP] MSSQL failing.

2010-07-08 Thread Andrew Ballard
On Thu, Jul 8, 2010 at 1:01 PM, Paul Halliday paul.halli...@gmail.com wrote:
 Is there something that needs to be tweaked or added to get this to
 work? I am trying to connect to server 2008 w/ MS SQL 2008. I can see
 the connections fail in the servers event logs if I take away \domain
 from \domain\username (mixed auth is turned off) so the communication
 is somewhat working.

 What am I missing?


Is the slash before the domain name above just a typo in your e-mail?
It took a while to get mssql configured to where I could test it here
since we're using Microsoft's SQL Server Driver for PHP (if you are
running PHP under Windows, I'd strongly recommend this over the old
mssql library anyway), but this worked:

?php

$hostname = 'hostname:1433';

$username = 'DOMAIN\Username';
$password = 'password';

$conn = mssql_connect($hostname, $username, $password) or die('Unable
to connect');

var_dump($conn);

?

Andrew

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



Re: [PHP] mail() + localhost

2010-07-01 Thread Andrew Ballard
On Thu, Jul 1, 2010 at 9:09 AM, Shreyas Agasthya shreya...@gmail.com wrote:
 Also, when the comment says that you need to 'configure' your php.ini, which
 .ini should I modify? The reason being, I see that file in two locations,
 apparently.
 (i) C:\Program Files\EasyPHP 3.0\apache
 (ii) C:\Program Files\EasyPHP 3.0\conf_files

Call this in a script running under your web server:

http://www.php.net/phpinfo


Alternatively, you could also look at these:

http://www.php.net/php-ini-loaded-file
http://www.php.net/php-ini-scanned-files


Andrew

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



Re: [PHP] PHP QPay

2010-06-29 Thread Andrew Ballard
On Tue, Jun 29, 2010 at 10:50 AM, Daniel P. Brown
daniel.br...@parasane.net wrote:
 On Tue, Jun 29, 2010 at 10:41, Jay Blanchard jblanch...@pocket.com wrote:
 [snip]
 As QPay seems to be an Aussie company, you may need to think a little
 bigger than just the small market in the USA.
 [/snip]

 QPay is a Miami, FL based company whose really lame web site is
 http://www.qpaynet.com.

    Am I the only one prompted with a By Invitation Only HTTP
 authentication zone overlaying the TemplateMonster-ish site at that
 address?


Nope. Got the same as well, for any of the links at the top of the
page. I also got 404 responses to the link that Richard posted, until
after viewing the root index page. Strange.

Andrew

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



Re: [PHP] file_get_contents limit

2010-06-29 Thread Andrew Ballard
On Tue, Jun 29, 2010 at 4:21 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Tue, 2010-06-29 at 17:02 -0300, Jo?o C?ndido de Souza Neto wrote:

 The characters are stripped off of the end of the file after that point.

 --
 Joo Cndido de Souza Neto

 Ashley Sheridan a...@ashleysheridan.co.uk escreveu na mensagem
 news:1277841481.2253.39.ca...@localhost...
  On Tue, 2010-06-29 at 16:53 -0300, Jo?o C?ndido de Souza Neto wrote:
 
  Ive got a file with only one line 21917 characters long but when I read
  this file using $varData = file_get_contents(file.txt) it gets only
  21504
  characters.
 
  Anyone would know why does it happen?
 
  Thanks in advance.
 
  --
  Joo Cndido de Souza Neto
 
 
 
 
 
  Are the characters stripped off of the end of the file after that point,
  or is the encoding not correctly determined and some characters are
  converted the wrong ones?
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 




 Have you looked at the memory settings in php.ini?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




I doubt that is the cause, at least not by itself. 21504 characters is
only 21K of data (could be more if the characters are multi-byte
encoded, but still less than 100K) , and the default memory limit in
PHP is 128M. I'm not sure what else it could be, though, as I don't
see any limitations on file_get_contents() discussed in the manual.

Andrew

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



Re: [PHP] file_get_contents limit

2010-06-29 Thread Andrew Ballard
On Tue, Jun 29, 2010 at 4:39 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:

 On Tue, 2010-06-29 at 16:37 -0400, Andrew Ballard wrote:

  On Tue, Jun 29, 2010 at 4:21 PM, Ashley Sheridan
  a...@ashleysheridan.co.uk wrote:
  
   Have you looked at the memory settings in php.ini?
  
 
  I doubt that is the cause, at least not by itself. 21504 characters is
  only 21K of data (could be more if the characters are multi-byte
  encoded, but still less than 100K) , and the default memory limit in
  PHP is 128M. I'm not sure what else it could be, though, as I don't
  see any limitations on file_get_contents() discussed in the manual.

 Default memory limit is still 32MB on every default install I've seen.


The manual currently shows 128M, and that's what I've seen for some
time now. Even so, a function returning less than 100K shouldn't
exhaust 32M of memory either, unless something else is at play. If
there is a memory limit being reached, PHP should log either an error
or warning (I can't remember which).

Andrew

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



Re: [PHP] mysql case statement

2010-06-28 Thread Andrew Ballard
On Sun, Jun 27, 2010 at 4:08 AM, Tanel Tammik keevit...@gmail.com wrote:
 Hello,

 how to select only if value is present?

    $query = $db-query(select menus.id, menus.name,
      case
        when panels.id is not null then '1'
        end as hiddenpanel

    from  . \DB_MENUS .  as menus
      left join  . \DB_HIDDENPANELS .  as panels on (menus.id =
 panels.menu_id)
    where menus.id=' . (int)$id . '
    );

 i would like to select hiddenpanel only if there is a corresponding value in
 DB_HIDDENPANELS. At the moment i get NULL if there is no corresponding value
 in HIDDENPANELS table!

 Br
 Tanel


That's what a LEFT JOIN does - it returns all rows from the LEFT table
that match the criteria in the WHERE clause, and then returns any rows
from the RIGHT table that happen do match. If you only want rows that
exist in both tables, change the join from LEFT (OUTER) JOIN to INNER
JOIN.

Andrew

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



Re: [PHP] Attachment to email from form.

2010-06-28 Thread Andrew Ballard
On Mon, Jun 28, 2010 at 8:53 AM, Richard Quadling rquadl...@gmail.com wrote:
 On 28 June 2010 13:44, Brandon Rampersad brandon.add...@gmail.com wrote:
 f**k no

 Enlightened criticism aside, why not? Or rather (as I'm willing to adapt) how?

Probably because you ignored his latest request to chat. Just guessing, really.

Andrew

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



Re: [PHP] Attachment to email from form.

2010-06-28 Thread Andrew Ballard
On Mon, Jun 28, 2010 at 10:04 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:

 On Mon, 2010-06-28 at 09:58 -0400, Andrew Ballard wrote:

 On Mon, Jun 28, 2010 at 8:53 AM, Richard Quadling rquadl...@gmail.com wrote:
  On 28 June 2010 13:44, Brandon Rampersad brandon.add...@gmail.com wrote:
  f**k no
 
  Enlightened criticism aside, why not? Or rather (as I'm willing to adapt) 
  how?

 Probably because you ignored his latest request to chat. Just guessing, 
 really.

 Andrew


 No, he often emails the list with random insults. He's emailed me personally 
 a couple of times too in response to a list email. Normally I'd keep this off 
 list, but as it's been going on for so long, and others have noticed it too, 
 figured his off-list behaviour should be mentioned as well.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



You are right, although my previous post was intended a little more
tongue-in-cheek. I just thought perhaps he was an embittered Google
Chat evangelist or something.  :-)

Andrew

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



Re: [PHP] mysql case statement

2010-06-28 Thread Andrew Ballard
On Mon, Jun 28, 2010 at 10:27 AM, David McGlone da...@dmcentral.net wrote:
 Tanel, we both learned something. I didn't fully understand join myself yet,
 but I think I do now.

 but let me ask this if the join wasn't there would an if statement like I
 mentioned have worked?

 Blessings,
 David M.

I think you are confusing a few things. You can't really rely on
testing empty(DB_HIDDENPANELS) because the value of the constant
DB_HIDDENPANELS is most likely a string that was set with an earlier
call to define. The OP could have tested for the column value
hiddenpanel using an if (...) test as you suggeted. However, given
that the OP stated he would like to select hiddenpanel only if there
is a corresponding value in DB_HIDDENPANELS, the INNER JOIN will do
that at the database query level, so an if (...) then test in PHP
isn't really necessary.

Andrew

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



Re: [PHP] Making a Password Confirmation in PHP

2010-06-25 Thread Andrew Ballard
On Fri, Jun 25, 2010 at 5:35 AM, Richard Quadling rquadl...@gmail.com wrote:
 And the fact that a browser will transmit input type=password as
 plain text isn't a security issue?

That's what SSL is for.

Andrew

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



Re: [PHP] Returning a Recordset from a Funtion

2010-06-25 Thread Andrew Ballard
On Fri, Jun 25, 2010 at 9:55 AM, David Stoltz dsto...@shh.org wrote:
 Hi Folks,



 Upon occasion, I have the need to hit our MS MSL database from our
 PHP/mySQL server. So I've created a function, but I'm not sure if you
 can return a recordset from a function. My code is below...



 In the calling page I code:

 ?php

 include('../includes/mssql.php');

 hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?



 The mssql.php include file is:

 ?php

 function hitMSSQL($server,$db,$login,$pass,$query){



                $conn = new COM (ADODB.Connection)

                  or die(Cannot start ADO);

                $connStr =
 PROVIDER=SQLOLEDB;SERVER=.$server.,1433;UID=.$login.;PWD=.$pass.;
 DATABASE=.$db;

                $conn-open($connStr);

                $rs = $conn-execute($query);

                return $rs;



 }

 ?



 If I have the echo statement in the function, it works.



 And of course I can return a single value like:

 Return $rs-Fields(value);



 But I can't return the whole recordset...



 Does anyone have any good ideas so I can access the recordset in the
 calling page?



 Thanks!



Is there a reason you need to work with COM/ADODB to get the
information from SQL Server as opposed to one of the PHP libraries? If
your are using COM you must be running under Windows which means you
should be able to use Microsoft's SQL Server Driver for PHP, which is
the best tool I've seen to date for the task. There are also the older
mssql and the newer PDO_MSSQL libraries, or even odbc or PDO_ODBC that
will work OK in many cases as well. Any of these are much simpler to
work with than COM variants in PHP.

Andrew

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



Re: [PHP] $_SERVER['REMOTE_ADDR'] and sql injection

2010-06-23 Thread Andrew Ballard
On Wed, Jun 23, 2010 at 6:01 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 That's what I'd use. You may also have to wrap it inside an abs() call
 to ensure it's a positive number, as some IP addresses equate to
 negative with ip2long().

NO NO NO NO NO

?php

$x = ip2long('192.168.0.1');
var_dump($x);
// int(-1062731775)

var_dump(long2ip($x));
// string(11) 192.168.0.1

var_dump(long2ip(abs($x)));
// string(13) 63.87.255.255

?

Andrew

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



Re: [PHP] $_SERVER['REMOTE_ADDR'] and sql injection

2010-06-23 Thread Andrew Ballard
On Wed, Jun 23, 2010 at 10:39 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:

 On Wed, 2010-06-23 at 10:35 -0400, Andrew Ballard wrote:

 On Wed, Jun 23, 2010 at 6:01 AM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:
  That's what I'd use. You may also have to wrap it inside an abs() call
  to ensure it's a positive number, as some IP addresses equate to
  negative with ip2long().

 NO NO NO NO NO

 ?php

 $x = ip2long('192.168.0.1');
 var_dump($x);
 // int(-1062731775)

 var_dump(long2ip($x));
 // string(11) 192.168.0.1

 var_dump(long2ip(abs($x)));
 // string(13) 63.87.255.255

 ?

 Andrew

 Someone had better tell all the makers of the ip2country databases then, 
 because there's not a negative number in sight!

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



You might choose to store an 8-byte integer rather than a 4-byte
integer to prevent negative numbers, but abs() won't do that. Usually
when I store IPv4 addresses in a database, I store them as BINARY(4)
so that I can compare ranges without worrying about either handling
negative numbers or using 8 bytes of storage to deal with addresses
above 127.255.255.255. I have also seen people present a case for
storing each octet in a separate TINYINT column.

Andrew

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



Re: [PHP] $_SERVER['REMOTE_ADDR'] and sql injection

2010-06-23 Thread Andrew Ballard
On Wed, Jun 23, 2010 at 11:09 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 Out of interest, how does PHP calculate the IP number, as it was my 
 understanding of IP numbers that they can't be negative.

 For example, my IP address is 89.243.156.135
 The four parts as binary:
 01011001
 0011
 10011100
 1111

 From there, I thought that the binary values were concatenated as if they 
 were a string, and then the decimal value worked out from that, giving, in my 
 case, a value of 1509137543.

 How is it possible that PHP can produce negative values from this method? 
 Does it do something else entirely, or is this a case of the integer value 
 overflowing into negative values? (which might explain why the value 
 correctly converts back)

 If so, what would be the best method to get the correct value, as abs() 
 obviously isn't it!

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



It has to do with the storage of the value as a 4-byte integer, as Bob
mentioned. The best way I know of in PHP involves either sprintf
dechex, or pack/unpack. If you use pack/unpack, just be careful with
the endian-ness of the format you choose:

?php

$x = ip2long('192.168.0.1');
var_dump($x);
// int(-1062731775)

var_dump(long2ip($x));
// string(11) 192.168.0.1

var_dump(long2ip(abs($x)));
//string(13) 63.87.255.255

var_dump(sprintf('%u', $x));
// string(10) 3232235521

var_dump((float) sprintf('%u', $x));
// float(3232235521)

var_dump(pack('L', $x));
// binary value, machine-dependent byte order

var_dump(pack('N', $x));
// binary value, big-endian

var_dump(pack('V', $x));
// binary value, little-endian

var_dump(dechex($x));
// string(8) c0a80001

?

I'm not sure how any of these are best passed along to various
databases, though. I believe something like this should work, as long
as the column defined with a type that will hold the positive value,
such as BIGINT (or, perhaps INT(10) UNSIGNED in MySQL, though I think
I remember having issues with that type).

$sql = sprintf('INSERT INTO `mytable` (`ip_address`) VALUES (%u)',
ip2long($ip));


I do most of my development with SQL Server, so I often just pass the
value as a 4-byte integer (or sometimes even in dotted notation) to a
stored procedure and then let T-SQL do the work.


Andrew

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



Re: [PHP] curl help or other suggestion

2010-06-17 Thread Andrew Ballard
On Thu, Jun 17, 2010 at 9:05 AM, Michael Alaimo mala...@sesda2.com wrote:
 I am trying to use register_shutdown_function.  Previous to the script
 shutting down I use curl to grab a website.

 Basically I want to know if the user has hit the stop button or left the
 page prematurely.

 The only problem is that curl runs and finishes its call before the
 shutdown function is called.  Because of this I  have no way to know if
 the user canceled the request somehow.  Any suggestions?

 Mike

I don't know that it will affect cURL, but if you are just looking to
log completed versus abandoned requests, this might help:

http://www.php.net/manual/en/function.ignore-user-abort.php

Andrew

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



Re: [PHP] SQL Syntax

2010-06-16 Thread Andrew Ballard
On Tue, Jun 15, 2010 at 8:58 PM, Jan Reiter the-fal...@gmx.net wrote:
 Hi folks!

 I'm kind of ashamed to ask a question, as I haven't followed this list very
 much lately.

 This isn't exactly a PHP question, but since mysql is the most popular
 database engine used with php, I figured someone here might have an idea.

 I have 2 tables. Table A containing 2 fields. A user ID and a picture ID =
 A(uid,pid) and another table B, containing 3 fields. The picture ID, an
 attribute ID and a value for that attribute = B(pid,aid,value).

 Table B contains several rows for a single PID with various AIDs and values.
 Each AID is unique to a PID.  (e.g. AID = 1 always holding the value for the
 image size and AID = 3 always holding a value for the image type)

This is known as an EAV (Entity-Attribute-Value) design. It is usually
(some would say always) a very bad idea to implement this in a
relational database. and this is no exception.

 The goal is now to join table A on table B using pid, and selecting the rows
 based on MULTIPLE  attributes.

 So the result should only contain rows for images, that relate to an
 attribute ID = 1 (size) that is bigger than 100 AND!!! an attribute ID =
 5 that equals 'jpg'.

 I know that there is an easy solution to this, doing it in one query and I
 have the feeling, that I can almost touch it with my fingertips in my mind,
 but I can't go that final step, if you know what I mean. AND THAT DRIVES ME
 CRAZY!!

The easy solution is to redesign the tables. There are a lot of
reasons why this design is usually a very bad idea. For starters, what
should be a simple query is anything but simple, as you have just
discovered. What's more, there is no simple way (if any way at all)
for your design to prevent an image from having a mime-type of 20174
or a size of 'jpg'.

Andrew

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



Re: [PHP] DOMDocument::loadXML() failed when parsing comments inside a script tag

2010-06-08 Thread Andrew Ballard
On Tue, Jun 8, 2010 at 2:50 AM, Raymond Irving xwis...@gmail.com wrote:
 Well it actually failed when loadHTML() is used.
 The strange thing is that it will fail regardless of the -- characters:

 Unexpected end tag : strong in Entity

 __
 Raymond Irving

What failed? I copied your example and pasted it into a new file in
Zend Studio and it ran without any errors or warnings when I changed
loadXML to loadHTML. It WILL fail if you use loadXML unless the
contents of the script are properly enclosed in a CDATA section
because a script tag has no meaning in regular XML.

I don't know if you have control over the XHTML code or not, but if
you want to use loadXML for the document in your example, it should
look like this, based on what I have read on the web:

?php
$html = '
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html
   body
   script type=text/javascript
   // ![CDATA[
   var i = 0, html = strongBold Text/strong,Normal Text;
   document.write(html);
   i--; // this line causes the parser to fail
   alert(html);
   // ]]
   /script
   /body
/html';
$dom = new DOMDocument();
$dom-loadXML($html);
echo $dom-saveHTML();
?

Andrew

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



Re: [PHP] DOMDocument::loadXML() failed when parsing comments inside a script tag

2010-06-07 Thread Andrew Ballard
On Mon, Jun 7, 2010 at 3:30 PM, Raymond Irving xwis...@gmail.com wrote:
 Hi Adam,

 Thanks for the update but I'm thinking that it would be much easier if the
 DOM parser could just ignore the contents of the script tags when parsing
 HTML content. This way we would not have to out JavaScript or force uses to
 add JavaScript to a separate file.

 What do you think?

 __
 Raymond Irving

You didn't tell it to open the contents as HTML; you told it to open
the contents as XML.

Andrew

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



Re: [PHP] opening a link in a new window

2010-05-15 Thread Andrew Ballard
 On Fri, May 14, 2010 at 8:59 AM, Andrew Ballard aball...@gmail.com wrote:

  This also has the side effect that the decision of whether to open a
  link in the current window or a new window/tab belongs to the viewer
  instead of the author, which some argue is exactly as it should be.
 
  Andrew

On Fri, May 14, 2010 at 4:49 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 There are still valid reasons to use it. On my own site for example, and
 links which lead outside of my site open up in a new tab/window. I link
 to a lot of other external sites often in my blog entries, and I think
 it's valid that these links open up in new tabs/windows so that my site
 is left open when they read the rest of the article.

 I guess I could add some form of indication that the link will open up
 in a new window though.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk

Obviously it is up to you as the site author, but then that was part
of the point I was trying to make above. Authors frequently make links
to external material open in a new window because they don't want
the user to navigate away from their own site. However, there are many
who would argue that the target of a link is a decision that belongs
to the viewer. In most browsers, one has the choice with any regular
link to either click it and open it in the same window/frame as the
referring document, or open the context menu (right-click, etc.) for
the link and open it in a new tab/window. If the site author specifies
target=_blank, the author has removed one of those options from the
viewer. I get annoyed by sites that use
href=javascript:window.open('someurl') specifically because it
prevents me from choosing to open the link in a new tab.

Besides, as Adam said, more and more web browsing is being done on
mobile devices and other platforms that don't support multiple
windows. In these environments, the idea of a link target no longer
has meaning.

For what it's worth, here is a sample page that shows one way to
address the OP's question of duplicating the functionality of target
on links while still being valid XHTML. And yeah ... I know someone
will blast me for how much code it took to duplicate a simple
target=_blank attribute. :-) I didn't test it extensively (just
tried it in Firefox and IE7) but I believe it degrades pretty well, it
simulates target pretty closely, and it validates.

http://pastebin.com/Q3MrWBKi


Andrew

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



Re: [PHP] opening a link in a new window

2010-05-14 Thread Andrew Ballard
On Thu, May 13, 2010 at 5:18 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Thu, 2010-05-13 at 17:13 -0400, David Mehler wrote:

 Hello,
 I want to open an external link in a new window, i know i can do this
 with xhtml, but only with the transitional dtd, which i'm not using. I
 was wondering if php could pull this off?
 Thanks.
 Dave.



 No. PHP is on the server, not the client-side. If you can't use
 something like target=_blank in your xhtml, then consider using
 Javascript. It's not the ideal solution, as it won't work where
 scripting is disabled or not available.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk

It may or may not be the ideal solution, but I'm pretty sure it is
considered the correct solution going forward. I recall reading
somewhere that things like controlling the target for a link are
considered behavior rather than part of the document's semantic
structure, and therefore belong in scripting rather than markup under
XHTML. That makes sense given that one of the goals of XHTML is
structured documents that can be consumed by multiple services,
including but not exclusively web browsers.

This also has the side effect that the decision of whether to open a
link in the current window or a new window/tab belongs to the viewer
instead of the author, which some argue is exactly as it should be.

Andrew

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



Re: [PHP] Append Dom Document

2010-05-14 Thread Andrew Ballard
On Thu, May 13, 2010 at 7:46 PM, Alice Wei aj...@alumni.iu.edu wrote:

 Hi,

  I am trying to create a news feed page that loads a number of different 
 feeds depending on what options the user selects. For some reason, I could 
 not figure out how to get the dom document to append the different xml 
 documents that get created.

 Below is the code, and obviously now every time when I try to have a new item 
 selected, then it displays that element's

 ?php

 $q=$_GET[q];
 $q2 = explode( ,$q);
 $count = count($q2);

 for($i=0;$i$count;$i++) {

 //find out which feed was selected
  switch ($q2[$i]) {
    case Weather:
        
 $xml=(http://rss.weather.com/rss/national/rss_nwf_rss.xml?cm_ven=NWFcm_cat=rsspar=NWF_rss;);
        break;

    case NFL:
      $xml = (http://www.nfl.com/rss/rsslanding?searchString=home;);
      break;

    default:
        exit;
        break;
   }
 }

 $xmlDoc = new DOMDocument();
 $xmlDoc-load($xml);

 //get and output item elements
 $x=$xmlDoc-getElementsByTagName('item');
 for ($i=0; $i=4; $i++)
  {
  $item_title=$x-item($i)-getElementsByTagName('title')
  -item(0)-childNodes-item(0)-nodeValue;
  $item_link=$x-item($i)-getElementsByTagName('link')
  -item(0)-childNodes-item(0)-nodeValue;
  $item_desc=$x-item($i)-getElementsByTagName('description')
  -item(0)-childNodes-item(0)-nodeValue;

  echo (pa href=' . $item_link
  . ' . $item_title . /a);
  echo (br /);
  echo ($item_desc . /p);
  }

 ?


 Is there such a function where I could allow my dom document here append and 
 not have to create a new one every time when a new selection is made?

 Thanks for your help.

 Alice


First, I don't see where you need to append anything. Your code simply
opens XML documents that you fetch from remote sources and iterates
through the nodes in each document to echo links to the articles. If
that's all you need, what you have looks like it will work just fine.

If you are concerned about the overhead of creating a new DOMDocument
each time through the loop, you could move that step outside the loop.
Every time you run $xmlDoc-load($xml) it will replace the existing
contents with the new contents. However, I suspect that instantiating
a new object is fairly cheap compared to the rest of the actions in
your loop, so I doubt you'll save much.

As for your original question, if you really need to append multiple
XML documents into a single document using DOM, you would need to
create a DOMDocument outside the loop that contains your aggregator's
information in the header and that will contain the aggregated items.
Then inside your loop you would still load each feed into a separate
DOMDocument instance just as you are now and import the nodes from the
rss feed into your aggregated document.

Andrew

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



Re: [PHP] Append Dom Document

2010-05-14 Thread Andrew Ballard
On Fri, May 14, 2010 at 12:04 AM, Nathan Nobbe quickshif...@gmail.com wrote:
[snip]
 having said that if you wanted to append
 a new DOMNode to an existing one, you would use the appendChild() method.

Usually, yes. In this case, since she would be importing nodes from
one document into another document, she would need to use importNode()
instead of appendChild().

Andrew

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



Re: [PHP] Multiple Login in a single PC should not be possible

2010-05-14 Thread Andrew Ballard
On Fri, May 14, 2010 at 3:18 AM, Jagdeep Singh jagsaini1...@gmail.com wrote:
 Hi All!

 I am looking for a solution, I want a user to do a single Login only on a PC
 .

 E.g. If a User has logged on my website website.com in Internet explorer,
 then he cant login on same website in another browser like Firefox etc with
 same loginid or another.

 Can I trace MAC address of a single machine to solve this issue?

 Or is there a concept of GLOBAL COOKIE / Cross Browser Cookie which will
 work for all browsers in a single machine..

 I hope You will help me out


 Regards

 Jagdeep Singh

I usually store the sessions in a database table that includes a
column for the user identity (username, e-mail address, etc.) and then
simply log out any previous active sessions any time a new session
logs in by deleting (or marking inactive) any rows for the same
identity whose session_id does not match the current session_id. That
ensures that users can have no more than one active session at a time.

Andrew

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



Re: [PHP] Append Dom Document

2010-05-14 Thread Andrew Ballard
On Fri, May 14, 2010 at 1:14 PM, Alice Wei aj...@alumni.iu.edu wrote:

 Hi,

   You are right about the fact I am not having multiple documents, and yet 
 what I am trying to do here is to have one xmldoc, which I have declared in 
 my original email, and have my other rss feeds that I am trying to call from 
 the PHP to append as I check more checkboxes from the list.

   Right now, when I check one box, it does present it the way I want it, 
 which is open a new xmldoc, and print out the rss feed. Yet, when I try to 
 check the second box, it gives me the display of the rss feed from the second 
 and not the first, because the second one opens a new xmldoc. However, I 
 would like to see both docs in one screen, which is why I want to know if 
 there is such a function available.

   Is what I am trying to do here possibly by any chance?
   Thanks for your help.

 Alice



Just move all of your DOMDocument code block inside the loop after the switch.

?php

$q=$_GET[q];
$q2 = explode( ,$q);
$count = count($q2);

for($i=0;$i$count;$i++) {

//find out which feed was selected
switch ($q2[$i]) {
   case Weather:
   
$xml=(http://rss.weather.com/rss/national/rss_nwf_rss.xml?cm_ven=NWFcm_cat=rsspar=NWF_rss;);
   break;

   case NFL:
 $xml = (http://www.nfl.com/rss/rsslanding?searchString=home;);
 break;

   default:
   exit;
   break;
}

$xmlDoc = new DOMDocument();
$xmlDoc-load($xml);

//get and output item elements
$x=$xmlDoc-getElementsByTagName('item');
for ($i=0; $i=4; $i++)
{
$item_title=$x-item($i)-getElementsByTagName('title')
-item(0)-childNodes-item(0)-nodeValue;
$item_link=$x-item($i)-getElementsByTagName('link')
-item(0)-childNodes-item(0)-nodeValue;
$item_desc=$x-item($i)-getElementsByTagName('description')
-item(0)-childNodes-item(0)-nodeValue;

echo (pa href=' . $item_link . ' . $item_title . /a);
echo (br /);
echo ($item_desc . /p);
}

}

?

Andrew

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



Re: [PHP] Error handling strategies (db related)

2010-04-27 Thread Andrew Ballard
On Tue, Apr 27, 2010 at 12:23 PM, tedd tedd.sperl...@gmail.com wrote:
 At 4:23 PM +0100 4/27/10, Nathan Rixham wrote:

 I'm still shocked you guys are still writing code that has errors in it,
 what's worse is you know about the errors, and instead of fixing them
 you're just telling the user about it!

 :p

 Here's my code that doesn't contain errors:

 ?php

 ?

 Cheers,

 ted

 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Watch out for that new warning message:

br /
bWarning/b:  Deadbeat script. Your code does not do anything
useful in bteddscript.php/b on line b1/bbr /


:-)

Andrew

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



  1   2   3   4   5   6   7   8   9   10   >