php-general Digest 30 Mar 2011 08:17:02 -0000 Issue 7250
php-general Digest 30 Mar 2011 08:17:02 - Issue 7250 Topics (messages 312123 through 312137): Re: Permission Denied - Help Requested 312123 by: Adam Richardson 312126 by: Ethan Rosenberg 312127 by: Al 312128 by: Ethan Rosenberg 312132 by: HallMarc Websites 312134 by: Adam Richardson 312135 by: Ethan Rosenberg 312136 by: Adam Richardson Re: Resizing an image 312124 by: tedd 312137 by: Ross McKay Re: Path question 312125 by: D. Dante Lorenso [DEADLOCK - Code Igniter 312129 by: Tristan 312130 by: Daniel Brown 312131 by: Ashley Sheridan Re: session variable problem 312133 by: markb Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 11:14 PM 3/28/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg mailto: eth...@earthlink.neteth...@earthlink.net wrote: At 01:32 AM 3/28/2011, Hans Åhlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg mailto:eth...@earthlink.net eth...@earthlink.net: Dear List - Thanks for all your help in the past.  Here is another one... I am getting a Permission Denied message when I try to run a PHP script.  I just changed the mode on the directory and the files to 777.  This problem arose when I changed the permissions.  I thought I was solving a problem, because I could not open a file for writing.  I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg **  Hans Åhlin   Tel: +46761488019   icq: 275232967   http://www.kronan-net.com/http://www.kronan-net.com/   irc://http://irc.freenode.net:6667irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan Hi Ethan, Are you using suPHP or suExec? I believe the server chokes on 777 permissions in those cases. Have you checked the permissions in the command line (sorry for the basic question, but just making sure I know what you've already done?) Also, can we see some of the code you're using to handle the file processing? Thanks, Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.comhttp://nephtaliproject.com + Adam - Thanks. 1] Pardon my ignorance but I do not understand this - Are you using suPHP or suExec? suPHP and suExec are two modules that allow PHP to run with the permissions of the user, making it easy to write files to disk. However, suPHP (and I believe suExec, but I can't remember for sure) does not like 777 permissions. 2] I changed the permissions to 755 and the Permission Denied message went away. Check! 3] Have you checked the permissions in the command line? Yes Check! 4] Here are some code snippets: $fptr1 = fopen(chessboard, r+); //this works $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should for($i = 0; $i 8; $i++) { for ($j = 0; $j 8; $j++) fprinf($fptr2, %s , $results[$i][$j]); fprinf($fptr2, \n); } //this never writes, so I am left with an empty file Can you try a simplified form that checks for success along the way? How about something like the code below to see how far it gets (I haven't tested, but it should be close): ?php // let's make sure you see the E_WARNING errors if present for file functions error_reporting(-1); // set var for later $cost = 120.89; if (!($fp = fopen(test.txt, 'w'))) { echo Can't open or create file!; } else if (!($len = fprintf($fp, In the year 3000, a Coke will cost %01.2f, with tax., $cost))) { echo Can't write to file!; } else if (!(fclose($fp))) { echo Can't properly close file!; } ? What do you see if you run this? Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com ---End Message--- ---BeginMessage--- At 01:40 PM 3/29/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 11:14 PM 3/28/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg mailto: eth...@earthlink.neteth...@earthlink.net wrote: At 01:32 AM
php-general Digest 30 Mar 2011 22:46:04 -0000 Issue 7251
php-general Digest 30 Mar 2011 22:46:04 - Issue 7251 Topics (messages 312138 through 312145): Re: Path question 312138 by: Richard Quadling Grasping class / controllers 312139 by: Aleksandar Skodric 312140 by: Ashley Sheridan 312141 by: Aleksandar Skodric Re: Slow sessions. 312142 by: Rob Adams 312145 by: Bostjan Skufca Re: Permission Denied - Help Requested - Solved 312143 by: Ethan Rosenberg Session Variables - Error 312144 by: Ethan Rosenberg Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- On 29 March 2011 19:41, D. Dante Lorenso da...@lorenso.com wrote: On 3/28/11 8:18 PM, Jack wrote: Hello All, Is there a smarter way to do includes by setting up a path or something where I don't have to include /home/domain.com/includes/include_file.php Apparently my path is as shown above, but I would prefer to just put in /includes/include_file.php I wrote about this a long time ago ... perhaps it might help: http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/ Talks about putting your functions into classes and using the autoloader to avoid putting include statements in your code. Might not help if you are loading content which is not just PHP functions/code, but if you haven't evolved this far yet, the read might help you out. -- Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The Zend Framework documentation has some notes regarding of autoloading of resources. http://framework.zend.com/manual/en/learning.autoloading.resources.html You may find some mileage there. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY ---End Message--- ---BeginMessage--- Hi all, I am using Codeigniter framework, tho' I believe my question is more PHP related in general. Problem I am having is following. Codeigniter (CI) uses general class CI_Controller for all functions. I have extended this controller with: abstract class CORE_Controller extends CI_Controller {...}. Then, I also have a RESTFul library which is: class Cpin2_rest {} And, last one is Ion Auth library which states: class Ion_auth {} In the Ion auth, there (should be) is initialization of CI_Controller with: $this-ci = get_instance(); However, $this-ci inherits Cpin2_rest instead of CI_Controller (or CORE_Controller). I really have no idea where have I made a mistake and can't get around this one :( Any help is appreciated! Thanks! Aleks ---End Message--- ---BeginMessage--- Aleksandar Skodric aleksan...@skodric.com wrote: Hi all, I am using Codeigniter framework, tho' I believe my question is more PHP related in general. Problem I am having is following. Codeigniter (CI) uses general class CI_Controller for all functions. I have extended this controller with: abstract class CORE_Controller extends CI_Controller {...}. Then, I also have a RESTFul library which is: class Cpin2_rest {} And, last one is Ion Auth library which states: class Ion_auth {} In the Ion auth, there (should be) is initialization of CI_Controller with: $this-ci = get_instance(); However, $this-ci inherits Cpin2_rest instead of CI_Controller (or CORE_Controller). I really have no idea where have I made a mistake and can't get around this one :( Any help is appreciated! Thanks! Aleks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That's completely CodeIgniter, not php. The mvc framework layout is something used by many languages, but questions about the framework aren't questions you should ask of the language but the framework. Thanks Ash -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. ---End Message--- ---BeginMessage--- Hi, Yes indeed you are correct. Found out that framework was loading libraries from array in specific order, whereby one overrules the next one. Anyway, problem solved by rearranging the order of the array :) Thanks anyway :) On 03/30/2011 04:13 PM, Ashley Sheridan wrote: Aleksandar Skodricaleksan...@skodric.com wrote: Hi all, I am using Codeigniter framework, tho' I believe my question is more PHP related in general. Problem I am having is following. Codeigniter (CI) uses general class CI_Controller for all functions. I have extended this controller with: abstract class CORE_Controller extends CI_Controller {...}. Then, I also have a RESTFul library which is: class Cpin2_rest {} And, last one is Ion Auth library which states: class Ion_auth {} In the Ion auth, there (should be) is initialization of CI_Controller with:
[PHP] Re: Resizing an image
On Tue, 29 Mar 2011 03:21:48 +0300, Andre Polykanine wrote: [...] My questions are: 1. what are the restrictions of ImageCopyResampled()? Can I make a jpg image from a jpg one, and a png image from a png one? And what about gif's? Yes, or even a JPEG from a GIF, or a PNG from a JPEG, etc. But: imagecopyresampled works on image *resources*, which you create either as blank canvases or by reading from files. In your case, you want to create a resource from a file (JPEG, PNG, GIF etc.) and another as a blank canvas into which you will copy the original image, resampled (or resized). See the examples here: http://au2.php.net/manual/en/function.imagecopyresampled.php After the comment // Resample it: * creates a new blank image resource to copy into, i.e. $dst_image * creates an image by reading a file, i.e. $src_image * copies with resampling, i.e. from $src_image to $dst_image 2. I don't need to output the image as the script output, I need to upload it as a file (replacing the uploaded larger file). Could I make it with fwrite and then copy it to the server? All of the examples give header(image/jpeg)... You can write the new image to a file using one of these: http://au2.php.net/manual/en/function.imagepng.php http://au2.php.net/manual/en/function.imagejpeg.php http://au2.php.net/manual/en/function.imagegif.php NB: see the following comments by tim (at) leethost (dot) com, regarding performance of imagecopyresampled vs imagecopyresized: http://au2.php.net/manual/en/function.imagecopyresampled.php#77679 http://au2.php.net/manual/en/function.imagecopyresampled.php#72606 Also check out ImageMagick, if your host provides it (or you can install it): http://au2.php.net/manual/en/book.imagick.php -- Ross McKay, Toronto, NSW Australia Let the laddie play wi the knife - he'll learn - The Wee Book of Calvin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Path question
On 29 March 2011 19:41, D. Dante Lorenso da...@lorenso.com wrote: On 3/28/11 8:18 PM, Jack wrote: Hello All, Is there a smarter way to do includes by setting up a path or something where I don't have to include /home/domain.com/includes/include_file.php Apparently my path is as shown above, but I would prefer to just put in /includes/include_file.php I wrote about this a long time ago ... perhaps it might help: http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/ Talks about putting your functions into classes and using the autoloader to avoid putting include statements in your code. Might not help if you are loading content which is not just PHP functions/code, but if you haven't evolved this far yet, the read might help you out. -- Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The Zend Framework documentation has some notes regarding of autoloading of resources. http://framework.zend.com/manual/en/learning.autoloading.resources.html You may find some mileage there. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Grasping class / controllers
Hi all, I am using Codeigniter framework, tho' I believe my question is more PHP related in general. Problem I am having is following. Codeigniter (CI) uses general class CI_Controller for all functions. I have extended this controller with: abstract class CORE_Controller extends CI_Controller {...}. Then, I also have a RESTFul library which is: class Cpin2_rest {} And, last one is Ion Auth library which states: class Ion_auth {} In the Ion auth, there (should be) is initialization of CI_Controller with: $this-ci = get_instance(); However, $this-ci inherits Cpin2_rest instead of CI_Controller (or CORE_Controller). I really have no idea where have I made a mistake and can't get around this one :( Any help is appreciated! Thanks! Aleks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Grasping class / controllers
Aleksandar Skodric aleksan...@skodric.com wrote: Hi all, I am using Codeigniter framework, tho' I believe my question is more PHP related in general. Problem I am having is following. Codeigniter (CI) uses general class CI_Controller for all functions. I have extended this controller with: abstract class CORE_Controller extends CI_Controller {...}. Then, I also have a RESTFul library which is: class Cpin2_rest {} And, last one is Ion Auth library which states: class Ion_auth {} In the Ion auth, there (should be) is initialization of CI_Controller with: $this-ci = get_instance(); However, $this-ci inherits Cpin2_rest instead of CI_Controller (or CORE_Controller). I really have no idea where have I made a mistake and can't get around this one :( Any help is appreciated! Thanks! Aleks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That's completely CodeIgniter, not php. The mvc framework layout is something used by many languages, but questions about the framework aren't questions you should ask of the language but the framework. Thanks Ash -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Grasping class / controllers
Hi, Yes indeed you are correct. Found out that framework was loading libraries from array in specific order, whereby one overrules the next one. Anyway, problem solved by rearranging the order of the array :) Thanks anyway :) On 03/30/2011 04:13 PM, Ashley Sheridan wrote: Aleksandar Skodricaleksan...@skodric.com wrote: Hi all, I am using Codeigniter framework, tho' I believe my question is more PHP related in general. Problem I am having is following. Codeigniter (CI) uses general class CI_Controller for all functions. I have extended this controller with: abstract class CORE_Controller extends CI_Controller {...}. Then, I also have a RESTFul library which is: class Cpin2_rest {} And, last one is Ion Auth library which states: class Ion_auth {} In the Ion auth, there (should be) is initialization of CI_Controller with: $this-ci = get_instance(); However, $this-ci inherits Cpin2_rest instead of CI_Controller (or CORE_Controller). I really have no idea where have I made a mistake and can't get around this one :( Any help is appreciated! Thanks! Aleks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That's completely CodeIgniter, not php. The mvc framework layout is something used by many languages, but questions about the framework aren't questions you should ask of the language but the framework. Thanks Ash -- With kind regards, Aleksandar Skodric aleksan...@skodric.com +31652612685 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow sessions.
On 3/28/2011 3:40 PM, Bostjan Skufca wrote: Great, please report back if/when you discover the cause. After searching for some information about the error messages I was getting on the file server, I found this: http://www.spinics.net/lists/linux-nfs/msg14679.html I ran 'server nfslock status', and it wasn't even running (rpcbind wasn't recognized as a service). So I started the nfslock service and it immediately fixed the problem. I checked the config, and the service wasn't set to start in level 3, so I turned that on. It's been running for over 24 hours now with no problems. Thanks again Bostjan for the help. I don't think I could have narrowed down the problem without using the strace. -- Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested - Solved
At 12:07 AM 3/30/2011, Adam Richardson wrote: On Tue, Mar 29, 2011 at 8:21 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 05:33 PM 3/29/2011, Adam Richardson wrote: Thanks. What do you see if you run this? Can't open or create file! Ethan OK, If you're running PHP as an Apache module, by default it won't have permissions to write to the directory (this is by design to avoid security issues.) You can do something like the following: 1. Create a directory for writing files outside of your public directory (let's call it uploads.) 2. Change the group associated with the directory to Apache: sudo chgrp -R www-data /home/username/path/to/uploads 3. Change the permissions on the directory so the group has write permissions: sudo chmod -R 2775 /home/username/path/to/uploads 4. Then try the script again. See if that works. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com Thanks - The directory is output_files, which is a subdirectory of /var/www I'm getting a message invalid owner on the command chown Apache output_files. Also with the -R option, and with apache as the owner, also with the chgrp. All these commands are run as root.. Help and advice please. Ethan Hi Ethan, I might be missing something. Did you set up the user Apache? On a standard install for Debian (using apt-get), apache is usually set up as the user/group www-data: http://wiki.debian.org/Apache http://wiki.debian.org/ApacheThe root user typically owns the /var/www directory. I usually set up virtual hosts within one of the other accounts and then change the group on a directory outside of the public directory specifically set aside for uploads and run the commands I sent. However, in the case of your example, I believe you can just run the 2 commands I sent on the /var/www/output_files directory and you should be able to write the files. sudo chgrp -R www-data /var/www/output_files sudo chmod -R 2775 /var/www/output_files Hope this helps, and sorry if I misunderstood something in your configuration or troubleshooting. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com Adam - Thanks. Works beautifully. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Session Variables - Error
Dear List - Thanks for your help. Here is another one. I cannot get my session variables to work. The program will print out a chess board and show the positions of the pieces after the move Here are code snippets: The program is chess2.php ?php session_start(); error_reporting(1); if (!isset($_SESSION['results'])){ //this always returns as not set. print_r($_SESSION); echo starting; $results = array(array(Br, Bn, Bb, Bq, Bk, Bb, Bn, Br),array(Bp, Bp, Bp, Bp, Bp, Bp, Bp, Bp), array(, , , , , , , ),array(, , , , , , , ),array(, , , , , , , ), array(, , , , , , , ),array(Wp, Wp, Wp, Wp, Wp, Wp, Wp, Wp), array(Wr, Wn, Wb, Wq, Wk, Wb, Wn, Wr)); $_SESSION['results'] = $results; print_r($_SESSION); } else { $results = $_SESSION['results']; echo br /starting valuesbr /; print_r($results); } ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; body . . . . . form method=post action=chess2.php Move Frominput type=text name=move_from/inputbr /br / Move To input type=text name=move_to/inputbr /br / input type=submit value=Enter Move/input /form ?php print_r($_POST); $from_before = '$'. $_POST[move_from]; echobr /; echo from_before = ; print_r($from_before); echobr /; $to = '$'. $_POST[move_to]; echo to = $to; //$to = $from; $from = '' ; echobr /; echo from after = $from; echobr /; echo to after = $to; $board = array //Correlation of input array [chessboard] with internal array [results] ( a8 = $results[0][0], b8 = $results[0][1], c8 = $results[0][2], d8 = $results[0][3], e8 = $results[0][4], f8 = $results[0][5], . . . . f1 = $results[7][5], g1 = $results[7][6], h1 = $results[7][7], ); for($i = 0; $i 8; $i++) // I get the correct results here { for ($j = 0; $j 8; $j++) printf(%s , $results[$i][$j]); printf(br /); } $_SESSION['results'] = $results; /body/html Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Slow sessions.
Nice of you to post the resolution of your problem. Glad to hear it is fixed now. Take care, b. On 30 March 2011 17:46, Rob Adams rad...@circlepix.com wrote: On 3/28/2011 3:40 PM, Bostjan Skufca wrote: Great, please report back if/when you discover the cause. After searching for some information about the error messages I was getting on the file server, I found this: http://www.spinics.net/lists/linux-nfs/msg14679.html I ran 'server nfslock status', and it wasn't even running (rpcbind wasn't recognized as a service). So I started the nfslock service and it immediately fixed the problem. I checked the config, and the service wasn't set to start in level 3, so I turned that on. It's been running for over 24 hours now with no problems. Thanks again Bostjan for the help. I don't think I could have narrowed down the problem without using the strace. -- Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions - More Info
Dear List - Thank you for your help in the past. This an update on my session problems. Here is a simple test program. It never increments the session counter; ie, does not detect that $_SESSION has been set. ?php session_start(); ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; html body ?php if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo Views=. $_SESSION['views']; ? /body /html I have no idea what is wrong. I need to make my session variables work so that I can finish a project. Help and advice, please. Ethan Rosenberg MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessions - More Info
On Wed, 2011-03-30 at 19:20 -0400, Ethan Rosenberg wrote: Dear List - Thank you for your help in the past. This an update on my session problems. Here is a simple test program. It never increments the session counter; ie, does not detect that $_SESSION has been set. ?php session_start(); ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; html body ?php if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo Views=. $_SESSION['views']; ? /body /html I have no idea what is wrong. I need to make my session variables work so that I can finish a project. Help and advice, please. Ethan Rosenberg MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] That code works perfectly for me, only thing I would change is the $_SESSION['views']=$_SESSION['views']+1; line to $_SESSION['views']++; for readability. If you're using Firefox, grab the Firebug plugin, which should show you the headers that are being sent to and from the server to the browser. From that, you might get an idea why the sessions don't seem to be working. Just to make sure, turn on display_errors in your php.ini file and restart Apache. Some whitespace (space or new line, for example) before that first ?php line could cause the headers to send and the sessions headers to fail (headers already sent error) which would give you the problems you're seeing now. Also, some editors have issues with the BOM (byte order marker) which could cause white-space to be perceived where there is none. If you are sure there isn't any, then try saving the script with a different character encoding to test if it is the BOM causing problems. -- Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] is there a static constructor?
All, I want to build a config file class that gets called statically. Is there such a thing as a static constructor? Example: class Daz_Config { public static function load() { ... } public static function get($key) { self :: load(); ... } } Daz_Config :: get('myvalue'); I want to call the load function when the class is used for the first time. If no code ever calls Daz_Config :: get(...) then I never want to invoke load() but if it does get called, I only want to call load() once before the class is used further. Anyone know how to do this with calling load() at the top of all the other functions and writing a load() function that exits early if already loaded? -- Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there a static constructor?
There is such thing, but its not called static constructor, its called singleton pattern class SingletonA { public static instance; public SingletonA(){} public static function getInstancce() { if(self::instance != null) { return self::instanc; } return new SingletonA(); } } On 3/31/2011 12:56 AM, D. Dante Lorenso wrote: All, I want to build a config file class that gets called statically. Is there such a thing as a static constructor? Example: class Daz_Config { public static function load() { ... } public static function get($key) { self :: load(); ... } } Daz_Config :: get('myvalue'); I want to call the load function when the class is used for the first time. If no code ever calls Daz_Config :: get(...) then I never want to invoke load() but if it does get called, I only want to call load() once before the class is used further. Anyone know how to do this with calling load() at the top of all the other functions and writing a load() function that exits early if already loaded? -- Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessions - More Info - SOLVED
At 07:28 PM 3/30/2011, Ashley Sheridan wrote: On Wed, 2011-03-30 at 19:20 -0400, Ethan Rosenberg wrote: Dear List - Thank you for your help in the past. This an update on my session problems. Here is a simple test program. It never increments the session counter; ie, does not detect that $_SESSION has been set. ?php session_start(); ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; html body ?php if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo Views=. $_SESSION['views']; ? /body /html I have no idea what is wrong. I need to make my session variables work so that I can finish a project. Help and advice, please. Ethan Rosenberg MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] That code works perfectly for me, only thing I would change is the $_SESSION['views']=$_SESSION['views']+1; line to $_SESSION['views']++; for readability. If you're using Firefox, grab the Firebug plugin, which should show you the headers that are being sent to and from the server to the browser. From that, you might get an idea why the sessions don't seem to be working. Just to make sure, turn on display_errors in your php.ini file and restart Apache. Some whitespace (space or new line, for example) before that first ?php line could cause the headers to send and the sessions headers to fail (headers already sent error) which would give you the problems you're seeing now. Also, some editors have issues with the BOM (byte order marker) which could cause white-space to be perceived where there is none. If you are sure there isn't any, then try saving the script with a different character encoding to test if it is the BOM causing problems. -- Thanks, Ash http://www.ashleysheridan.co.uk ++ Ash - Thanks. What did it was to 1] explicitly declare the character set and 2] close and restart Apache. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there a static constructor?
On 31 March 2011 06:56, D. Dante Lorenso da...@lorenso.com wrote: All, I want to build a config file class that gets called statically. Is there such a thing as a static constructor? Example: class Daz_Config { public static function load() { ... } public static function get($key) { self :: load(); ... } } Daz_Config :: get('myvalue'); I want to call the load function when the class is used for the first time. If no code ever calls Daz_Config :: get(...) then I never want to invoke load() but if it does get called, I only want to call load() once before the class is used further. Anyone know how to do this with calling load() at the top of all the other functions and writing a load() function that exits early if already loaded? The concept doesn't really make sense - a class that never gets instantiated never gets constructed, hence no static constructor (nor a static destructor). You'll have to call your constructor function at the top of the static methods you'll be using - just check inside the constructor if it's been called before or not. Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php