Re: [PHP] Is there a PHP based authentication library?
Hi Bastien, That is indeed getting very close to what i was looking for. Thanks a lot! On Tue, Apr 2, 2013 at 9:46 PM, Bastien wrote: > Check out > http://philsturgeon.co.uk/blog/2011/09/ninjauth-social-integration-php from > Phil sturgeon. > > Bastien Koert > > On 2013-04-02, at 3:41 PM, Mark wrote: > > Hi Andy, > > To be honest, that's also not what i'm looking for, but might be a > good starting point to extend on. Depends on how you made it :) I cant > promise that i'ill be working on it. I might be for some future > project in my company but it might very well not happen as well. > > On Tue, Apr 2, 2013 at 2:08 AM, Andy McKenzie wrote: > > I started building one at my last job, though it was part of a framework I > > was developing. I knew I was going to need to authenticate against both > > LDAP and old-fashioned database username/md5-password columns. (Ah, legacy > > user databases.) > > > If it would be useful, I could dig out what I had and try to make it into a > > stand-alone set of functions, but I never got further than those two > > options. Basically there was a script that took in a username and password > > from a web form, then looked at a config file to decide which set of the > > sub-functions to use. For a DB, it checked to see if the username and > > hashed password matched a row in the database; for LDAP, it did some > > re-encoding to handle the weird encrypt that our OpenLDAP server used, then > > ran through the process of checking to see if the user actually had that as > > their password. > > > Like I said, let me know if anyone wants to see it... I'm unemployed right > > now, and a project to work on this week (or next... this week is kind of > > busy) might be a good thing. > > > -Andy McKenzie > > > > On Mon, Apr 1, 2013 at 6:49 PM, Mark wrote: > > > On Tue, Apr 2, 2013 at 12:27 AM, Sorin Badea > > wrote: > > Hi Mark, > > I think a simple Google search would be faster. Anyway, an unified way > > for > > 3rd party authentication doesn't exist from my knowledge, but for Persona > > you could use the sample from mozilla github account > > https://github.com/mozilla/browserid-cookbook . > > > Good luck, > > Sorin! > > > > On Tue, Apr 2, 2013 at 12:26 AM, Mark wrote: > > > Hi, > > > I stumbled upon this payment library: http://ci-merchant.org/ which > > abstracts the different payment backends away and exposes a new easy > > to use interface for the app developer to use. Thus making it very > > easy to use different payment providers. > > > I was wondering if something like that is also existing for > > authentication? For example, in authentication you have quite a few > > different ones: > > - Mozilla Persona > > - openid > > - facebook connect > > - google (openid?) > > - use/pass based authentication (a.k.a. the self made version that > > every dev begins with) > > - oauth > > - twitter connect > > - etc... > > > Is there such a library in existence? I'm especially looking for one > > with mozilla persona implemented. > > > Kind regards, > > Mark > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > > Badea Sorin (unu.sorin) > > sorin.bade...@gmail.com > > unu_so...@yahoo.com > > Pagina personala: > > http://badeasorin.com > > > I couldn't find it on google thus i asked in the one place where - if > > it exists - people would probably know. I find it quite surprising > > that a library like this isn't in existence yet. I can imagine tons of > > sites would certainly benefit from having one generic interface to > > use. > > > Anyway, thank you for your pointer and reply. If you (or anyone else) > > finds a lib for this, please don't hesitate to post it in here. :) > > > -- > > 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 > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there a PHP based authentication library?
Hi Andy, To be honest, that's also not what i'm looking for, but might be a good starting point to extend on. Depends on how you made it :) I cant promise that i'ill be working on it. I might be for some future project in my company but it might very well not happen as well. On Tue, Apr 2, 2013 at 2:08 AM, Andy McKenzie wrote: > I started building one at my last job, though it was part of a framework I > was developing. I knew I was going to need to authenticate against both > LDAP and old-fashioned database username/md5-password columns. (Ah, legacy > user databases.) > > If it would be useful, I could dig out what I had and try to make it into a > stand-alone set of functions, but I never got further than those two > options. Basically there was a script that took in a username and password > from a web form, then looked at a config file to decide which set of the > sub-functions to use. For a DB, it checked to see if the username and > hashed password matched a row in the database; for LDAP, it did some > re-encoding to handle the weird encrypt that our OpenLDAP server used, then > ran through the process of checking to see if the user actually had that as > their password. > > Like I said, let me know if anyone wants to see it... I'm unemployed right > now, and a project to work on this week (or next... this week is kind of > busy) might be a good thing. > > -Andy McKenzie > > > On Mon, Apr 1, 2013 at 6:49 PM, Mark wrote: > >> On Tue, Apr 2, 2013 at 12:27 AM, Sorin Badea >> wrote: >> > Hi Mark, >> > I think a simple Google search would be faster. Anyway, an unified way >> for >> > 3rd party authentication doesn't exist from my knowledge, but for Persona >> > you could use the sample from mozilla github account >> > https://github.com/mozilla/browserid-cookbook . >> > >> > Good luck, >> > Sorin! >> > >> > >> > On Tue, Apr 2, 2013 at 12:26 AM, Mark wrote: >> >> >> >> Hi, >> >> >> >> I stumbled upon this payment library: http://ci-merchant.org/ which >> >> abstracts the different payment backends away and exposes a new easy >> >> to use interface for the app developer to use. Thus making it very >> >> easy to use different payment providers. >> >> >> >> I was wondering if something like that is also existing for >> >> authentication? For example, in authentication you have quite a few >> >> different ones: >> >> - Mozilla Persona >> >> - openid >> >> - facebook connect >> >> - google (openid?) >> >> - use/pass based authentication (a.k.a. the self made version that >> >> every dev begins with) >> >> - oauth >> >> - twitter connect >> >> - etc... >> >> >> >> Is there such a library in existence? I'm especially looking for one >> >> with mozilla persona implemented. >> >> >> >> Kind regards, >> >> Mark >> >> >> >> -- >> >> PHP General Mailing List (http://www.php.net/) >> >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> > >> > >> > >> > -- >> > Badea Sorin (unu.sorin) >> > sorin.bade...@gmail.com >> > unu_so...@yahoo.com >> > Pagina personala: >> > http://badeasorin.com >> >> I couldn't find it on google thus i asked in the one place where - if >> it exists - people would probably know. I find it quite surprising >> that a library like this isn't in existence yet. I can imagine tons of >> sites would certainly benefit from having one generic interface to >> use. >> >> Anyway, thank you for your pointer and reply. If you (or anyone else) >> finds a lib for this, please don't hesitate to post it in here. :) >> >> -- >> 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
Re: [PHP] Is there a PHP based authentication library?
On Tue, Apr 2, 2013 at 12:27 AM, Sorin Badea wrote: > Hi Mark, > I think a simple Google search would be faster. Anyway, an unified way for > 3rd party authentication doesn't exist from my knowledge, but for Persona > you could use the sample from mozilla github account > https://github.com/mozilla/browserid-cookbook . > > Good luck, > Sorin! > > > On Tue, Apr 2, 2013 at 12:26 AM, Mark wrote: >> >> Hi, >> >> I stumbled upon this payment library: http://ci-merchant.org/ which >> abstracts the different payment backends away and exposes a new easy >> to use interface for the app developer to use. Thus making it very >> easy to use different payment providers. >> >> I was wondering if something like that is also existing for >> authentication? For example, in authentication you have quite a few >> different ones: >> - Mozilla Persona >> - openid >> - facebook connect >> - google (openid?) >> - use/pass based authentication (a.k.a. the self made version that >> every dev begins with) >> - oauth >> - twitter connect >> - etc... >> >> Is there such a library in existence? I'm especially looking for one >> with mozilla persona implemented. >> >> Kind regards, >> Mark >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > > > -- > Badea Sorin (unu.sorin) > sorin.bade...@gmail.com > unu_so...@yahoo.com > Pagina personala: > http://badeasorin.com I couldn't find it on google thus i asked in the one place where - if it exists - people would probably know. I find it quite surprising that a library like this isn't in existence yet. I can imagine tons of sites would certainly benefit from having one generic interface to use. Anyway, thank you for your pointer and reply. If you (or anyone else) finds a lib for this, please don't hesitate to post it in here. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there a PHP based authentication library?
On Tue, Apr 2, 2013 at 12:25 AM, David OBrien wrote: > > > > On Mon, Apr 1, 2013 at 5:26 PM, Mark wrote: >> >> Hi, >> >> I stumbled upon this payment library: http://ci-merchant.org/ which >> abstracts the different payment backends away and exposes a new easy >> to use interface for the app developer to use. Thus making it very >> easy to use different payment providers. >> >> I was wondering if something like that is also existing for >> authentication? For example, in authentication you have quite a few >> different ones: >> - Mozilla Persona >> - openid >> - facebook connect >> - google (openid?) >> - use/pass based authentication (a.k.a. the self made version that >> every dev begins with) >> - oauth >> - twitter connect >> - etc... >> >> Is there such a library in existence? I'm especially looking for one >> with mozilla persona implemented. >> >> Kind regards, >> Mark >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > https://github.com/openid/php-openid That's OpenID only. What i meant is one library with some plugin structure where you can add in a plugin for each authentication method. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Is there a PHP based authentication library?
Hi, I stumbled upon this payment library: http://ci-merchant.org/ which abstracts the different payment backends away and exposes a new easy to use interface for the app developer to use. Thus making it very easy to use different payment providers. I was wondering if something like that is also existing for authentication? For example, in authentication you have quite a few different ones: - Mozilla Persona - openid - facebook connect - google (openid?) - use/pass based authentication (a.k.a. the self made version that every dev begins with) - oauth - twitter connect - etc... Is there such a library in existence? I'm especially looking for one with mozilla persona implemented. Kind regards, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Recommendation request: Use Magento or build my own eCommerce?
On Mon, Oct 22, 2012 at 4:51 PM, Marc Guay wrote: > Why not just use the entire OpenCart package? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Well, i was basing my choice of Magento on the "internet opinion" and magento seems the most popular system out there to use with most of the required extensions already there. OpenCart doesn't seem to be as recommended as Magento.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Recommendation request: Use Magento or build my own eCommerce?
On Mon, Oct 22, 2012 at 4:06 PM, Mark wrote: > > Hi, > > I'm in a difficult situation here. I have a list of requirements for an > eCommerce system (Magento) where i'm getting mixed opinions about what to do. > Note: i do consider myself to be a quite experienced PHP programmer and > certainly have the skills to either make the extensions or make everything > from scratch. Both do require month of work! First - for the complete picture > - the list of requirements for the eCommerce system: > - (buld into magento) Multishop has to be possible > - Different payment modules have to be possible (buckaroo, afterpay, ...) > - Online chat (with for example zopim) has to be possible > - Advanced product permissions (magento only has "manage" not more specific > as in "edit") > - Setting pruduct margins > - Abandoned cart alerts > - One page checkout > - Some javascript/ajax things like "instant cart" > - A very specific order page (the "Booking and Reservations" plugin can do > that) > > Thus far it's all oke. However, if i go to the magento irc channel i'm > getting really mixed opinions about what to use and what to create myself. > They basically say that i should prevent installing as much extensions as > possible and try to make most of the things myself. This is where i'm getting > really confused. > > There are two possible routes to take here. > 1. I can go for the magento route and just take the very steep learning curve > it has. It will be a slow process to make the modules required (mainly the > advanced permissions, setting product margins and a abandoned cart > extension). Two of those three are very difficult to make. Certainly if you > consider that i'm just starting developing in any eCommerce system. > > 2. Considering the steep learning curve of making extensions for Magento it > might be easier - in the long run - to build it all myself. In the beginning > that will be an even slower process then using Magento, but once the > structure is build it will be a much faster development process for any > extension. > > I know it's usually a bad thing to reinvent the wheel and i am certainly not > intending that. However, right now i really get the impression that i'm > better of making it all myself. Both approaches take many months of > development where the self made version is going to pay off in development > time in the long run when compared to magento. I am just not sure what the > best solution might be. > > So here is a list of pros and cons that i can think of for both approaches. > > Pros/Cons for using magento > - [pro] a lot of existing extensions > - [pro] i don't need to worry about security updates since the come from > magento > - [pro] living community around it to help out if there are any issues > - [con] very steep learning curve > - [con] not straightforward to start developing in > - [con] takes a lot of time till you can even use the basics > > Pros/Cons for self made > - [pro] Development will go a lot faster > - [pro] i can make it more specific for one goal > - [pro] a much easier extension model > - [con] security all depends on me > - [con] i have to make complicated extensions like buckaroo and afterpay > myself > - [con] no existing library of extensions to use > > Again, i'm puzzled by this. If i follow the #magento (on freenode) list then > i should pick magento, but make every extension myself or only use the really > good ones. Thus that will require a lot of time to develop them. I 'm > guessing about half a year. Then again, if i make it all from the ground up > it's probably also going to take half a year to develop (or slightly more) > but it will obviously be much easier to maintain since i know every single > line of it. > > What is your recommendation? Build it myself? Use Magento? or another option > that i didn't even consider yet? > > Kind regards, > Mark Something i made up just now. Would it work if i make the ecommerce system myself and build OpenCart support in it so that OpenCart extensions can be installed in my oscommerce as well? Since then i wouldn't have to bother about payment modules. Though it does add a very complex translation layer from "my to be build oscommerce" to the OpenCart system... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Recommendation request: Use Magento or build my own eCommerce?
Hi, I'm in a difficult situation here. I have a list of requirements for an eCommerce system (Magento) where i'm getting mixed opinions about what to do. Note: i do consider myself to be a quite experienced PHP programmer and certainly have the skills to either make the extensions or make everything from scratch. Both do require month of work! First - for the complete picture - the list of requirements for the eCommerce system: - (buld into magento) Multishop has to be possible - Different payment modules have to be possible (buckaroo, afterpay, ...) - Online chat (with for example zopim) has to be possible - Advanced product permissions (magento only has "manage" not more specific as in "edit") - Setting pruduct margins - Abandoned cart alerts - One page checkout - Some javascript/ajax things like "instant cart" - A very specific order page (the "Booking and Reservations" plugin can do that) Thus far it's all oke. However, if i go to the magento irc channel i'm getting really mixed opinions about what to use and what to create myself. They basically say that i should prevent installing as much extensions as possible and try to make most of the things myself. This is where i'm getting really confused. There are two possible routes to take here. 1. I can go for the magento route and just take the very steep learning curve it has. It will be a slow process to make the modules required (mainly the advanced permissions, setting product margins and a abandoned cart extension). Two of those three are very difficult to make. Certainly if you consider that i'm just starting developing in any eCommerce system. 2. Considering the steep learning curve of making extensions for Magento it might be easier - in the long run - to build it all myself. In the beginning that will be an even slower process then using Magento, but once the structure is build it will be a much faster development process for any extension. I know it's usually a bad thing to reinvent the wheel and i am certainly not intending that. However, right now i really get the impression that i'm better of making it all myself. Both approaches take many months of development where the self made version is going to pay off in development time in the long run when compared to magento. I am just not sure what the best solution might be. So here is a list of pros and cons that i can think of for both approaches. Pros/Cons for using magento - [pro] a lot of existing extensions - [pro] i don't need to worry about security updates since the come from magento - [pro] living community around it to help out if there are any issues - [con] very steep learning curve - [con] not straightforward to start developing in - [con] takes a lot of time till you can even use the basics Pros/Cons for self made - [pro] Development will go a lot faster - [pro] i can make it more specific for one goal - [pro] a much easier extension model - [con] security all depends on me - [con] i have to make complicated extensions like buckaroo and afterpay myself - [con] no existing library of extensions to use Again, i'm puzzled by this. If i follow the #magento (on freenode) list then i should pick magento, but make every extension myself or only use the really good ones. Thus that will require a lot of time to develop them. I 'm guessing about half a year. Then again, if i make it all from the ground up it's probably also going to take half a year to develop (or slightly more) but it will obviously be much easier to maintain since i know every single line of it. What is your recommendation? Build it myself? Use Magento? or another option that i didn't even consider yet? Kind regards, Mark
Re: [PHP] What's the best way to make a dynamic plugin architecture?
On Tue, Aug 28, 2012 at 1:43 PM, Matijn Woudt wrote: > On Tue, Aug 28, 2012 at 1:16 AM, Larry Garfield > wrote: >> On 8/27/12 6:11 PM, Matijn Woudt wrote: >> You should never be calling require() yourself. Just follow the PSR-0 naming standard and use an autoloader, then you don't have to even think about it. There are many existing autoloaders you can use, including Composer's, Symfony2's, and probably Zend has one as well. >>> >>> I believe there's one in PHP by default now called SPLClassLoader or >>> something like that.. >>> >>> - Matijn >> >> >> There was a proposal for one, but it was never added. You still need a >> user-space class loader for PSR-0, but they're readily available. >> >> >> --Larry Garfield >> > > Ah thanks for the info. I heard about it way back and assumed it was > implemented by now ;) > > - Matijn > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > I did some searching on that one since it sounds interesting. It's laying dormant in bugzilla: https://bugs.php.net/bug.php?id=60128 (the RFC : https://wiki.php.net/rfc/splclassloader) Thanks for the advice so far. I will certainly implement Autoloading. Why didn't i think of that :p Guess my PHP knowledge is a bit rusty since i did make autoloaders before. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What's the best way to make a dynamic plugin architecture?
On Mon, Aug 27, 2012 at 4:26 PM, Stuart Dallas wrote: > On 27 Aug 2012, at 14:52, Mark wrote: > >> On Mon, Aug 27, 2012 at 3:46 PM, Stuart Dallas wrote: >>> On 27 Aug 2012, at 14:29, Mark wrote: >>> >>>> On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas wrote: >>>>> On 26 Aug 2012, at 19:42, Mark wrote: >>>>> >>>>>> 2. Let the plugin itself (so in this case PluginOne.php) open itself >>>>>> and register it to the PluginLoader. >>>>>> >>>>>> With the first option i have to do eval which i try to avoid if possible. >>>>>> With the second solution the PluginLoader probably has to be a >>>>>> singlethon. >>>>> >>>>> Why does it need to be a singleton? >>>> >>>> Well, i would then do something like this from within the included >>>> plugin file after the class: >>>> PluginLoader::getInstance()->registerPlugin(new PluginOne()); >>>> >>>> Or something alike. >>> >>> I'm not sure I see what PluginLoader is doing? It makes more sense to me if >>> you register like so: >>> >>> PluginLoader::getInstance()->registerPlugin('PluginOne'); >>> >>> Then you get an instance of the plugin: >>> >>> $plugin = PluginLoader::getInstance()->factory('PluginOne'); >>> >>> Tho, even then I don't see what the PluginLoader is adding to the party. >> >> Well, i'm making the classes up as i type. I don't actually have a >> PluginLoader yet. Or rather, i'm just beginning to make it right now. >> What it's doing is very simple. Read through the directory of the >> plugins and load every single plugin it finds in memory. Then every >> plugin registers the mime types it can handle. That information is >> stored in the PluginLoader upon which some other place can call: >> PluginLoader::pluginForMime("text/html"). Though i still have to take >> a good look at that. >> >> But you're right, i can use the factory pattern here. > > > Ahh, I see. Personally I'd go with the following (pseudocode)... > > Inside the PluginLoader constructor (or other method) > foreach (plugindir) > require plugindir/plugindir.php > $plugindir::init($this) > > The static init() method calls PluginLoader::registerPlugin('mime/type', > 'PluginClassName'). Then pluginForMime does a lookup for the mime type and > returns an object of the corresponding type. That way a single plugin can > support multiple mime types. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ That sounds sane and i probably go for that :) Thanks for clarifying it a little. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What's the best way to make a dynamic plugin architecture?
On Mon, Aug 27, 2012 at 3:46 PM, Stuart Dallas wrote: > On 27 Aug 2012, at 14:29, Mark wrote: > >> On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas wrote: >>> On 26 Aug 2012, at 19:42, Mark wrote: >>> >>>> 2. Let the plugin itself (so in this case PluginOne.php) open itself >>>> and register it to the PluginLoader. >>>> >>>> With the first option i have to do eval which i try to avoid if possible. >>>> With the second solution the PluginLoader probably has to be a singlethon. >>> >>> Why does it need to be a singleton? >> >> Well, i would then do something like this from within the included >> plugin file after the class: >> PluginLoader::getInstance()->registerPlugin(new PluginOne()); >> >> Or something alike. > > I'm not sure I see what PluginLoader is doing? It makes more sense to me if > you register like so: > > PluginLoader::getInstance()->registerPlugin('PluginOne'); > > Then you get an instance of the plugin: > > $plugin = PluginLoader::getInstance()->factory('PluginOne'); > > Tho, even then I don't see what the PluginLoader is adding to the party. Well, i'm making the classes up as i type. I don't actually have a PluginLoader yet. Or rather, i'm just beginning to make it right now. What it's doing is very simple. Read through the directory of the plugins and load every single plugin it finds in memory. Then every plugin registers the mime types it can handle. That information is stored in the PluginLoader upon which some other place can call: PluginLoader::pluginForMime("text/html"). Though i still have to take a good look at that. But you're right, i can use the factory pattern here. > >> Thank you for your advice, really appreciated. > > > No probs. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What's the best way to make a dynamic plugin architecture?
On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas wrote: > On 26 Aug 2012, at 19:42, Mark wrote: > >> Envision the following plugin architecture: >> >> class PluginLoader >> { >> } >> >> interface PluginInterface >> { >> .. some function definitions .. >> } >> >> class PluginOne implements PluginInterface >> { >> } >> >> class PluginTwo implements PluginInterface >> { >> } >> >> The PluginLoader is loading the plugins. >> The PluginInterface defines an interface which each plugin has to implement. >> PluginOne and PluginTwo are plugins that implement the interface. >> >> Each plugin (PluginOne and PluginTwo) are stored in their own folders. >> So the folder structure would be somewhat like this: >> |- Plugins >> |- - PluginOne >> |- - - PluginOne.php >> |- - - other possible files >> |- - PluginTwo >> |- - - PluginTwo.php >> |- - - other possible files >> |- PluginLoader.php >> |- PluginInterface.php >> >> Now making this structure isn't an issue. I can do all of that just >> fine. The place where i'm actually going to make a plugin instance is >> where things get a little more complicated. The PluginLoader simply >> reads all the dirs in the Plugins folder and tries to find a filename >> with the same dir. So if it reads the dir Plugins/PluginOne it will >> try to include the PHP file: Plugins/PluginOne/PluginOne.php. That's >> fine and working. >> >> To actually make a plugin instance i can do two things that i know of: >> 1. use eval like so: eval('$obj = new '.$pluginName.'();'); and >> register it to the PluginLoader. > > No need to use eval, you can simply do this: > > $obj = new $pluginName(); > > See here: http://php.net/language.variables.variable Ahh right, i completely forgot about that option. That might just work the way i want it :) > >> 2. Let the plugin itself (so in this case PluginOne.php) open itself >> and register it to the PluginLoader. >> >> With the first option i have to do eval which i try to avoid if possible. >> With the second solution the PluginLoader probably has to be a singlethon. > > Why does it need to be a singleton? Well, i would then do something like this from within the included plugin file after the class: PluginLoader::getInstance()->registerPlugin(new PluginOne()); Or something alike. > >> Now my question is: what is the right way of loading plugins like >> this? Is there some other option then the two i described above? My >> PHP limitations are the newest version so no limitation there :) >> I'm kinda leaning towards the second option now since that seems to be >> quite stable and not very error prone. The eval one is much easier to >> break :p > > If you're happy for each plugin to be in a separate directory then what you > have in option 1, minus the eval, will work perfectly well. I don't know what > your use case is but if there's a chance a single plugin might want to > provide several classes then I'd require an init.php in each plugin folder > and have that register the class names with the class loader. It could also > then pass along some meta information such as a description of what each > class does. If this is for use in web requests you might want to stick to > what you currently have as there's a lot less overhead. Yeah, if i extend it more that will certainly be an requirement. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ Thank you for your advice, really appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] What's the best way to make a dynamic plugin architecture?
Hi, Envision the following plugin architecture: class PluginLoader { } interface PluginInterface { .. some function definitions .. } class PluginOne implements PluginInterface { } class PluginTwo implements PluginInterface { } The PluginLoader is loading the plugins. The PluginInterface defines an interface which each plugin has to implement. PluginOne and PluginTwo are plugins that implement the interface. Each plugin (PluginOne and PluginTwo) are stored in their own folders. So the folder structure would be somewhat like this: |- Plugins |- - PluginOne |- - - PluginOne.php |- - - other possible files |- - PluginTwo |- - - PluginTwo.php |- - - other possible files |- PluginLoader.php |- PluginInterface.php Now making this structure isn't an issue. I can do all of that just fine. The place where i'm actually going to make a plugin instance is where things get a little more complicated. The PluginLoader simply reads all the dirs in the Plugins folder and tries to find a filename with the same dir. So if it reads the dir Plugins/PluginOne it will try to include the PHP file: Plugins/PluginOne/PluginOne.php. That's fine and working. To actually make a plugin instance i can do two things that i know of: 1. use eval like so: eval('$obj = new '.$pluginName.'();'); and register it to the PluginLoader. 2. Let the plugin itself (so in this case PluginOne.php) open itself and register it to the PluginLoader. With the first option i have to do eval which i try to avoid if possible. With the second solution the PluginLoader probably has to be a singlethon. Now my question is: what is the right way of loading plugins like this? Is there some other option then the two i described above? My PHP limitations are the newest version so no limitation there :) I'm kinda leaning towards the second option now since that seems to be quite stable and not very error prone. The eval one is much easier to break :p Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] If PHP Were British
On 22/06/2012 22:07, Daevid Vincent wrote: > http://www.addedbytes.com/blog/if-php-were-british/ LOL! -- Mark Rousell PGP public key: http://www.signal100.com/markr/pgp Key ID: C9C5C162 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers
On 22/05/2012 19:32, Ashley Sheridan wrote: > After that, you have file permissions. In Unix, you have file, owner and > group permissions; Windows has read/write permissions and I believe on > newer versions you can get something similar to what Unix/Linux has had > for the last however many years but I'm not 100% sure on that one. Just to clarify on this point, Windows (or rather NTFS) permissions use full ACLs and so, for each file system object, any number of users and/or groups can have any number of allow or deny permissions assigned to them for a range of activities (e.g. read, write, append, delete, create, execute, traverse, read/write attributes, read/write permissions, etc.). There's a good article here that begins to explain it: 'Understanding Windows NTFS Permissions' http://www.windowsecurity.com/articles/Understanding-Windows-NTFS-Permissions.html NTFS ACLs are similar to (not not identical to) Posix Access Control Lists that are available for Linux and Unixes. -- MarkR PGP public key: http://www.signal100.com/markr/pgp Key ID: C9C5C162 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Differences between PHP on LAMP and PHP on Windows Servers
On 22/05/2012 19:15, Gates, Jeff wrote: > Can anyone tell me what differences I might encounter by working with PHP on > a Unix server verses working with PHP on a Windows server. We use Windows > production servers here but many of us would like to get more LAMP > environments. > > So, I'm wondering if I can use the hive mind here to get a sense of the pros > and cons of each platform. > > Thanks. > > Jeff In addition to Ashley's response, server variables can be populated with different values on PHP/Apache/Linux versus PHP/IIS/Windows. This can be a particular issue if you're writing 404 handlers or anything that relies on query strings. In particular you need to test and check for differences between Apache and IIS in how the REQUEST_URI, QUERY_STRING, URL, and ORIG_PATH_INFO variables are populated depending on whether your script is being called directly or as a 404 handler. When redirecting due to a 404 or some other redirect or error IIS will populate some variables with values like this "/404.php?404;http://www.server.com:80/blah.php?v=1&t=2"; whereas Apache will populate the same variable with "/blah.php?v=1&t=2" in the same situation. This means the query string needs to be parsed differently. You need to test for your own usage scenarios. -- MarkR PGP public key: http://www.signal100.com/markr/pgp Key ID: C9C5C162 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Howto detect the hostname of the server?
Hi. On Saturday 26 Nov 2011 at 00:14 Andreas wrote: > how could I identify the server the script runs on? [snip] > I looked into phpinfo() but haven't found anything helpful, yet. > Have I overlooked something or is there another way to identify the server? Wouldn't the server IP address in $_SERVER['SERVER_ADDR'] or the hostname in $_SERVER['SERVER_NAME'] do the trick? That's what I use. The second one is handy for differentiating between sites when using Apache name-based virtual hosts on the same IP. Full list here: http://uk.php.net/manual/en/reserved.variables.server.php Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Secure data management
Hi. On Wednesday 05 Oct 2011 at 00:04 Mark Kelly wrote: > I'd be interested in any ideas folk have about these issues, or any others > they can envisage with this proposal. Thank you all for joining in here - it's been a fascinating read so far. Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Secure data management
Hi. On Tuesday 04 Oct 2011 at 21:39 Stuart Dallas wrote: > http://stut.net/2011/09/15/mysql-real-escape-string-is-not-enough/ Thanks. I followed this link through and read the full message (having missed it the first time round), and while I find the idea of using base64 to sanitise text interesting I can also forsee a few difficulties: It would prevent anyone from accessing the database directly and getting meaningful results unless the en/decode is in triggers, or maybe stored procedures. No more one-off command-line queries. How would you search an encoded column for matching text? I'd be interested in any ideas folk have about these issues, or any others they can envisage with this proposal. Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Object Query Language optimization
Hi. On Saturday 21 May 2011 at 15:56 jean-baptiste verrey wrote: > I'm writing an Object Query Language [snip] > (queries don't get much more complicated than that, you have multiple > alias.fieldName in the select, then multiple joins) I often use SQL that is far, far more complex than this. Anyway, I can't help directly with the code, other than to suggest that you take a look at other projects that do the same thing and see how they do it. There's a starter list at: http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software#PHP HTH, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: dynamic copyright in page footer?
On Saturday 30 Apr 2011 at 14:28 Nathan Rixham wrote: > echo implode(",", range(2011,date("Y"))); What an elegant solution! Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex for extracting quoted strings
Hi. Thanks for all the replies. On Saturday 05 Mar 2011 at 22:11 Simon J Welsh wrote: > On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote: > > $regex = '/"([^"]+)"/'; Shawn, this regex gets me two copies of each string - one with and one without the double quotes - as did the one Nathan posted earlier. > Also, you'll want preg_match_all rather than preg_match. Yeah, I realised that quite early on in my messing about. What I have ended up with is: $regex = '/".*?"/'; $found = preg_match_all($regex, $sentence, $phrases); This still leaves the quotes in the phrases, but at least I only get one copy of each phrase. I'm just trimming the quotes afterwards. Thanks for all the advice. Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex for extracting quoted strings
Hi. I'm hoping someone can help me extract text between double quotes from a string. $regex = 'some magic'; $r = preg_match($regex, $sentence, $phrases); So, if $sentence = 'Dave said "This is it". "Nope, that is the wrong colour" she replied.'; I want $phrases to contain 'This is it' and 'Nope, that is the wrong colour'. Can anyone help? Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Custom function
Hi. On Wednesday 16 Feb 2011 at 00:49 Simon J Welsh wrote: > As $z is converted to a boolean and exists, that works just the same way as > !empty(). --- First I'd like to apologise for handing out bad advice, and second, to thank Simon and Andre for pointing out my mistake. I'll go back to keeping my mouth shut in future :) Cheers guys, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Custom function
Hi. On Tuesday 15 Feb 2011 at 23:41 Andre Polykanine wrote: > Give it a default (possible empty) value: > > function MyFunction($x, $y, $z="") { > // function goes here > if (!empty($z)) { > // The optional parameter is given > } > } Using an empty string and the empty() function in this way can lead to subtle and hard to find bugs - for example if $z = 0, the code will not be executed. Note the list of things that are considered empty: http://uk.php.net/manual/en/function.empty.php Instead, consider setting the default value for $z to boolean false: function MyFunction ($x, $y, $z = FALSE) { if ($z) { // do stuff with $z } } In this way almost any value in $z will trigger the conditional code, including 0 or an empty string. The exceptions are FALSE and NULL. If you explicitly need to react to a NULL value, use is_null() to detect it. Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Including files on NFS mount slow with APC enabled
Bug reported, see http://pecl.php.net/bugs/bug.php?id=18154 On 08/17/2010 01:13 PM, Colin Guthrie wrote: > I don't know the internals of APC but that smells like a bug to me. > > Can you post the bug number here if you report one? > > Cheers > > Col > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Including files on NFS mount slow with APC enabled
I now notice that when I replace include_once with include the open() call disappears. That's very nice, but why does include_once need to open the file, even when apc.include_once_override is enabled? Is this a bug? On 08/16/2010 03:21 PM, Mark Hunting wrote: > I am struggling with the performance of some websites that use a lot of > includes (using include_once). The files are on a NFS mount (NFSv4), and > I use APC to speed things up. APC has enough memory, and I see all > included files are in the APC cache. apc.include_once_override is > enabled. This is on a Ubuntu Linux 10.04 server. > > What surprises me is that using strace I see apache open()ing all > included files. I would think this is not necessary as APC has these > files in its cache. Opening a file takes 1-3 ms, the websites include > 100-200 files, so this costs about half a second for each request. I > tried a lot to prevent this but my options are exhausted. Is it normal > that all these files are open()ed each time, and if so how can I speed > up these includes? > > Part of the trace is below, look especially at the first line where 2ms > are lost while this file is in the APC cache: > > open("/[removed]/library/Zend/Application.php", O_RDONLY) = 1440 <0.002035> > fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000137> > fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000124> > fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000133> > mmap(NULL, 11365, PROT_READ, MAP_SHARED, 1440, 0) = 0x7faf3f068000 > <0.000395> > stat("/[removed]/library/Zend/Application.php", {st_mode=S_IFREG|0755, > st_size=11365, ...}) = 0 <0.000219> > munmap(0x7faf3f068000, 11365) = 0 <0.000151> > close(1440) = 0 <0.000845> > > Thanks, > Mark > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Including files on NFS mount slow with APC enabled
Thanks for your answer. I have tested this option before, and it indeed disables the stat() operation. However, it doesn't disable the open() operation, which is about 10x slower than the stat() call (see my example trace). On 08/16/2010 07:21 PM, Jonathan Tapicer wrote: > Hi, > > APC checks by default if every included file was modified doing a stat > call. You can disable it, setting apc.stat to 0 > (http://www.php.net/manual/en/apc.configuration.php#ini.apc.stat). Try > if that improves the performance. Of course, you should manually > delete the APC opcode cache every time you modify a PHP file, since > APC won't detect that it was modified. > > Regards, > > Jonathan > > On Mon, Aug 16, 2010 at 10:21 AM, Mark Hunting wrote: > >> I am struggling with the performance of some websites that use a lot of >> includes (using include_once). The files are on a NFS mount (NFSv4), and >> I use APC to speed things up. APC has enough memory, and I see all >> included files are in the APC cache. apc.include_once_override is >> enabled. This is on a Ubuntu Linux 10.04 server. >> >> What surprises me is that using strace I see apache open()ing all >> included files. I would think this is not necessary as APC has these >> files in its cache. Opening a file takes 1-3 ms, the websites include >> 100-200 files, so this costs about half a second for each request. I >> tried a lot to prevent this but my options are exhausted. Is it normal >> that all these files are open()ed each time, and if so how can I speed >> up these includes? >> >> Part of the trace is below, look especially at the first line where 2ms >> are lost while this file is in the APC cache: >> >> open("/[removed]/library/Zend/Application.php", O_RDONLY) = 1440 <0.002035> >> fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000137> >> fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000124> >> fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000133> >> mmap(NULL, 11365, PROT_READ, MAP_SHARED, 1440, 0) = 0x7faf3f068000 >> <0.000395> >> stat("/[removed]/library/Zend/Application.php", {st_mode=S_IFREG|0755, >> st_size=11365, ...}) = 0 <0.000219> >> munmap(0x7faf3f068000, 11365) = 0 <0.000151> >> close(1440) = 0 <0.000845> >> >> Thanks, >> Mark >> >> -- >> 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
[PHP] Including files on NFS mount slow with APC enabled
I am struggling with the performance of some websites that use a lot of includes (using include_once). The files are on a NFS mount (NFSv4), and I use APC to speed things up. APC has enough memory, and I see all included files are in the APC cache. apc.include_once_override is enabled. This is on a Ubuntu Linux 10.04 server. What surprises me is that using strace I see apache open()ing all included files. I would think this is not necessary as APC has these files in its cache. Opening a file takes 1-3 ms, the websites include 100-200 files, so this costs about half a second for each request. I tried a lot to prevent this but my options are exhausted. Is it normal that all these files are open()ed each time, and if so how can I speed up these includes? Part of the trace is below, look especially at the first line where 2ms are lost while this file is in the APC cache: open("/[removed]/library/Zend/Application.php", O_RDONLY) = 1440 <0.002035> fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000137> fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000124> fstat(1440, {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000133> mmap(NULL, 11365, PROT_READ, MAP_SHARED, 1440, 0) = 0x7faf3f068000 <0.000395> stat("/[removed]/library/Zend/Application.php", {st_mode=S_IFREG|0755, st_size=11365, ...}) = 0 <0.000219> munmap(0x7faf3f068000, 11365) = 0 <0.000151> close(1440) = 0 <0.000845> Thanks, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] NetBeans Question
Hi. On Monday 31 May 2010 at 02:50 Ashley Sheridan wrote: > Yeah, like I mentioned earlier, Dreamweaver is known for having issues > with include files, can be slow when working on large projects with lots > of files, and is only available for Mac and Windows, which limits it > somewhat. Indeed. I can't stand the thing myself - I was just being polite :) I use netbeans on Linux and Windows, so its cross-platform nature is quite important to me. I also appreciate the Subversion integration, which is very nicely done. Tedd: I'm no expert, but I'll chime in if I have any answers for you. Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] NetBeans Question
Hi Brandon. You sent your reply directly to me, instead of to the mailing list. Also I don't agree - netbeans is an excellent IDE and to call it a text editor is not doing it justice at all. Cheers, Mark On Monday 31 May 2010 at 02:03 you wrote: > Dreamweaver is better if you want a real IDE. If you want a regular text > editor netbeans is the way to go. > > On Sun, May 30, 2010 at 8:15 PM, Mark Kelly wrote: > > Hi Tedd. > > > > On Sunday 30 May 2010 at 19:01 tedd wrote: > > > I wanted to ask my questions on the NetBeans forums, but I am having > > > trouble logging in. They seem to have a problem with my given ID, > > > password, and email address and I haven't the time to straighten it > > > all out -- I just want answers -- so I turned to this list. > > > > Just in case you didn't spot it, there is a mailing list specifically for > > PHP > > development using netbeans that I have found very useful. You can sign up > > here: > > > > http://netbeans.org/community/lists/top.html#technologies > > > > Cheers, > > > > Mark > > > > -- > > 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
Re: [PHP] NetBeans Question
Hi Tedd. On Sunday 30 May 2010 at 19:01 tedd wrote: > I wanted to ask my questions on the NetBeans forums, but I am having > trouble logging in. They seem to have a problem with my given ID, > password, and email address and I haven't the time to straighten it > all out -- I just want answers -- so I turned to this list. Just in case you didn't spot it, there is a mailing list specifically for PHP development using netbeans that I have found very useful. You can sign up here: http://netbeans.org/community/lists/top.html#technologies Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need login suggestions
Hi. On Monday 03 May 2010 at 03:49 Ashley M. Kirchner wrote: [snip] >So what if a student registers on the wrong side of the wall? Nothing > happens [snip] > Kids would be registering for a > photo contest, parents will be registering for something completely > different. You might try changing the interface to reflect the above - instead of dividing the users into students and parents, give them two nice big buttons to click "Register for Photo Contest" and "Register for This Other Thing". As far as managing the differences in code, when they log in stick $userType (from the database I guess) in the session and check it in every secured page to control who sees what. I've done several variations on this particular theme; it's simple to manage, especially if you have a page initialisation function/method you can put the $userType check into. HTH, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: HipHop and other PHP compiler performance evaluation
Manuel Lemos schreef: FYI http://digg.com/programming/PHP_compiler_performance A nice article, thank you for the information! -- Kind regards, Mark Cilissen / Pixlism -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Login Script: mysql_num_rows(): supplied argument isnot a valid MySQL result resource
Ashley Sheridan schreef: On Fri, 2010-02-19 at 18:30 +0100, Mark Cilissen wrote: David Hutto schreef: --- On Fri, 2/19/10, David Hutto wrote: From: David Hutto Subject: Login Script: mysql_num_rows(): supplied argument is not a valid MySQL result resource To: php-general@lists.php.net Date: Friday, February 19, 2010, 3:30 AM The following script is supposed to validate a username and password in a mysql db. When entering the username and password of a preregistered user, I get the following errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/login.php on line 24 Warning: Cannot modify header information - headers already sent by (output started at /var/www/login.php:24) in /var/www/login.php on line 26 On line 24 is: if(!mysql_num_rows($login)) //if the username and pass are wrong --The supplied argument is $login, which is previously defined as: $login = mysql_query("SELECT * FROM 'userinfo' WHERE `user` = '$user' AND `pass` = '$pass`"); --which is further defined above it as these values: $user = $_POST['user']; //pulls the username from the form $pw = $_POST['pass']; //pulls the pass from the form $pass = md5($pw); //makes our password an md So why is the sum of those previous definitions an invalid argument for the mysql_query() to test for whether the username and md5 password values are true/equivalent to each other? Because basically !mysql_num_rows($login) is just if'ing the lack of a user/pass match, else it continues to set cookie and session variables. If I'm looking at this wrong let me know. Thanks for any help you may be able to provide, below is the full login.php page. David This is the full login.php script, I'm pretty sure no other portions are needed to show at this point for the current problem: Username Password '); } elseif($act == "auth") //if our page action = auth { $user = $_POST['user']; //pulls the username from the form $pw = $_POST['pass']; //pulls the pass from the form $pass = md5($pw); //makes our password an md5 include("connect.php"); //connects to our mysql database $login = mysql_query("SELECT * FROM `userinfo` WHERE `user` = '$user' AND `pass` = '$pass`"); //selects info from our table if the row has the same user and pass that our form does if(!mysql_num_rows($login)) //if the username and pass are wrong { header("Location: login.php"); //redirects to our login page die(); //stops the page from going any further } else { setcookie("user", $user, time()+3600);//sets our user cookie setcookie("pass", $pass, time()+3600);//sets our pass cookie header("Location: memprar.php");//instead of yourpage.php it would be your protected page } } ?> The query should be: SELECT * FROM `userinfo` WHERE `user` = '$user' AND `pass` = '$pass' Remember: ` for tables and columns, ' for strings. Also, look up SQL Injection, as your script contains a huge vulnerability. This can be fixed using mysql_real_escape_string, so it is this: ELECT * FROM `userinfo` WHERE `user` = '".mysql_real_escape_string($user)."' AND `pass` = '".mysql_real_escape_string($pass)."' -- Kind regards, Mark Cilissen / Pixlism I did cover all of those points and give the same sanitisation suggestion in the email I sent to this question earlier! Thanks, Ash http://www.ashleysheridan.co.uk Didn't see it, it was in another thread. -- Kind regards, Mark Cilissen / Pixlism -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Login Script: mysql_num_rows(): supplied argument is not a valid MySQL result resource
David Hutto schreef: --- On Fri, 2/19/10, David Hutto wrote: From: David Hutto Subject: Login Script: mysql_num_rows(): supplied argument is not a valid MySQL result resource To: php-general@lists.php.net Date: Friday, February 19, 2010, 3:30 AM The following script is supposed to validate a username and password in a mysql db. When entering the username and password of a preregistered user, I get the following errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/login.php on line 24 Warning: Cannot modify header information - headers already sent by (output started at /var/www/login.php:24) in /var/www/login.php on line 26 On line 24 is: if(!mysql_num_rows($login)) //if the username and pass are wrong --The supplied argument is $login, which is previously defined as: $login = mysql_query("SELECT * FROM 'userinfo' WHERE `user` = '$user' AND `pass` = '$pass`"); --which is further defined above it as these values: $user = $_POST['user']; //pulls the username from the form $pw = $_POST['pass']; //pulls the pass from the form $pass = md5($pw); //makes our password an md So why is the sum of those previous definitions an invalid argument for the mysql_query() to test for whether the username and md5 password values are true/equivalent to each other? Because basically !mysql_num_rows($login) is just if'ing the lack of a user/pass match, else it continues to set cookie and session variables. If I'm looking at this wrong let me know. Thanks for any help you may be able to provide, below is the full login.php page. David This is the full login.php script, I'm pretty sure no other portions are needed to show at this point for the current problem: Username Password '); } elseif($act == "auth") //if our page action = auth { $user = $_POST['user']; //pulls the username from the form $pw = $_POST['pass']; //pulls the pass from the form $pass = md5($pw); //makes our password an md5 include("connect.php"); //connects to our mysql database $login = mysql_query("SELECT * FROM `userinfo` WHERE `user` = '$user' AND `pass` = '$pass`"); //selects info from our table if the row has the same user and pass that our form does if(!mysql_num_rows($login)) //if the username and pass are wrong { header("Location: login.php"); //redirects to our login page die(); //stops the page from going any further } else { setcookie("user", $user, time()+3600);//sets our user cookie setcookie("pass", $pass, time()+3600);//sets our pass cookie header("Location: memprar.php");//instead of yourpage.php it would be your protected page } } ?> The query should be: SELECT * FROM `userinfo` WHERE `user` = '$user' AND `pass` = '$pass' Remember: ` for tables and columns, ' for strings. Also, look up SQL Injection, as your script contains a huge vulnerability. This can be fixed using mysql_real_escape_string, so it is this: ELECT * FROM `userinfo` WHERE `user` = '".mysql_real_escape_string($user)."' AND `pass` = '".mysql_real_escape_string($pass)."' -- Kind regards, Mark Cilissen / Pixlism -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checking correct usage of fopen(), stream_set_timeout() and fread() [newbie]
Hi, I have some code to download large files as part of a larger class. I've been in a discussion with the developer of a library that I'm using who has told me clearly that my code will not work at all, even though it does. He is suggesting my problems are due to my not understanding the nature of fread() even the code is very similar to examples on php.net. I do get very rare timeout problems where the stream_set_timeout() does not seem to be firing, and PHP exits on a general timeout. However I'm using this under Tomcat and the logs are not giving me as much information as under Apache webserver, where I have been unable to reproduce this problem. So it's proving difficult to track down and I'm not able to reproduce the error consistently. I would appreciate any comments about the validity of the code (at the bottom) so I have a better idea whether it is my problem, or not. It might be that I need to catch and handle the error, but that is an area where I have no experience as yet. I'm aware the code could be rewritten in CURL, but for now I'm more after an understanding of what problems there might be, if any, with this approach. The server is returning content-length in the header, and chunk encoding is not an approach I'm intending to use right now. Also, I'd appreciate any ideas on what the developer might mean by the following quote. He's asked that I do not use his mailing list anymore and should take my questions to php-general, so it would be impolite to ignore this so I can ask him to explain further: "3. The network buffer used by the PHP streams implementation reads data eagerly. If you fread($socket, 1024) and the network buffer already contains 24 bytes, PHP will try to read 1000 bytes nevertheless." My understanding is the fread() will wait until is has 1024 bytes (in this example) and then return that, unless EOF is encountered when the data up to and including EOF is returned. I'm not sure what he's trying to say. Many thanks for any advice on this. Mark... Code: (The intentions are: used for downloading very large files while avoiding memory problems, this is contained in a loop for a list of files, if the socket is unavailable then the download is not attempted for that file, if the socket is available but no data is received in a 30 second period, then that download should be aborted and retried up to 5 times) $download_attempt = 1; do { $fs = fopen('http://' . $host . $file, "rb"); if (!$fs) { $this->writeDebugInfo("FAILED to open stream for ", "http://"; . $host . $file); } else { $fm = fopen ($temp_file_name, "w"); stream_set_timeout($fs, 30); while(!feof($fs)) { $contents = fread($fs, 4096); // Buffered download fwrite($fm, $contents); $info = stream_get_meta_data($fs); if ($info['timed_out']) { break; } } fclose($fm); fclose($fs); if ($info['timed_out']) { // Delete temp file if fails unlink($temp_file_name); $this->writeDebugInfo("FAILED on attempt " . $download_attempt . " - Connection timed out: ", $temp_file_name); $download_attempt++; if ($download_attempt < 5) { $this->writeDebugInfo("RETRYING: ", $temp_file_name); } } else { // Move temp file if succeeds $media_file_name = str_replace('temp/', 'media/', $temp_file_name); rename($temp_file_name, $media_file_name); $this->newDownload = true; $this->writeDebugInfo("SUCCESS: ", $media_file_name); } } } while ($download_attempt < 5 && $info['timed_out']);
[PHP] Intermittent etwork connection errors with apache. Restarting apache temporarily fixes the problem. PHP or apache problem?
Hi - At the top of my php scripts, I have code to connect to our ldap server, in order for the scripts to make ldap requests. I don't have any disconnect call in my code. Lately I have noticed that the apache server will get into a state where connection requests will occasionally fail. When I refresh the page, the connection almost always succeeds on the 2nd attempt. If I restart the apache server, the problem totally goes away for a long period of time. So I assume that somewhere, something is causing connections to stay opened when the script ends, rather than automatically closing them. This error occurs with other types of network connections that the script makes (besides ldap), so it's not an ldap issue. How does Apache automatically close connections when the script ends? Is it possible that connections are being left opened? Is there any way to debug the problem, i.e. to see if connections are left opened in some way? I'm running redhat 5, httpd-2.2.3-31.el5_4.2 php-5.1.6-23.2.el5_3 Thanks. - Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Recognizing double clicks
Hi. On Sunday 22 Nov 2009 at 05:34 Skip Evans wrote: > It just dawned on me the button may be disabled right when > it's clicked to prevent a double submit? > > Is that doable? To mark a button as disabled after it has been clicked to prevent it being clicked twice just add some simple code in the button (all on one line in case it wraps): onClick="this.disabled=true; this.value='Processing'; this.form.submit();" However I would also do something server side (a unique ID for every form served works well) to handle browsers that don't have javascript turned on. Never rely on (or trust) code running on the client. Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: shell_exec fails to compile java class?
דניאל דנון schreef: Where are you trying to write text.txt? Are you setting a current working directory in your batch file? Do you have write permission in this directory? (copied it to make it easier to understand my answer) In the same folder. Yes, there is a "cd javafiles" Yes. I know its not a permission / directory sort of things, since when there are no errors - the .class compiled java files are created properly. On Fri, Nov 6, 2009 at 9:11 PM, John List wrote: ? wrote: Hello, Thank you - I've managed to do that using a bat file like you suggested. Only problem is that: When I try to call: C:\\Java\bin\javac.exe Tester.java > test.txt (Which should run Tester.java and log any results into test.txt), When there are compilation errors and this command returns results - test.txt stays empty. Any suggestions? Where are you trying to write text.txt? Are you setting a current working directory in your batch file? Do you have write permission in this directory? john On Wed, Nov 4, 2009 at 4:34 PM, Nathan Rixham wrote: ? wrote: Hello! I need to use shell_exec (or any other similar function) in order to compile a java class-file. I have all the needed components installed on my computer (Windows XP with Java SDK) - I can use "java c:\path" in order to compile using Start->Run. When I try to do the same with shell_exec or `` it returns null and it doesn't compiles. Even when there are errors - it doesn't show them at all. I've tried to use instead of "java c:\path..." the full java command line compiler path but it didn't work either. When I try functions such as "echo test" it works. Clearly I'm missing here something - problem is... what? create an ant builder or .bat and call that instead; most likely because the environment isn't set up correctly when executing via php; thus when using ant or bat you can set everything up correctly as needed. always use PHP on linux but permissions and the scope / permissions of the account php runs under may come in to play? nathan Hello, You should execute: C:\\Java\bin\javac.exe Tester.java 1>test.txt 2>&1 This will redirect normal messages as well as errors to your text file. -- Kind regards, Mark Cilissen / Pixlism -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Assignment in Conditional - How are they evaluated?
How is the following evaluated: [code] if ($data = somefunc()) ... [/code] Ignoring the 'assignment inside condition' arguments, is the return value of somefunc() assigned to $data, and then $data's value is evaluated (to true or false), or is the actual assignment tested (does the assignment fail, etc)? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: What would stop header("Location...) from working?
tedd schreef: Hi gang: I just had a script stop following this statement: header("Location:users.php"); It *was* working, but now instead of running "users.php", it defaults to the parent script. When I place exit() after it, such as: header("Location:users.php"); exit(); The script simply exits. It does not continue to users.php -- BUT -- it did. What would stop this statement from working? Thanks, tedd If ANYTHING is output before header(), it stops working. Did you turn off error reporting? You might want to double-check, because it returns an error if anything is output. -- Kind regards, Mark Cilissen / Pixlism -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Unsuscribe
Manuel Morini schreef: I want a list in spanish about PHP Thank you Manuel.morini Try php.general.es. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: simple xml object
AChris W schreef: I have the following xmlwith standard tags changed to [ and ] to prevent mail clients from encoding it as html. [?xml version="1.0"?] [resultset errors="0" results="86"] [result id="20080922133104871678" lastinspected="9/29/2009 0:00"]0.4[/result] [result id="20080922133104871678" lastinspected="8/28/2009 0:00"]1.1[/result] . . . I am using the simplexml_load_string to read it in to an object and execute the following code $xml = simplexml_load_string($content); foreach($xml as $Result){ print_r($Result); foreach($Result->attributes() as $i => $v){ $$i = $v; print "Attr: $i = '$v'\n"; } } that all works fine. Problem is I can't figure out how to get the acutual value (0.4 and 1.1). I also don't know why I can't simply do something like $id = $Result->attributes()->id; the output of this looks like SimpleXMLElement Object ( [...@attributes] => Array ( [id] => 20080922133104871678 [lastinspected] => 9/29/2009 0:00 ) [0] => 0.4 ) Attr: id = '20080922133104871678' Attr: lastinspected = '9/29/2009 0:00' SimpleXMLElement Object ( [...@attributes] => Array ( [id] => 20080922133104871678 [lastinspected] => 8/28/2009 0:00 ) [0] => 1.1 ) Attr: id = '20080922133104871678' Attr: lastinspected = '8/28/2009 0:00' How do I read the [0] value? $Result[0] gives me nothing. Although I'm not that familiar with SimpleXML, since the value returned is an object, wouldn't $Result->0 do the trick? -- Kind regards, Mark Cilissen / Pixlism http://www.ninyou.nl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Unsuscribe
Manuel Morini schreef: I want a list in spanish about PHP Thank you Manuel.morini Try php.general.es. -- Mark Cilissen / Pixlism http://www.ninyou.nl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] putting variables in a variable
Ross, If I understand correctly what you want to do, you're almost there... You need: $myimage1 = "image1.jpg"; $myimage2 = "image2.jpg"; $myimage3 = "image3.jpg"; $body .=" "; Cheers, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: preg_replace problem
Hi. On Saturday 13 June 2009, Al wrote: > I may not have been very clear. Feed it just "test" with the > quotes. You should get back, "test" the same as you gave it. Instead, > I get back "e;test"e; Like Shawn, I have tried your code in isolation and only get the expected results. I looped it over a few test values: \n\n"; foreach ($valueList as $value) { echo "Before: $value\n"; $value=preg_replace("%&(?!amp;)%i", "&", $value); echo "After: $value\n\n"; } echo ''; ?> outputs (ignoring as that was just to remove the for easy reading): Before: " After: " Before: "test" After: "test" Before: "test&test" After: "test&test" Before: "test&test" After: "test&test" The only conclusion is that something else in your code is converting the quotes. Have a look around. HTH Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fractions
Hi. On Sunday 24 May 2009, Ron Piggott wrote: > Is there a way to remove the trailing '0'? $width = number_format($width,2); > Also is there a way to have the original fraction display (1/4), as well > as have provision for 1/8 and 3/8 and 1/2, etc. display? On this one I suspect you'd have to write your own function, but maybe someone else knows better. HTH Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what to use instead of foreach
Hi Phil. On Monday 13 April 2009, PJ wrote: > Thanks for the suggestion, Mark. I've already experimented with count; > you're close, but there is still a small glitch and that's in count(); > foreach doesn't give a damn about count so you can't use that - it is > reset once inside the foreach loop. Look again at the code - the count() is not inside the foreach, so it is not reset, simply stored in $lastIndex for comparison. If your array is associative then simply use another variable to find the last value in the array - the code doesn't need to change much. Try actually running the code below - it does work, as does the previous version I posted if the array is not associative. I'd prefer it if in future you didn't tell me that my code didn't work without actually trying it - I tested that snippet before posting it, as I did with the following. HTH Mark $value) { if ($index != $lastIndex) { $outputString .= "$value, "; } else { $outputString = rtrim($outputString,', '); // Strip last comma. $outputString .= " & $value"; } } echo $outputString; // Associative array (changed only very slightly). $a = array('martha' => '1','jock' => '2','dave' => '3'); $lastIndex = count($a); $counter = 0; $outputString = ''; foreach ($a as $index => $value) { $counter++; if ($counter != $lastIndex) { $outputString .= "$value, "; } else { $outputString = rtrim($outputString,', '); // Strip last comma. $outputString .= " & $value"; } } echo $outputString; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what to use instead of foreach
Hi. On Sunday 12 April 2009, PJ wrote: > foreach does not allow for different formatting for output... [snip] > But how do you get result1, result2 & result3 // with at end ? $lastIndex = count($a) - 1; // Adjust for zero-indexing. $outputString = ''; foreach ($a as $index => $value) { if ($index != $lastIndex) { $outputString .= "$value, "; } else { $outputString = rtrim($outputString,', '); // Strip last comma. $outputString .= " & $value"; } } echo $outputString; Like that? If your array is associative you can drop the $lastIndex calc and adjust the loop to update a counter instead. HTH Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $_GET
Hi. On Sunday 12 April 2009, Ron Piggott wrote: > At the very start of my index.php I have the following lines of code: > > foreach($_GET as $key => $val) { > $$key = $_GET[$val]; > echo $_GET[$val] . ""; > } Try: echo $_GET[$key] . ""; HTH Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE8 and HTML5
Richard Heyes wrote: I have less issues with Chrome and its beta Not thrashing my HDD is also kinda basic, but Chrome 0.2 was more than happy to do that. Thrashing? That's not a bug... it's a feature and that thrashing was chrome indexing (read harvesting information) your hard drive. Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PEAR Help
Jason Todd Slack-Moehrle wrote: > How I need to install OLE and Spreadsheet_Excel_Writer and I dont see > how > > pear install . > > fails every time with channel errors and not found errors. > > I have downloaded the .tgz files, but I dont know where to put the > contents. You can install them by using local filename instead of the package name, e.g.: pear install OLE.tgz Regards, Mark -- http://www.markwiesemann.eu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing for Current pointer position in array during iteration
tedd wrote: At 2:40 PM -0400 8/29/08, Mark Weaver wrote: Hi All, Go figure... I sat down today to get some more work on my current project; I got to a certain point where I need to step through an array with a foreach loop. I found that I need to test for the current pointer position of the array, but I haven't a clue as to how this might be accomplished. I've been all over google and php.net, but I'm not finding anything that will help me do this. Basically all I want to do is something like this: if( current_arrayPointer_postition == n ){ ... do this }else{ ...do this } Anyone know of a built-in PHP function that can assist with this, or can you point me to a resource that could help me code a solution? Try looking at "current" http://www.php.net/current Maybe that will help. Cheers, tedd Thanks all for the helpful suggestions. Actually Jochem's suggestion was just what I needed. I was stuck at just how to test where the pointer was and couldn't see a way out. I knew there had to be a simple, elegant solution, but apparently was over-thinking it. Jochem put things back into perspective for me. -- Mark It was good to be the fire... Better by far than to crawl and mew and suck and shit and die! 'Arthur C. Clarke' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing for Current pointer position in array during iteration
Jochem Maas wrote: Mark Weaver schreef: Hi All, Go figure... I sat down today to get some more work on my current project; I got to a certain point where I need to step through an array with a foreach loop. I found that I need to test for the current pointer position of the array, but I haven't a clue as to how this might be accomplished. I've been all over google and php.net, but I'm not finding anything that will help me do this. Basically all I want to do is something like this: if( current_arrayPointer_postition == n ){ ... do this }else{ ...do this } foreach isn't really like that. it uses (IIRC) an internal pointer of it's own leaving the userland pointer where ever it is. but: $n = 5; // make a new array with numeric keys starting at 0 $array = array_values(array); // loop it foreach ($array as $key => $val) { if ($key == $n) { echo "I got five on it"; } else { echo "usual suspect"; } } very nice... Thank you Jochem. That did the trick. -- Mark It was good to be the fire... Better by far than to crawl and mew and suck and shit and die! 'Arthur C. Clarke' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Testing for Current pointer position in array during iteration
Hi All, Go figure... I sat down today to get some more work on my current project; I got to a certain point where I need to step through an array with a foreach loop. I found that I need to test for the current pointer position of the array, but I haven't a clue as to how this might be accomplished. I've been all over google and php.net, but I'm not finding anything that will help me do this. Basically all I want to do is something like this: if( current_arrayPointer_postition == n ){ ... do this }else{ ...do this } Anyone know of a built-in PHP function that can assist with this, or can you point me to a resource that could help me code a solution? thanks, -- Mark It was good to be the fire... Better by far than to crawl and mew and suck and $h1t and die! 'Arthur C. Clarke' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Counting Occurrences within an If statement
I have been working on the something for the last day and can't figure it out. I am pulling 7500 rows from a MySQL database, but I only want to display a certain numbers of rows based up an if statement. I want to count the rows within the if statement. mysql query result if(x < y){ display a row in a table }else{ Don't display anything } Every time a row is displayed, I want to add one to a counter markb
Re: [PHP] Search thoughts
Hi. Just noticed I replied direct rather than to the list last time, sorry about that. On Saturday 19 July 2008, Richard Heyes wrote: > How much traffic do you have and what's your hardware? Are your queries > cached and subsequently repeated? Do you pre cache common queries? I've done this kind of search twice, but both were for internal web apps so I can't link you to them. In both cases I return only items IDs and limit it to 10 results, with the subsequent queries being done only if the previous ones didn't return enough results to fill the page. Both of these speed it up a lot, obviously. One of them has a possible max of 6 different ways to examine the data tables, and still return a full results page in under half a second. Nothing is pre-cached, and I'm really not sure about the hardware, sorry, that's the IT guy's problem. I don't imagine it's anything spectacular though. The apps get quite heavy use but I'm with Tedd on the results issue, we only see maybe 10% of the users going to page 2, but these are internal users searching company data, so the pattern may not be typical. Hope you find something you're happy with, Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Log files
I am writing an application in which I want to create log files. I am weighing the difference between using text files and using a database to house the data. It appears to me that there is really no advantage either way or is there? There are pros and cons to both methods, but I am concerned about opening and closing a text file some many times that it may cause and issue. The file may be opened and closed 1,000 or more times a day. Opinions please.. markb
[PHP] String to date
I need to convert a date retrieved from user input to a mysql date. Here the problem, I need to convert one of three possible combinations, either 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's limited to one character to explode on. I would prefer not to use regexp, but think I am going to have to. The one part of the code that works below is using 01/01/2008 format. Any suggestions echo $olddate = '06/06/2008'; echo ""; echo $olddate2 = '06-16-2008'; echo ""; echo $olddate3 = '06.26.2008'; echo ""; echo $newdate = date("Y-m-d",strtotime($olddate)); echo ""; echo $newdate2 = date("Y-m-d",strtotime($olddate2)); echo ""; echo $newdate3 = date("Y-m-d",strtotime($olddate3)); markb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SOLVED: Calendar Date Help
Robert Cummings wrote: function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); I don't really want to say "I told you so", but that's one of the two lines I denoted as incorrect in my first response ;) :P indeed you did... it just took me a while before it dawned on me. I just wasn't seeing it until the "Mule" got tired of trying to climb a vertical cliff! Thank you Robert for the push to seriously scrutinize my code. It's far more important to learn to build complex code from simple code, than to try and understand complex code and then refactor it to simple code. Just a thought for the future since as it stands you have a very convoluted system of moving back and forth between months. Cheers, Rob. The particular block of code you're referring to definitely needs to be "re factored", however at the moment I don't know enough about php to accomplish that. I think one of the bad habits I got into early on was coding verbosely so I wouldn't have to comment as much. That definitely doesn't serve very well at times. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SOLVED: Calendar Date Help
Mark Weaver wrote: Hi all, I've put this off as long as possible, however I think I've reached an impasse. I've got an application that I've been writing. One of the modules for this app is an event calendar. I've got the calendar to the place where it displays the current month as well as previous and future months. The place I'm stuck is it will only show months in the past or the future that are months in the current year. Basically the method I'm using to move backward and forward is with Unix timestamps. 1. When the calendar first loads the "what" is checked for; // passed in via $_GET $what == current, prev, or next a. "current" is the default $now = time() $prev = date('n',$now)-1 $next = date('n',$now)+1 b. Timestamp values are then stored in an array and then sent to client in session cookie which is then accessed upon each subsequent request to display the event calendar. My question/boggle is why, when the calendar advances to December(current year) it will display January, but of the current year. The same happens in reverse. Once I reach the end of the year either in the past or future the month increases or decreases accordingly, but the year doesn't change. Since the year value isn't changing the month calendar days that are displayed simply repeat themselves. I know there's something I'm missing, but I am definitely not seeing what it is... /** code below / $cal = new Calendar; $calpos = array(); // check incoming values if ($what === "current"){ $cal->setCal(0,0,0,date('n'),1); $now = time(); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } elseif($what === "prev"){ $peek = $_SESSION['calendar']; $now = $peek['prev']; $cal->setCal(0,0,0,date('n',$now),1); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } elseif($what === "next"){ $peek = $_SESSION['calendar']; $now = $peek['next']; $cal->setCal(0,0,0,date('n',$now),1); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } <> function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); // Using the stamp the various necessary properties are set for the // object function getStamp($dateStr,$dayVal=1){ return date('U',mktime(0,0,0, $dateStr,$dayVal,date('Y'))); } Just in case: The solution was right in front of my all along. When setting the calendar object I was giving the class everything it needed except the {year} value. I _ass_-umed it was being set auto-magically; possibly by fairies or tree elves. Turns out I needed to set that parameter. Imagine that... :) -- $cal->setCal(0,0,0,date('n',$now),1); -- function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); -- Solution: setCal function from Calendar Class: function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1,$yrVal) current: $cal->setCal(0,0,0,date('n',time()),1,date('Y',time())); $prev value coming from session cookie $now = $session['prev']; prev: $cal->setCal(0,0,0,date('n',$now),1,date('Y',$now)); $next value coming from session cookie $now = $session['next']; next: $cal->setCal(0,0,0,date('n',$now),1,date('Y',$now)); It all works very nicely now. Thank you Robert for the push to seriously scrutinize my code. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] In case this helps... (Calendar Date Help)
Robert Cummings wrote: On Wed, 2008-05-28 at 16:47 -0400, Robert Cummings wrote: Out of curiosity.. have you thought about reworking your premise? Using prev, current, and next is extremely sloppy IMHO. Additionally, it prevents bookmarking a specific calendar date. Why don't you have a date parameter that indicates the year and month? If no such field exists then you fallback to current date. Then the situation becomes trivial and doesn't require dependence on the session. Having looked at your code it strikes me as very poorly thought out which makes it difficult to ascertain your current problem. At any rate, it's obviously more complex than is necessary. Those two lines above should be: $timestampPrev = strtotime( '-1 month', $timestampCurr ); $timestampNext = strtotime( '+1 month', $timestampCurr ); Cheers, Rob. Ok... I've made a change to getStamp() using the two lines above to see what would happen, however the results are the same. If I move through the months up to December the calendar moves normally and correctly. But, once I get to January it displays January for 2008 and never increments the year. getStamp() now looks like this: public function getStamp($stamp,$d){ if ($d === 1){ return strtotime( '+1 month', $stamp ); } elseif($d === 0){ return strtotime( '-1 month', $stamp ); } } I know it's a matter of me not understanding fully what I'm doing; I'm just not sure where to go from here. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] In case this helps... (Calendar Date Help)
Robert Cummings wrote: Out of curiosity.. have you thought about reworking your premise? Using prev, current, and next is extremely sloppy IMHO. Additionally, it prevents bookmarking a specific calendar date. Why don't you have a date parameter that indicates the year and month? If no such field exists then you fallback to current date. Then the situation becomes trivial and doesn't require dependence on the session. Having looked at your code it strikes me as very poorly thought out which makes it difficult to ascertain your current problem. At any rate, it's obviously more complex than is necessary. Prev'; echo 'Curr'; echo 'Next'; ?> Well, of course it's sloppy. I've only been coding PHP OOP since January. :) Given the app is barely in the alpha stage I wanted to start with a simple premise and wait till development is further along to make the ugly bits more elegant. At the moment I don't understand why getStamp() isn't taking $dateStr and returning the the {year} for date stamps in past or future outside the current year. (value being passed to getStamp() inside $dateStr is 'date('Y')-1') When I can understand what I'm currently doing wrong premise changing will likely make a lot more sense. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] In case this helps... (Calendar Date Help)
Mark Weaver wrote: Hi all, I've put this off as long as possible, however I think I've reached an impasse. I've got an application that I've been writing. One of the modules for this app is an event calendar. I've got the calendar to the place where it displays the current month as well as previous and future months. The place I'm stuck is it will only show months in the past or the future that are months in the current year. Basically the method I'm using to move backward and forward is with Unix timestamps. 1. When the calendar first loads the "what" is checked for; // passed in via $_GET $what == current, prev, or next a. "current" is the default $now = time() $prev = date('n',$now)-1 $next = date('n',$now)+1 b. Timestamp values are then stored in an array and then sent to client in session cookie which is then accessed upon each subsequent request to display the event calendar. My question/boggle is why, when the calendar advances to December(current year) it will display January, but of the current year. The same happens in reverse. Once I reach the end of the year either in the past or future the month increases or decreases accordingly, but the year doesn't change. Since the year value isn't changing the month calendar days that are displayed simply repeat themselves. I know there's something I'm missing, but I am definitely not seeing what it is... /** code below / $cal = new Calendar; $calpos = array(); // check incoming values if ($what === "current"){ $cal->setCal(0,0,0,date('n'),1); $now = time(); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } elseif($what === "prev"){ $peek = $_SESSION['calendar']; $now = $peek['prev']; $cal->setCal(0,0,0,date('n',$now),1); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } elseif($what === "next"){ $peek = $_SESSION['calendar']; $now = $peek['next']; $cal->setCal(0,0,0,date('n',$now),1); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } <> function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); // Using the stamp the various necessary properties are set for the // object function getStamp($dateStr,$dayVal=1){ return date('U',mktime(0,0,0, $dateStr,$dayVal,date('Y'))); } After scratching my head on this for a few hours I'm still no closer to the solution, but essentially what I need to do in the getStamp function is test the {year} of the stamp that results from the incoming $dateStr against the actual {year} value of the current year's timestamp time(). In case it helps below is the code being used in it's entirety. The first block of code is the Calendar class and the second is the code for the page which displays the event calendar. my appologies if it's all jumbled up. /* Calendar Class ***/ class Calendar{ public $month,$weekday,$dayname,$monthname,$numdays,$year,$mday,$dbdate,$today,$fday; public function Calendar(){ @$this->month = $month; @$this->weekday = $weekday; @$this->dayname = $dayname; @$this->monthname = $monthname; @$this->numdays = $numdays; @$this->year = $year; @$this->mday = $mday; @$this->dbdate = $dbdate; @$this->fday = $fday; } public function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); $month = date('m',$stamp); // month value with leading zero $mday = date('d',$stamp); // day value with leading zero
Re: [PHP] Calendar Date Help
Robert Cummings wrote: function getStamp($dateStr,$dayVal=1){ return date('U',mktime(0,0,0, $dateStr,$dayVal,date('Y'))); } ^ ^ ^ Similarly. Cheers, Rob. Hi Rob, Changing: function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); To: function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ if (date('Y') > date('Y',date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y') { $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y')+1)); } else { $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); } Makes no change. Strange condition still exists. I was rather hoping that if "date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y')))" is smart enough to know to increase or decrease the month value that it would do the same to the year value accordingly. $offset contain either date('n',$timestamp)-1 or date('n',$timestamp)+1 The $timestamp value comes from the array being stored in the $_SESSION['calendar'] as either 'current', 'prev', or 'next'. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Calendar Date Help
Hi all, I've put this off as long as possible, however I think I've reached an impasse. I've got an application that I've been writing. One of the modules for this app is an event calendar. I've got the calendar to the place where it displays the current month as well as previous and future months. The place I'm stuck is it will only show months in the past or the future that are months in the current year. Basically the method I'm using to move backward and forward is with Unix timestamps. 1. When the calendar first loads the "what" is checked for; // passed in via $_GET $what == current, prev, or next a. "current" is the default $now = time() $prev = date('n',$now)-1 $next = date('n',$now)+1 b. Timestamp values are then stored in an array and then sent to client in session cookie which is then accessed upon each subsequent request to display the event calendar. My question/boggle is why, when the calendar advances to December(current year) it will display January, but of the current year. The same happens in reverse. Once I reach the end of the year either in the past or future the month increases or decreases accordingly, but the year doesn't change. Since the year value isn't changing the month calendar days that are displayed simply repeat themselves. I know there's something I'm missing, but I am definitely not seeing what it is... /** code below / $cal = new Calendar; $calpos = array(); // check incoming values if ($what === "current"){ $cal->setCal(0,0,0,date('n'),1); $now = time(); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } elseif($what === "prev"){ $peek = $_SESSION['calendar']; $now = $peek['prev']; $cal->setCal(0,0,0,date('n',$now),1); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } elseif($what === "next"){ $peek = $_SESSION['calendar']; $now = $peek['next']; $cal->setCal(0,0,0,date('n',$now),1); $prev = $cal->getStamp(date('n',$now)-1,1); $next = $cal->getStamp(date('n',$now)+1,1); $calpos['curr'] = $now; $calpos['prev'] = $prev; $calpos['next'] = $next; $_SESSION['calendar'] = $calpos; } <> function setCal($h=0,$m=0,$s=0,$offset,$dayVal=1){ $stamp = date('U',mktime($h,$m,$s, $offset,$dayVal,date('Y'))); // Using the stamp the various necessary properties are set for the // object function getStamp($dateStr,$dayVal=1){ return date('U',mktime(0,0,0, $dateStr,$dayVal,date('Y'))); } -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Two word array Value
I am trying to use array's to populate a group of check boxes for a form. I am getting the checkboxes to print OK, but when the form is posted I am only getting part of the array. Form Page: $vars = array("Main Classroom" => "Main Classroom", "Break Out Classroom" => "Break Out Classroom", "Gym" => "Gym", "Firearms Range" => "Firearms Range", "EVOC Track" => "EVOC Track"); $cols = 4; echo "Equipment Needed"; foreach($vars as $key => $value){ if (($cols % 4) == 0 ){ echo ""; } echo "".$value.""; $cols++; } echo ""; echo ""; When I submit the form I am only getting the following having checked the boxes for Mail Classroom and Break Out Classroom. If I eliminate the spaces between the words, I get everything, but when I put the spaces between the words in the array, it cuts off the second word. Not sure what is happening? Array ( [Main] => Main [Break] => Break [Submit] => Submit )
Re: [PHP] Re: Where to start!
Richard Heyes wrote: I do not agree that creating a database which is normalised to3NF is a waste of time. It isn't always, but it is sometimes. When time is a (significant) factor, getting something up and running (which has acceptable performance) may be more impotant than creating a technically perfect solution. In fact creating something that is technically perfect is often just a pipe dream for programmers. > On the contrary, a totally un-normalised database is nothing but a problem waiting to bite you in the a**e. So you can: a) Create something that gets you to market as fast as possible that is "good enough". b) Optimise/adjust the structure later. IME though, b) rarely happens. > Computer systems have a habit of growing over time Really? ...and if you don't follow the rules of normalisation your database will end up as the biggest bottleneck. Granted it's more likely, but not a given. You just need developers who have discipline, oh and a good memory helps. Anyone who doesn't know how to reach 3NF shouldn't be designing databases. Rubbish. It helps, in particular for how you can optimise you structure without duplicating data (too much), but shouldn't be a requirement. Me personally I've always found it very productive to take a few hours before I begin coding a project, to roughly flow-chart the basics of the application, and then layout the db on paper to get a graphical view of the tables I'll need, how they relate or don't relate to one another. That way when I do actually create the db I'm usually at 3NF. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] joins issues again
On Tue, Apr 8, 2008 at 7:28 AM, Steven Macintyre <[EMAIL PROTECTED]> wrote: > I have the following SQL statement; ... and this relates to PHP how? > SELECT count( salesID ) AS count, branch_name, company_name, branch.branchID That doesn't make sense. You're selecting a group function (COUNT) along with other columns which you're not grouping on. It might help if you told us what you were trying to accomplish with the query. But you'd be better off asking on a SQL list instead of a PHP one. > FROM sales > LEFT JOIN IGuser ON sales.IGuid = IGuser.IGuid > LEFT JOIN branch ON IGuser.branchID = branch.branchID > LEFT JOIN company ON branch.companyID = '{$companyID}' > WHERE maincompanyid = '{$mcid}' > GROUP BY branch.branchID > ORDER BY branch_name ASC > > However, i do not want those join records to be appended, only to return the > count of records from sales. So why are you joining in the first place? -- Mark J. Reed <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] dynamic boxes problem... JS and PHP
Ryan S wrote: Hey everyone, A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or just me. (My money is on the last one :p ) Here's what I am trying to do: In a form I have a listbox with the values 1-5, and under the listbox i have a with the id of "recips" (like so: ' + '' + ''+ x +'. Recipient\'s name:' + '' + 'Recipient\'s email:' + '' + '' + '' + ''; } document.getElementById('recips').innerHTML=msg; } / # End JS code So far on the page everything is working, but when I click the submit button this is my PHP processing script: It shows me everything that has been submitted but NOT any of the above dynamically made boxes values... but get this, it DOES show me all values... in IE7 _not_ in FF (am using 2.0.0.13) Anybody else face anything like this? Is this a bug in FF? Is $_REQUEST wrong to catch this? Dont know what the @#$@ to do... ANY help even a link to a site which can shed a little light would be appreciated. Thanks in advance. /Ryan Hi Ryan, Since I'm relatively new to PHP I could be off on this, but I'd say yes, $_REQUEST is wrong. I would think you'd want to use $_POST to receive the incoming values from a form. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Could someone tell me what a tilde(~) in PHP does ?
On Tue, Apr 8, 2008 at 8:50 AM, Mark J. Reed <[EMAIL PROTECTED]> wrote: > That is, the number 47 in binary is 110001, " ... or 10, if you want to be technical. 110001 is 49. :) "The important thing is to understand what you're doing, rather than to get the right answer." --Tom Lehrer -- Mark J. Reed <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Could someone tell me what a tilde(~) in PHP does ?
On Tue, Apr 8, 2008 at 6:19 AM, Tony Collings <[EMAIL PROTECTED]> wrote: > The humble tilde (~). I came across it the other day in some PHP code > [code]~E_ERROR[/code] That comes from C, not postpositional math. It's bitwise negation. That is, the number 47 in binary is 110001, with leading 0's out to whatever the word size is, usually 32 or 64 bits. The ~ flips the bits, so on a 32-bit system ~47 is binary 11001110, which is -48 if you treat it as a signed value and 429496248 as unsigned. The tilde is most often seen in the company of flag values, where each bit represents an option that is on or off. Typically, you have a bunch of constants defined as the individual bit values, like say E_DEBUG. Then ~E_DEBUG means "turn on everything except E_DEBUG". Often used with bitwise AND (&) as a mask to turn a particular bit off, as in which turns off E_DEBUG while leaving the other bits in $flag unchanged. -- Mark J. Reed <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date comparison Question
On Mon, Apr 7, 2008 at 11:42 AM, <[EMAIL PROTECTED]> wrote: >t the data is fed from the database, CaldTime is timestamp and since it will not allow me to have 2 timestamps in > the same table ?? What database are you using? It sounds like it has a specific meaning of "timestamp" - probably "the last time this row was modified" - and you want an arbitrary date column, which would probably be a different column type. Not a string, though. An actual date type. possible names are date, datetime, datestamp... , and you I set the CallEnd varchar(12). Storing the data they seem to be the same for output. I checked hexadecimal and binary to look for obscurities. > > > $sqldata['CaldTime'] = "2008-04-07 11:15:32"; > $sqldata['CallEnd'] = "2008-04-07 11:17:17"; > > $time1 = strtotime("$sqldata[CaldTime]"); > $time2 = strtotime("$sqldata[CallEnd]"); > $interval = $time2 - $time1; > > echo $interval; > > +++ > Displays like 1.75:0 > I am looking for a more precise time like 1:45 instead. > Am I looking at this all wrong for time difference? strtotime returns an integer number of seconds. The difference between $time1 and $time2 is 105. If you want minutes and seconds, you have to do the math yourself. $interval_min = floor($interval/60); $interval_sec = $interval % 60; echo "$interval_min:$interval_sec"; -- Mark J. Reed <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string
On Mon, Apr 7, 2008 at 9:30 AM, <[EMAIL PROTECTED]> wrote: > Do a preg match to find one or preg_match_all to find all the john in the > string. preg_* is overkill if you're just searching for a literal string. use it if you're searching for any strings matching a pattern, part of which you don't know. If you know the entire string you're looking for, strstr() is both more efficient and easier to use. Now, strpos() is more efficient still, but arguably more annoying to use because of the "0 but true" issue that necessitates checking for !== false. Besides efficiency, the only difference between strstr() and strpos() is what they return. strpos() returns the index of the first match, while strstr() returns the entire string starting from that point; it's the building of the copy of the string that causes strstr() to be less efficient. Both functions have case-insensitive variants stristr and stripos. In each case, if the substring occurs more than once within the outer string, the return value is based on the *first* occurrence. strpos() (but not strstr()) has a variant that uses the *last* one instead: strrpos() (r=reverse), which also has a case-insensitive version strripos(). You can easily define a strrstr() though: function strrstr($where, $what) { $pos = strrpos($where, $what); return $pos === false ? false : substr($where, $pos); } And for good measure, a strristr: function strristr($where, $what) { $pos = strripos($where, $what); return $pos === false ? false : substr($where, $pos); } > >$name = "John Taylor"; > $pattern = '/^John/'; > preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3); > print_r($matches); > ?> > > > > > > > > $name = "John Taylor"; > I want to verify if $name contains "john", if yes echo "found"; > Cannot remember which to use: > http://ca.php.net/manual/en/ref.strings.php > Sorry, > John > > -- > 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 > > -- Mark J. Reed <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arbitrary mathematical relations, not just hashes
On Sun, Apr 6, 2008 at 11:51 PM, Casey <[EMAIL PROTECTED]> wrote: > I hit reply-all... now am I suddenly subscribed to Perl and Ruby lists!?! Huh, didn't notice the cross-posting. But no, you're not subscribed to any new lists. Since we're cross-posting, the translation of my sample would be apropos. Here are a few different takes on a loopless versions in Ruby. Given: color = { :apple => :red, :ruby => :red, :banana => :yellow } This is, I think, the most straightforward: color.keys.find_all { |k| color[k] == :red } But having to repeat the hash name is inelegant. Which leads us to this: color.find_all { |k,v| v == :red }.collect { |p| p[0] } Building up a list from the elements of a Hash would seem to be a natural application of Hash#inject, although the fact that the inject block has to return the accumulator makes it a little less elegant than it could be, IMO: color.inject([]) { |a,p| a << p[0] if p[1] == :red; a } In Perl5 I don't have a better solution than the first one above: my %color = ( apple => 'red', ruby => 'red', banana => 'yellow'); grep { $color{$_} eq 'red' } keys %color; -- Mark J. Reed <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arbitrary mathematical relations, not just hashes
As far as languages with two-way relation go, there are many; perhaps the most prototypical is Lisp, in that either member of a pair within an alist can be used to look the pair up, with no extra function or second map definition required. But PHP has pretty good support, too, actually. If you have a 1-to-1 relation, you can use array_flip() to get a second array with the keys and values swapped in one go. If you have a 1-to-many, as in this case, you can use the optional search parameter to array_keys: >>> $color = array('apple' => 'red', 'ruby' => 'red', 'banana' => 'yellow'); >>> array_keys($color, 'red') Array ( [0] => apple [1] => ruby ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] objects stored in sessions
Richard Heyes wrote: So, if I create a user object, set the properties of said user object and store that object in the user session will that object be available throughout the application from the session? Yes. Just remember to include the class definition before you start the session on subsequent pages, otherwise you will encounter problems. Or alternatively use __autoload() to allow the class code to be loaded when you start the session. sweet! thank you Richard. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] objects stored in sessions
Hi All, I've got something on my little mind, and please keep in mind I'm still somewhat new to PHP Oop, so please excuse my silly ass if I ask something that should be obvious. I've got an application that I'm re-writing from PERL to PHP Oop. At the beginning of the application, at log in, a session is created for this user. What I would like to do is create a user object and store object properties in that session. So, if I create a user object, set the properties of said user object and store that object in the user session will that object be available throughout the application from the session? thanks, -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cookie Trouble: getting the information back out...
tedd wrote: Mark: You said: I'm gonna shit and go blind cause I haven't got a clue... and The only thing preventing me from gouging out my eyes right now is ... Are you sure that programming is right for you? It sounds like you're going to hurt yourself. This was just a cookie. :-) Cheers, tedd There's an old proverb that basically says that if you present a mule with two choices, (1) a easy, meandering path up the side of a mountain that triples the time it would take to get to the top, and (2) a brutally hard path that goes straight up the mountain, but would most certainly have a good chance of killing the mule if taken, the mule will take path number 2 each and every time. It's the mule in me! :) I can't help myself. It's like sitting a pair of shoes down in front of a leprechaun; he can't resist the compulsion the shine and clean those shoes. I can't resist the compulsion to solve a problem by coding a solution for it. I really enjoy programming. It satisfies a creative bent in me, but from time to time I do get very frustrated with it. Especially when, as in this case, it's only a cookie and an easy concept. What frustrates me is I know I'm missing something, but for the life of me I can't see it. Therefore the shoe that I'm compelled to clean and shine keeps dipping itself back into the mud. For me moving from procedural PERL programming to OOP PHP feels like a paradigm shift! some of it coming back easily and some of it not so easily. Ya know... old dog new tricks... that sort of thing. But if I don't challenge myself and learn new things I could run the risk of getting stuck in a rut of thinking the same way about things and well... never mind... shit! more mud on that shoe again. :) -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cookie Trouble: getting the information back out...
Jim Lucas wrote: Mark Weaver wrote: Andrew Ballard wrote: On Tue, Mar 25, 2008 at 9:59 PM, Mark Weaver <[EMAIL PROTECTED]> wrote: Thank you Andrew... Now it all makes perfect sense. Good grief! there's so much to learn. It seems that Java was easier. ;) That's not specific to PHP. It's just how http works, so it's the same for ASP, Perl, I suspect Java and most (if not all) other languages. There might be a language that sets a cookie when you assign a value to a special cookie variable, but I'm not familiar with any. Andrew Unless I was doing something differently when I originally wrote this in PERL I don't recall having this issue. At that time I would set the cookie and then redirect (load the index with the full menu) if cookie existed. Geez! now my $_SESSION isn't persisting to the next page when the screen refreshes. The only thing preventing me from gouging out my eyes right now is that I know I'll get this stuff. It's just a matter of time... The "problem" that you are encountering is because the $_COOKIE array is "populated" when the script is executed. More then likely the other languages that you used, would allow you to set a cookie and then they would enter them into the "global" array for you, and not make you wait until the next page load. You could accomplish this yourself by making a wrapper function for the setcookie() function and have your function set the data using setcookie() and having it enter the data directly into the $_COOKIE array. Something like this should do the trick Wow! very sweet!! Thank you Jim. I'm getting my brain good and wrinkled today. -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cookie Trouble: getting the information back out...
Andrew Ballard wrote: On Tue, Mar 25, 2008 at 9:59 PM, Mark Weaver <[EMAIL PROTECTED]> wrote: Thank you Andrew... Now it all makes perfect sense. Good grief! there's so much to learn. It seems that Java was easier. ;) That's not specific to PHP. It's just how http works, so it's the same for ASP, Perl, I suspect Java and most (if not all) other languages. There might be a language that sets a cookie when you assign a value to a special cookie variable, but I'm not familiar with any. Andrew Unless I was doing something differently when I originally wrote this in PERL I don't recall having this issue. At that time I would set the cookie and then redirect (load the index with the full menu) if cookie existed. Geez! now my $_SESSION isn't persisting to the next page when the screen refreshes. The only thing preventing me from gouging out my eyes right now is that I know I'll get this stuff. It's just a matter of time... -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cookie Trouble: getting the information back out...
Andrew Ballard wrote: On Tue, Mar 25, 2008 at 9:31 PM, Daniel Brown <[EMAIL PROTECTED]> wrote: On Tue, Mar 25, 2008 at 9:11 PM, Mark Weaver <[EMAIL PROTECTED]> wrote: > Hi all, [snip!] > Cookie Test Page > == > if (isset($_COOKIE["cookiename"])){ > list($first,$second,$third) = explode('|',$_COOKIE["cookiename"]); > echo "I found your cookie\n"; > echo "The following Values were Contained in the cookie: > Username: $first > Password: $second > Type: $third\n"; > } > else{ > echo "I wasn't able to find your cookie.\n"; > } > > Now, I've constructed a cookie_test.php page to check things out and the > strange behavior I'm seeing is, upon first execution I get the "else" > block, but if I hit the browser's reload button I get the "if" block. At > first I thought the cookie wasn't being read at all because of weird > characters, but then upon reloading the page and seeing the "if" block > being displayed I'm thoroughly confused. It's gotta something simple I'm > missing. Is this block of code executed immediately after the cookie is set? Sometimes PHP works too fast for its own good and the client doesn't even realize it has a cookie yet. Try setting it with one page and either sleep()'ing for a bit or forcing a link-click or page refresh before checking for the cookie. Um... Cookie data ISN'T available to the same script that sets it. If you use setcookie(), all it does is send a header to the browser immediately ahead of the output of your script telling the browser to store those values in either memory or on disk. The value will not appear in the $_COOKIE array until the browser requests the next page and includes the Cookie: header as part of the request. The part of the manual that applies is this line: "Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays." $_SESSION variables are available immediately as soon as you set them. The session cookie still isn't set on the client until the browser processes the response headers at the end of the transaction, but the values are already in the array and, if the session cookie works they will be accessible on successive requests. Andrew Thank you Andrew... Now it all makes perfect sense. Good grief! there's so much to learn. It seems that Java was easier. ;) -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Cookie Trouble: getting the information back out...
Hi all, I suspect I already know part of the answer to this, but I'm not sure which way to go with it. I've got a project I'm working on and one of the things it's got to do is set cookies and then read them later. When the app was first written I was doing everything in PERL and cookies are fairly straight-forward, however I'm finding cookies in PHP somewhat problematic. Setting the cookie is a snap, however getting the info back out is, well... problematic. this is basically what I'm doing, what I'm seeing in the cookie, and what I'm getting back out. Setting the cookie == $values = "blah|blah|blah"; setcookie("cookiename", $values, time()+$timevalue); Inside the Cookie == Content: blah%7Cblah%7Cblah Getting info Out Of Cookie == list($first,$second,$third) = explode("|", $values); Cookie Test Page == if (isset($_COOKIE["cookiename"])){ list($first,$second,$third) = explode('|',$_COOKIE["cookiename"]); echo "I found your cookie\n"; echo "The following Values were Contained in the cookie: Username: $first Password: $second Type: $third\n"; } else{ echo "I wasn't able to find your cookie.\n"; } Now, I've constructed a cookie_test.php page to check things out and the strange behavior I'm seeing is, upon first execution I get the "else" block, but if I hit the browser's reload button I get the "if" block. At first I thought the cookie wasn't being read at all because of weird characters, but then upon reloading the page and seeing the "if" block being displayed I'm thoroughly confused. It's gotta something simple I'm missing. and I swear if someone tells me to RTFM I'm gonna shit and go blind cause I haven't got a clue as to "which" part of the FM to read concerning this. :) thanks, -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing
PHP General Users Mailing List wrote: testing so I wasn't imagining things then? -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] question about linux editor
Casey wrote: On Mon, Mar 24, 2008 at 7:28 PM, Sudhakar <[EMAIL PROTECTED]> wrote: i need to connect to the linux server using an editor. can anyone suggest which would be an ideal linux editor to connect to the server. apart from the ip address, username and password are there any other details i would need to connect to the server. please advice. thanks. Putty! er... no... he said from Linux! :) -- Mark - the rule of law is good, however the rule of tyrants just plain sucks! Real Tax Reform begins with getting rid of the IRS. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strange list behavior when replying to message on list
Nilesh Govindrajan wrote: Shawn McKenzie wrote: Mark Weaver wrote: Andrew Ballard wrote: On Sat, Mar 22, 2008 at 11:13 AM, Mark Weaver <[EMAIL PROTECTED]> wrote: Hi all, I'm wondering if anyone else happens to be using Mozilla Thunderbird and seeing this behavior, and also if this behavior is a feature or a bug. When I hit the reply button to respond to a message most of the time the actual sender's address is the one the message is being sent to rather than the list itself. This is the first mailing list I've been on that I've seen this behavior; all other lists I'm on when one hits the reply button, or CTRL+R the mailing list's address is inserted as it should be and is expected. I know with some email clients there is a menu item specifically there for responding "to the list" based on whether or not there is a list-header in the header information but that isn't an available option with Thunderbird. Is anyone else seeing this behavior or is there something I'm missing? Mark It's not specific to Thunderbird or any other mail client. I'm pretty sure it was configured that way on purpose. Have a look at this thread: http://marc.info/?l=php-general&m=105700032521606&w=2 Andrew well, obviously since the issue still exists it's clear that this never got resolved. I just don't understand the obstenant behavior of some folks in the presence of clear and plain logic. Especially from a programmer. Makes no sense at all. Guess I'm off to create the necessary recipe for Procmail to do the adult thing and make sense of the non-sense. I use Thunderbird 2.x on Kubuntu and I just hit reply to this mail. I have news.php.net setup as a news account. I do receive and have received frequent timeouts contacting the news server though. Has been a pain for quite awhile. -Shawn That's what I also do. :D I have thunderbird 2.x on Fedora 8. So, it works. :) by the way... I thought everyone would be rather interested to know that because of the way the list is setup and running at the moment and "not" hiding the senders email address, it's extremely easy to harvest addresses from messages. That means that if someone got infected or a spammer, scammer, etc... ever subscribed to the list it wouldn't be any trouble at all to get list members' addresses. It took all of 10 seconds to grep the imap folder where all the messages I get are stored for the From: header and out popped everyone's address. Just another reason to hide the sender's address and use the reply-to header. -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Procmail Recipe to INSERT reply-to header (was: strange list behavior when replying to message on list)
tedd wrote: At 11:22 AM -0400 3/22/08, Greg Bowser wrote: Yeah. I always forget to reply to all. I always reply to all and then cut out everything that isn't [EMAIL PROTECTED] I know, there's probably a better way, but that's what I do. Cheers, tedd Just in case you "Do" have access to procmail the recipe below should do the trick for fixing this annoying "feature". Just keep telling yourself it's a feature and not a bug. :) - # fixing the MISSING reply-to header on PHP list messages # This adds a Reply-To: header :0 fhw * ^Received:.*from lists.php.net |formail -I "Reply-To: php-general@lists.php.net" -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strange list behavior when replying to message on list
tedd wrote: At 11:22 AM -0400 3/22/08, Greg Bowser wrote: Yeah. I always forget to reply to all. I always reply to all and then cut out everything that isn't [EMAIL PROTECTED] I know, there's probably a better way, but that's what I do. Cheers, tedd That's what I've been doing as well until I get procmail setup to do it for me. -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strange list behavior when replying to message on list
Andrew Ballard wrote: On Sat, Mar 22, 2008 at 11:13 AM, Mark Weaver <[EMAIL PROTECTED]> wrote: Hi all, I'm wondering if anyone else happens to be using Mozilla Thunderbird and seeing this behavior, and also if this behavior is a feature or a bug. When I hit the reply button to respond to a message most of the time the actual sender's address is the one the message is being sent to rather than the list itself. This is the first mailing list I've been on that I've seen this behavior; all other lists I'm on when one hits the reply button, or CTRL+R the mailing list's address is inserted as it should be and is expected. I know with some email clients there is a menu item specifically there for responding "to the list" based on whether or not there is a list-header in the header information but that isn't an available option with Thunderbird. Is anyone else seeing this behavior or is there something I'm missing? Mark It's not specific to Thunderbird or any other mail client. I'm pretty sure it was configured that way on purpose. Have a look at this thread: http://marc.info/?l=php-general&m=105700032521606&w=2 Andrew well, obviously since the issue still exists it's clear that this never got resolved. I just don't understand the obstenant behavior of some folks in the presence of clear and plain logic. Especially from a programmer. Makes no sense at all. Guess I'm off to create the necessary recipe for Procmail to do the adult thing and make sense of the non-sense. -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strange list behavior when replying to message on list
Nilesh Govindrajan wrote: The list admin, if uses a program called ezlm (or something similar), it adds the List-Id or the Newsgroups header which also helps. They must have it. hmmm... I wonder if Sylpheed for Windows will handle this? I'll have to take a look. -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strange list behavior when replying to message on list
Brandon Orther wrote: I just signed back up to the list recently, but it was like this 5 years ago when I was still on it. I have always wondered why they didn't have that. It seems like they are pushing people to submit their solutions to the person with the question. Kind Regards, Brandon Orther Boy! is this tempting... I've got a sendmail server running with Mailman installed on it that I'm already running lists on it. -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strange list behavior when replying to message on list
Nilesh Govindrajan wrote: Greg Bowser wrote: Yeah. I always forget to reply to all. The problem is with the headers. Whereas other lists have a reply-to: in the email headers, this list does not. It annoys the hell out of me. Why in the bloody hell doesn't the list admin simply "add" that reply-to header. As far as I know Sendmail adds that auto-magically by default. (I'm assuming they're not using Sendmail as the lists' MTA). It sure would make life easier wouldn't it? How long has it been this way? -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strange list behavior when replying to message on list
Hi all, I'm wondering if anyone else happens to be using Mozilla Thunderbird and seeing this behavior, and also if this behavior is a feature or a bug. When I hit the reply button to respond to a message most of the time the actual sender's address is the one the message is being sent to rather than the list itself. This is the first mailing list I've been on that I've seen this behavior; all other lists I'm on when one hits the reply button, or CTRL+R the mailing list's address is inserted as it should be and is expected. I know with some email clients there is a menu item specifically there for responding "to the list" based on whether or not there is a list-header in the header information but that isn't an available option with Thunderbird. Is anyone else seeing this behavior or is there something I'm missing? Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: fwrite/fclose troubles
Al wrote: Seems like this does what you are attempting. if(DEBUG_MODE) // TRUE for debug only { ini_set("display_errors", "on"); //use off if users will see them error_reporting(E_ALL); echo 'Error display and logging on '; } If I understand this correctly this "if" statement directs php to check the main ini config file and if certain conditions are met then it displays the information in the browser window. Useful, but it would seem, at least to me at the moment, that if the script fails before it's even able to get anything to the screen then nothing gets displayed. Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: fwrite/fclose troubles
Al wrote: int file_put_contents ( string $filename, mixed $data [, int $flags [, resource $context]] ) This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file. This native function does it for you Very nice! I wasn't aware of this one. Thank you!! Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: fwrite/fclose troubles
Dave Goodchild wrote: Why are you writing a logging class? Why not use error_log and enable error logging? two reasons actually, 1. learning OOP for PHP, so the more I practice at it the better I get. 2. the logging that's being done with this class is done primarily for debugging during the development phase of the application itself. That way during run-time I can tail the log file and see where a portion of the app is failing if it fails or simply tell me where it's at and what it's doing. Standard error logging wasn't giving me the feedback that I needed at the time and debug logging is a habit I got into when I learned PERL to help tell me where things were failing. Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: fwrite/fclose troubles
Peter Ford wrote: Mark Weaver wrote: Hi all, I've been lurking and reading now for some time, but have decided to come out of the shadows cause I've got an issue that's gonna drive me crazy! I'm developing an application and within this application is a class that is very simple and only serves a singular purpose - to make log entries to help with debugging. Problem is, now I'm debugging the damned logging class that is supposed to be helping me debug the application as I'm putting it together! I've looked and looked all over the place, but I don't seem to be able to find an answer to this problem. The only information that I have found so far deals with permissions and I don't think that's the problem. At first I was getting an access denied error but since setting dir perms and log file perms so that both apache and my user can right to both the directory and the file that one has gone away. Log Directory permissions: /mystuff/logs rwx-rwx-rwx (777) Log file permissions: /mystuff/logs/run.log rwx-rwx-rwx (777) At any rate, the following is the information I'm getting in the apache error_log while working on this particular portion of the application: PHP Warning: fwrite(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 22, PHP Warning: fclose(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 23, The Log class: - class Log{ public $path, $entry, $logfile; public function Log(){} public function setLog($path,$file){ $this->path = $path; $this->logfile = $file; } public function writeLog($entry){ // open the file, in this case the log file $h = "$this->path/$this->logfile"; fopen($h, 'a+'); fwrite($h,$entry); fclose($h); } } Code snippet where attempting to write log entry from program: $pl_log = new Log; $pl_log->setLog($logpath,"run.log"); $usernanme = $_POST['username']; $password = $_POST['secret']; /** * (debugging) logging incoming values from form: */ $pl_log->writeLog("getDateTime(): Incoming values from Login Form: blah...blah...blah\n"); Any help with this would be most appreciated. (be gentle... I'm a PERL program learning PHP OOP) As Stut pointed out, you've misunderstood the difference between a file resource and a file name. Try something like: public function writeLog($entry) { // open the file, in this case the log file $fileName = $this->path.'/'.$this->logfile; $h = fopen($fileName, 'a+'); fwrite($h,$entry); fclose($h); } The file resource that fwrite and fclose need is the *result* of opening the file, not the file name as you were doing. Ideally, you would check the value of $h after the fopen call, to make sure that it had successfully opened the file. Also, I changed the way you were constructing the file name: interpolating the variables in a string is slightly less efficient than concatenating the bits together, and there are possible gotchas when using the $this->variable structure in a string like that. An alternative syntax is to escape the variables with braces: $fileName = "{$this->path}/{$this->logfile}"; Hi Peter, Thank you for that information. I'm rather new at this sort of PHP coding and a bit embarrassed at the amount of OOP I've forgotten since college. Clearly there's a lot to learn. Like this concept of escaping you've mentioned. Until now the only type of "escaping" I'm familiar with from PERL is something like this: \$$some_dollar_amount, but I have a feeling escaping things in PHP oop is quite a bit different. I haven't quite gotten my head around some of the stuff I've been reading about, but it's coming. -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite/fclose troubles
Hi all, I've been lurking and reading now for some time, but have decided to come out of the shadows cause I've got an issue that's gonna drive me crazy! I'm developing an application and within this application is a class that is very simple and only serves a singular purpose - to make log entries to help with debugging. Problem is, now I'm debugging the damned logging class that is supposed to be helping me debug the application as I'm putting it together! I've looked and looked all over the place, but I don't seem to be able to find an answer to this problem. The only information that I have found so far deals with permissions and I don't think that's the problem. At first I was getting an access denied error but since setting dir perms and log file perms so that both apache and my user can right to both the directory and the file that one has gone away. Log Directory permissions: /mystuff/logs rwx-rwx-rwx (777) Log file permissions: /mystuff/logs/run.log rwx-rwx-rwx (777) At any rate, the following is the information I'm getting in the apache error_log while working on this particular portion of the application: PHP Warning: fwrite(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 22, PHP Warning: fclose(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 23, The Log class: - class Log{ public $path, $entry, $logfile; public function Log(){} public function setLog($path,$file){ $this->path = $path; $this->logfile = $file; } public function writeLog($entry){ // open the file, in this case the log file $h = "$this->path/$this->logfile"; fopen($h, 'a+'); fwrite($h,$entry); fclose($h); } } Code snippet where attempting to write log entry from program: $pl_log = new Log; $pl_log->setLog($logpath,"run.log"); $usernanme = $_POST['username']; $password = $_POST['secret']; /** * (debugging) logging incoming values from form: */ $pl_log->writeLog("getDateTime(): Incoming values from Login Form: blah...blah...blah\n"); Any help with this would be most appreciated. (be gentle... I'm a PERL program learning PHP OOP) -- Mark "If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity." == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Alternative to Quickforms - Not Use Tables
Stephen wrote: > Subject says it. > > Is there an open source class for forms that provides for the use of CSS > for the layout of forms? Don't you like HTML_QuickForm, or aren't you aware about the tableless renderer that is available in PEAR? => http://pear.php.net/package/HTML_QuickForm_Renderer_Tableless Regards, Mark -- http://www.markwiesemann.eu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php