[PHP] Re: [PHP-DEV] [PHP] PHP 5.5.0 final has been released!
I second this - great to see both finally available. Fantastic release! Martin Amps | CIO www.iCracked.com iCracked | Redwood City, CA On Jun 21, 2013, at 2:01 PM, Julian jswprog.mailingli...@gmx.at wrote: Awesome work and the new design for the php.net website is also nice ;) Am 20.06.2013, 23:22 Uhr, schrieb Julien Pauli jpa...@php.net: Hello! The PHP Development Team would like to announce the immediate release of PHP 5.5.0. This release includes a large number of new features and bug fixes. A separate release announcement is also available. For changes in PHP 5.5.0 since PHP 5.4, please consult the PHP 5 ChangeLog. Release Announcement: http://www.php.net/release_5_5_0.php Downloads:http://www.php.net/downloads.php#v5.5 Changelog:http://www.php.net/ChangeLog-5.php#5.5.0 Thanks to all contributors that made this new version available. regards, David Soria Parra Julien Pauli -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML id attribute and arrays
How should I follow the HTML specification while having the passed parameters automatically converted to arrays in PHP? The name attribute, not the id attribute, is used as the key when submitting form values. The name and id attributes do not have to be the same. Thank you, I thought it should be the same (for same reason, maybe compatibility between XHTML and HTML). But could not find anything on the net which states this. So my memories might be corrupted :) Based on first tests, it works (but have not checked the W3C validator yet). Thanks, Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML id attribute and arrays
How should I follow the HTML specification while having the passed parameters automatically converted to arrays in PHP? The name attribute, not the id attribute, is used as the key when submitting form values. The name and id attributes do not have to be the same. Thank you, I thought it should be the same (for same reason, maybe compatibility between XHTML and HTML). But could not find anything on the net which states this. So my memories might be corrupted :) Based on first tests, it works (but have not checked the W3C validator yet). Thanks, Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML id attribute and arrays
The name and id attributes do not have to be the same. Thank you, I thought it should be the same You're probably thinking of: http://www.w3.org/TR/html401/struct/links.html#h-12.2.3 The id and name attributes share the same name space. This means that they cannot both define an anchor with the same name in the same document. It is permissible to use both attributes to specify an element's unique identifier for the following elements: A, APPLET, FORM, FRAME, IFRAME, IMG, and MAP. When both attributes are used on a single element, their values must be identical. Confusing, the name attribute on a form field (input, textarea, select, etc) is different to the name attribute on a a or form element, so this rule does not apply to it. Thank you, Benjamin, for clarification. This sounds like the source of my (bogus) feeling. Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] HTML id attribute and arrays
Hi, PHP converts x[a]=b parameter of the HTTP request as an array named x with its item named a set to value b. So, it seems possible to have the following (X)HTML code: input type=text name=x[a] id=x[a] value=b / Unfortunatelly, HTML specification does not allow neither [ nor ] inside the id attribute. Specifically: * Must begin with a letter A-Z or a-z * Can be followed by: letters (A-Za-z), digits (0-9), hyphens (-), underscores (_), colons (:), and periods (.) * Values are case-sensitive How should I follow the HTML specification while having the passed parameters automatically converted to arrays in PHP? Thank you for any tips, Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Zip files: generate text file in archive on the fly
On 10-10-17 03:55 PM, Dotan Cohen wrote: I need to provide a download of a zip archive containing three files. This is fairly straightforward in PHP so long as one is working with files that already exist. However, I need to customise one of the files (a simple text file) with the user name and other info before zipping. I see no mention of this in the fine manual, and even googling has led me nowhere. Ideas? Am I missing something obvious? Thanks! The solution to this seems to be as simple as grabbing the contents of the file using ZipArchive::getFromName (or equivalent), deleting that file in the archive, modifying the contents, then writing the file using ZipArchive::addFromString. Were ZipArchive::getStream able to handle write operations, I imagine you could modify it this way, but reading the file in for modification is much less issue-laden. I haven't tested it, but you could also simply try using ZipArchive::addFromString without deleting the file first. It may just overwrite the file. Thanks, Justin Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Fatal error: Allowed memory size of XXXXX bytes exhausted
On 10-10-15 04:42 PM, Julien Jabouin wrote: Hello, I have an issu with a script launched by cron. In fact, although i setup php memory_limit to high value (1G or 2Go), i have the same issue. By example with 2G : Output from command /usr/bin/php5 -d memory_limit=2G -f /home/test/www/cron.php .. Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 266257 bytes) in /home/test/www/app/code/local/Ess/M2e/Model/M2eConnector.php on line 423 And with 1G : Output from command /usr/bin/php5 -d memory_limit=1G -f /home/test/www/cron.php .. Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 267717 bytes) in /home/test/www/app/code/local/Ess/M2e/Model/M2eConnector.php on line 423 Result is the same... Do you know why ? This is my php version : /usr/bin/php5 -v PHP 5.2.6-1+lenny4 with Suhosin-Patch 0.9.6.2 (cli) (built: Nov 22 2009 01:50:58) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies On a Debian Lenny, 64 bits version. It would seem that your script is gobbling memory somewhere. Perhaps you've entered an infinite loop which is simply tacking additional elements onto an array constantly. Without seeing the script itself, it's hard to say quite what the problem might be, but what's evident is that your script is eating memory. Thanks, Justin Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Binary data unpacking
Hello everyone, For the past while, I've been working on a class for reading in, modifying and writing out NBT-format files. This particular format is used for the game Minecraft, as some of you may know. Attached is my work so far on this, which is coming close to being a working solution to reading the files in. As well, attached is an example NBT for testing the script. The specification for the NBT format can be found at http://www.minecraft.net/docs/NBT.txt. The issue which I'm having is that PHP's pack and unpack function for binary data does not seem to be complete. Or, at least, it's missing certain functionality which is necessary for what I'm trying to do. It may be a matter of misunderstanding on my part, but I would have expected the pack and unpack function to be able to handle every combination of endianness, signing and machine-specific sizing of each type. Currently, I'm stuck in reading in the TAG_INT type of the NBT format, which is a 32-bit signed short, big-endian, as per the specification. There does not seem to be a packing format code for this data type. How might I go about this? Am I simply missing something about binary data, or is PHP's pack/unpack functionality indeed lacking? And, if the pack and unpack functions are indeed lacking, is it possible to handle binary data without those functions? Thanks, Justin Martin attachment: nbt.class.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Addendum: Binary data unpacking
Sorry, I had forgotten that attachments weren't accepted on the list. My code can be found at http://pastebin.com/6nmR67c3. The test NBT can be found via the NBT specification link. Thanks, Justin Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: zip and mac safari
It works in other browsers and it works when storing it and unzipping in a terminal on OSX. I think it is probably a safari unzipped bug (not sure what tool safari chooses to automatically unzipped without asking). the weird thing is that some people report it works, so maybe they don't store directories or the use a different header for sending the file? If someone has a working solution let me know. Best Martin On Oct 8, 2010, at 17:18, TR Shaw ts...@oitc.com wrote: I don't have any problem in this regard. On Oct 8, 2010, at 11:09 AM, Nathan Rixham wrote: M. Reuter wrote: Hi, does anyone know how to use a php script to zip a folder (with a subfolder) so that safari can open it and not decompresses forever? if it works in other browsers, and not in safari, then it's either a big in safari, in which case report it with an offending zip file - or it's a big in PHP / your zipping process which is handled gracefully by other browsers but not by safari, in which case report it too. Best, Nathan -- 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
[PHP] /status page of php-fpm 5.3.3
Hello, I am using PHP 5.3.3 compiled as PHP-FPM. My Apache is using mod_fastcgi to connect to PHP-FPM and everything works as expected. Unfortunately I don't know how to forward request http://localhost/status to PHP-FPM so that I will see the status page of PHP-FPM. I found only NGINX configuration http://forum.nginx.org/read.php?3,56426,56578. Could you pls. help me to fix this configuration ? FastCgiExternalServer /opt/php-5.3.3/bin/www -socket /dev/shm/fpm-www.socket -idle-timeout 900 ScriptAlias /php-bin/ /opt/php-5.3.3/bin/ Directory /var/www IfModule mod_fastcgi.c FilesMatch \.php$ SetHandler php-fastcgi Action php-fastcgi /php-bin/www /FilesMatch /IfModule /Directory I was trying something like: Location /status SetHandler php-fastcgi Action php-fastcgi /php-bin/www /Location
[PHP] Re: PHP: inexplicable behaviour of pre- and post-increment operators
Mess Dne 27.2.2010 5:01, clanc...@cybec.com.au napsal(a): A week ago Dasn asked a question about converting arrays, and I quoted one possible way of achieving his task, using the operation: $i = 0; while ($i $k) { $b[$a[$i++]] = $a[$i++]; } I added the comment that I have always been wary of using statements like this because I was unsure when the incrementing would occur, so I tried it. I received several CC e-mails replying to this post, including one rather critical comment to the effect that pre-and post-increment were all quite simple, and I really ought to learn the fundamentals before I started trying to do anything elaborate. I posted a reply to these e-mails, but as neither they, nor my reply, or any follow-up discussion ever appeared in the discussion group I will repost this reply. (I did have a power failure at this time, so it is conceivable that any follow-up was lost as a result of a glitch in my mailer, but I think it is more likely that there was a glitch in the discussion group server.) Unfortunately things aren't nearly as simple as this writer believes. The rule I have always used is that if you use the same variable as an index on both sides of an assign statement it is not safe to change the value of the index within the statement. While I have achieved the result I wanted in the example above (using PHP 5.1.6 -- there is no guarantee it would work with other implementations of PHP) the results of doing this in the general case can be quite inexplicable. The particular case which prompted my comment was the one where you want to copy part of one array into the corresponding elements of another array. In accordance with my rule, I normally write: $i = 0; $j=count($a); while ($i $j) { $b[$i] = $a[$i]; ++$i; } It is tempting to try to put the increment into the assignment statement. Clearly the value of $a[$i] has to be read before it can be written to $b[$i], so the logical expression would be: while ($i $j) { $b[$i++] = $a[$i]; } A. However if you try this, you get $b[1] = $a[0], and so on. But if you try the alternative: while ($i $j) { $b[$i] = $a[$i++]; } B. You get $b[0] = $a[1], and so on (as you would expect). Out of curiosity, I then tried: $i = -1; $j=count($a) - 1; while ($i $j) { $b[$i] = $a[++$i]; }C This gave the desired result, and seemed moderately logical. However when I tried: $i = -1; $j=count($a) - 1; while ($i $j) { $b[++$i] = $a[$i]; }D This gave exactly the same result. It is quite impossible to explain the results in cases A and D from the definitions of the pre-and post-increment operator, so I think I will stick to my safe rule! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: My experience with the Forms Generation and Validation class
Guys! Here you both have a really good oportunity. You have contacted each other and say a lot, try to make something of this! Think on what you have done, design your idea, diagram a new set of classes, propose an implementation, work together and write the best form generation tool for all the community. You know you can do it! On Mon, Nov 23, 2009 at 11:54 PM, Manuel Lemos mle...@acm.org wrote: Hello Anonymous complainer, on 11/22/2009 09:23 AM LinuxManMikeC said the following: Just like to share my real world experience with Manuel Lemos' formsgeneration library. http://www.phpclasses.org/formsgeneration At work early this summer we had a project under a tight deadline that needed unified form creation, processing, and error reporting. I had seen Manuel promoting his formsgeneration class on the mailing list and thought I'd look into it to help keep the project within the deadline. I read some positive reviews and comments, the demos looked promising, and the interface seemed good enough. Little did I know the headaches I was in for. I found the configuration structures and interface to be extremely cumbersome, not to mention terribly documented. The interface seems quite inefficient and in most cases its easier just to throw together a form and validation code by hand. Usage was often convoluted, and due to the poor documentation I spent half my effort trying to decipher the interface. And it was difficult to customize in several areas. While it can work well enough in several simple cases, in my opinion it is too cumbersome for any significant form processing project, especially in the business world. I ended up wasting a week of work using the formsgeneration class and had to redo the project making my own form utility code from scratch as I went (which took just as much time and actually worked as intended). Granted I did make the mistake of not giving myself enough evaluation time before the project. I just want caution others to carefully evaluate this code before deciding to use it in their projects, especially since Manuel seems so eager to promote his code (and his web site) whenever the opportunity arises. And in general, to be cautious and take your time when evaluating any 3rd party code for production use. There seems to be a misunderstanding. I am not eager to promote my code. I just look forward to have my classes tested by as many people as possible, so I get as many bug reports and feature improvements as possible. The fact is that I developed this and many other packages for my own purposes. Nowadays I could not live without them because they make me several orders of magnitude more productive than if I had to do it edit HTML code mannually as you said you did. Anyway, maybe this surprises you, but I like criticism. Especially constructive criticisms from people that are able to give specific examples of what they do not like, instead of making vague claims as you did. I like constructive criticism because it helps me making my code better, more useful to others and ultimately to myself. That is why I publish my work as Open Source. Unfortunately you did make any constructive criticism. There seems to be no way to improve my work because you were not specific to what exactly you find cumbersome, even less what you would different to make it less cumbersome. I never claimed it would be perfect for everybody. What is good and productive for some, maybe hard and difficult for others, especially if you try to learn all by yourself and never ask for help. The class has a support forum where you can ask questions and always get a response so you never get stuck. http://www.phpclasses.org/discuss/package/1/ Anyway, I don't know if you ever asked for help because you are using an anonymous identity here. Actually, I wonder why you bother to write a special message anonymously just campaign against the forms class. It makes me wonder if you have other reasons to do it that you may not be revealing unrelated with the class. Anyway, I am not upset. I am just sorry that you made many criticisms without giving real examples to demonstrate your points. That way it will not be helpful to anybody. -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Multiple file upload
On Wed, Nov 11, 2009 at 12:09 PM, Matthew Croud m...@obviousdigital.comwrote: Dear lords of PHP, I have a working image upload script that meets all my needs, My question is I need to upload multiple images using the same form, This is the PHP part I have so far, largely taken from a book: _ $file_dir = /public_html/uploads; foreach($_FILES as $file_name = $file_array) { echo path: .$file_array[tmp_name].br/\n; echo name: .$file_array[name].br/\n; $UploadName = $file_array[name]; if (is_uploaded_file($file_array[tmp_name])) { move_uploaded_file($file_array[tmp_name], $file_dir/.$file_array[name]) or die (Couldn't copy); echo file was moved!br/; } } _ Lets say the HTML from that sends data to this script has 3 upload forms that get send to $_FILES, would I access the data by modifying the following line from the above example: ... foreach($_FILES[' UPLOADIMAGE1 '] as $file_name = $file_array) { ... ... foreach($_FILES[' UPLOADIMAGE2 '] as $file_name = $file_array) { ... ... foreach($_FILES[' UPLOADIMAGE3 '] as $file_name = $file_array) { ... Thanks for reading! Matt Cheezoid -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Your foreach does exactly what you are asking. foreach($_FILES as $file_name = $file_array) The keys in $_FILES are the input type=file / in your form. If you have 3 files... then count( $_FILES ) should be 3 -- Martin Scotta
Re: [PHP] Suppress Right-Click and Hide hover URL
On Mon, Nov 9, 2009 at 4:37 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Mon, 2009-11-09 at 11:33 -0800, Don Wieland wrote: Hi gang, Is there a javascript to Suppress Right-Click and Hide hover URL? I as trying to get this to work with no luck: a href=\aInlet_Proc_Area.php?id={$row1['id']}proc=delete\ onMouseOver=\javascript:window.status=''; return true;\ onClick= \javascript:return confirm('Are you sure you want to REMOVE the assoication of this Area with this Inlet?')\\Remove/a Please let me know if this can be tweaked to work... Thanks! Don Wieland D W D a t a C o n c e p t s ~ d...@dwdataconcepts.com Direct Line - (949) 305-2771 Integrated data solutions to fit your business needs. Need assistance in dialing in your FileMaker solution? Check out our Developer Support Plan at: http://www.dwdataconcepts.com/DevSup.html Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or higher http://www.appointment10.com For a quick overview - http://www.appointment10.com/Appt10_Promo/Overview.html There's no absolute way to stop the right click menu other than develop completely in Flash, but I find this works quite well: body oncontextmenu=return false; The way you are hiding the actual link URL will work for people who navigate solely with their mouse, but you might want to add an onfocus() handler in there as well for people who tab between links. At the end of the day though, none of this will stop someone from viewing your source code for the link, or using a browser plugin like Firebug to determine what it is. Thanks, Ash http://www.ashleysheridan.co.uk Why I will let you to hide things on my browser? The browser is mine... -- Martin Scotta
Re: [PHP] Assignment in Conditional - How are they evaluated?
On Thu, Oct 29, 2009 at 10:58 AM, Mark Skilbeck markskilb...@gmail.comwrote: 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 The code is interpreted this way... $data = somefunc(); if ($data) -- Martin Scotta
Fwd: [PHP] Assignment in Conditional - How are they evaluated?
On Thu, Oct 29, 2009 at 11:11 AM, Robert Cummings rob...@interjinn.comwrote: Ashley Sheridan wrote: On Thu, 2009-10-29 at 13:58 +, Mark Skilbeck wrote: 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)? I believe that it determines if the return value of somefunc() is non-false. It will have the added benefit then that you can use the return value afterwards if it was, for example, not true, but a string or something instead. I do this all the time... an example is the following: ?php if( ($user = get_current_user()) ) { // Yay, we have a user... do something. echo $user-name(); } else { // Handle no current user. echo 'Anonymous'; } ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php There is a situation when common-sense can fail... if( $a $b = do_something() ) The problem here is the precedence between and = The correct sentence will be... if( $a ($b = do_something()) ) C coders knows this behaviour very well. cheers, Martin Scotta -- Martin Scotta
Re: [PHP] Re: UrlRewrite htaccess confusion
You can use a regexp for search and replace in your files. packages.php?category=([^]+)year=([^]+)title=([^]+) The problem is those values are variables on the code. As Shawn said, it is easier to provide some function to create links.If you need to change all links you only change the function and the work is done. cheers, On Thu, Oct 29, 2009 at 2:31 PM, Shawn McKenzie nos...@mckenzies.netwrote: Shawn McKenzie wrote: Rob Gould wrote: You are indeed correct! Absolute URLs for everything, images, css, javascript, and links fixed the issue. Took me forever to change every link in the whole site, but it's happy now. Seems like there ought to be an easier way. There is an easier way. The logic depends upon your app, but create a function that builds and optionally echos URLs for you. It can work out the base url or you can do that when you initialize your app and define it as a constant. It can be as simple or as complex as you need. a href=?php makelink($file, $arrayOfVars); ?Something/a -- or -- echo 'a href=' . makelink($file, $arrayOfVars) . 'Something/a'; Or the simplist approach is to define at constant at app initialization and use it: echo 'a href=' . BASEURL . 'packages/basketball/2010/nba-all-star-gameSomething/a'; -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] [php] INSERT and immediately UPDATE
On Wed, Oct 28, 2009 at 4:21 PM, Allen McCabe allenmcc...@gmail.com wrote: Hey everyone, I have an issue. I need my (employee) users to be able to insert shows into the our MySQL database and simultaneously upload an image file (and store the path in the table). I have accomplished this with a product-based system (adding products and uploading images of the product), and accomplished what I needed because the product name was unique; I used the following statements: $prodName = $_POST['prodName']; $prodDesc = $_POST['prodDesc']; $prodPrice = $_POST['prodPrice']; $query2 = INSERT INTO product (pID, pName) VALUES (NULL, '$prodName');; $result2 = mysql_query($query2) or die(mysql_error()); $query = SELECT pID FROM product WHERE pName = '$prodName';; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die (mysql_error()); $prodID = $row['pID']; I had to select the new product to get the product id to use in the new unique image name. The problem I am facing now, is that with the shows that my users add will have multitple show times; this means non-unique titles. In fact, the only unique identifier is the show id. How can I insert something (leaving the show_id field NULL so that it is auto-assigned the next ID number), and then immediately select it? PHP doesn't seem to be able to immediately select something it has just inserted, perhaps it needs time to process the database update. Here is the code I have now (which does not work): $query2 = INSERT INTO afy_show (show_id, show_title, show_day_w, show_month, show_day_m, show_year, show_time, show_price, show_description, show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}', '{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}', '{$show_time}', '{$show_price}', '{$show_description}', '{$show_comments_1}', '{$show_seats_reqd}');; $result2 = mysql_query($query2) or die(mysql_error()); $query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;; $result3 = mysql_query($query3) or die('Record cannot be located!' . mysql_error()); $row3 = mysql_fetch_array($result3); $show_id = $row3['show_id']; How do I select the item I just inserted to obtain the ID number?? mysql_insert_id http://ar.php.net/manual/en/function.mysql-insert-id.php mysqli-insert_id http://ar.php.net/manual/en/mysqli.insert-id.php -- Martin Scotta
Re: [PHP] How to Get the Sub Classes of a Parent Class
On Tue, Oct 27, 2009 at 9:30 PM, Raymond Irving xwis...@yahoo.com wrote: Hi Martin, This works great but I was hoping that I didn't have to loop through get_declared_classes to find the sub class. Is there a way to get the subclasses using Reflection? For example: $r = new ReflectionClass($name); print_r($r-getSubClasses()); Many Thanks -- *From:* Martin Scotta martinsco...@gmail.com *To:* Raymond Irving xwis...@yahoo.com *Cc:* David Otton phpm...@jawbone.freeserve.co.uk; PHP-General List php-general@lists.php.net *Sent:* Mon, October 26, 2009 8:34:05 PM *Subject:* Re: [PHP] How to Get the Sub Classes of a Parent Class On Mon, Oct 26, 2009 at 10:22 PM, Raymond Irving xwis...@yahoo.comwrote: This works if you know the name of the class. What I'm looking for is a way to get one of the sub classes and initialize it dynamically. From: David Otton phpm...@jawbone.freeserve.co.uk To: Raymond Irving xwis...@yahoo.com Cc: PHP-General List php-general@lists.php.net Sent: Sun, October 25, 2009 10:25:27 AM Subject: Re: [PHP] How to Get the Sub Classes of a Parent Class 2009/10/25 Raymond Irving xwis...@yahoo.com: I want to automatically initialize a specific sub class when the php page is loaded. I'm looking for a solution for php 5.1+ or anything that's optimized for 5.3 You may be able solve this with a simple class_exists() (pseudo-code ahead): if(class_exists($var)) { $class = new $var; } else { $class = new FourOhFour; } This script only works for loaded classes . If your script has autoloader then there is no way to know the declared classes before you declare them. error_reporting( E_ALL | E_STRICT ); Class Foo {} Class Bar extends Foo {} Class Baz extends Foo {} Class Beer extends Bar {} Class Pier extends Bar {} function get_subclasses($class) { $sub = array(); foreach(get_declared_classes() as $name ) { $rClass = new ReflectionClass($name); if( $rClass-isSubclassOf( $class )) { $sub[] = $name; } } return $sub; } print_r( get_subclasses( 'Foo' )); print_r( get_subclasses( 'Bar' )); -- Martin Scotta Hi Raymon I think your main problem here is that you do not know which class you will instantiate. This can lead to undefined behaviour. Maybe you need to re-analyse your solution. cheers, Martin Scotta
Re: [PHP] Array
On Sat, Oct 24, 2009 at 7:59 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Sat, 2009-10-24 at 06:57 -0400, Ron Piggott wrote: The following line gives me an error message when there aren't any values in the array --- how do I accommodate this? Warning: Invalid argument supplied for foreach() foreach ($_SESSION['order'] AS $key = $value ) { Do an isset() on $_SESSION['order'] first to determine if the variable even exists, then do is_array() to determine if it's an array or not before trying to iterate it. My guess is that $_SESSION['order'] isn't an array all the time. Thanks, Ash http://www.ashleysheridan.co.uk foreach works with array and instances. Unless the class implements Transversable, it's public properties are used on the loop. foreach($object as $prop = $value ) //php translates the foreach into something like this... foreach(get_object_vars($object) as $prop = $value ) -- Martin Scotta
Re: [PHP] how call a variable in a text
On Thu, Oct 22, 2009 at 8:40 AM, Thodoris t...@kinetix.gr wrote: I don't think it is about readability: $arr[3] = 'test'; $test = 3; //This prints $test echo This doesn't work: $$arr[3]; //This prints 3 echo This works: ${$arr[3]}; Using the same type way as before in this thread. Above example is a classic one where readability and maintainability deal well together. First of all everything works as expected but obviously you need to know what you need. It is ambiguous to write $$arr[3] ... what do you expect?] No I don't think it is. It produces $test and if this is what you need echo it works nice :-) . Did you mean the variable derived by $arr[3]? echo This works: {$$arr[3]}; since curly brackets make the meaning of the expression explicit, it will be 3 indeed. What is the less ambiguous, readable, easy to maintain, way to obtain that result? echo This works: {${$arr[3]}}; If our aim is to get the variable with name equal to the value of $arr[3] Can you see now why I am talking about good practice? Zero ambiguity, and that's how I like to code Regards Although I totally agree with the way of thinking and it is my style as well. But I though that the point of the thread was to present ways of putting vars inside strings... -- Thodoris PHP knows that before $ and {} there is a variable name so, this is completely correct for PHP ?php // tested on PHP 5.2.6, is this correct on PHP = 5 ? $name = 'Martin'; $var = 'name'; echo $name {$name} ${name} ${ 'name' } ${$var} {$$var} ${${ 'var' }} ,PHP_EOL; // am I missing any other way here? // this is non-sense, but funny :) $a = 'b'; $b = 'c'; $c = 'd'; $d = 'e'; $e = 'a'; $swap = 'a'; for($i=0,$e=rand(1, 100); $i$e; ++$i) $swap = ${ $swap }; echo $swap, PHP_EOL; I feel ${ $var } safer for developers than $$var because I feel it more readable. $$var can be interpreted by a typo for somebody, while with ${ $var } there is no doubt what was the coder intent. -- Martin Scotta
Re: [PHP] How to pronounce PHP code over the phone?
First ask him/her for an email address, and then while you are over the phone send the text by email. This way the other can *instantaneously* read and both of you can talk about the code. On Fri, Oct 16, 2009 at 1:01 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Fri, 2009-10-16 at 18:01 +0200, Dotan Cohen wrote: Wow! Here goes: Open-bracket, dollar item hypen greater-than, get service id, no all one word but with a capital S and I. Open and close brackets, question mark, dollar item again, then a hyphen and greater-than, that get service id and brackets bit again, exactly the same as last time; yes, capital S and I again. Colon, no the colon is the one with two dots, not dot and comma. Dollar item again, then hypen, greater-than, get id, with a capital I. Nope, no service bit this time. Now, open bracket and two closing brackets (I assumed the final two on your example were typos?!). now a semi-colon, yes the one with the comma. That's pretty much how I could foresee me telling someone this on the phone, but to be honest, I'd really prefer an email ;) So it really involves mentioning each character. I was hoping that there would be a shared language for constructs such as - and the like. Thanks. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Not that I know of, and trying to explain any sort of code over the phone is just going to lead to a disaster down the line! Thanks, Ash http://www.ashleysheridan.co.uk -- Martin Scotta
Re: [PHP] Insult my code!
On Wed, Oct 7, 2009 at 8:06 AM, Eric Bauman baum...@livejournal.dk wrote: On 7/10/2009 7:25 PM, David Otton wrote: 2009/10/7 Eric Baumanbaum...@livejournal.dk: Any thoughts would be much appreciated! One observation. Model isn't a synonym for Database Table - models can be anything that encapsulates business logic. Requiring all your models to inherit from Model is probably a bad idea. Thank-you for responding. Out of curiosity, why is this a bad idea? Is it also bad for views controllers? Cheers, Eric -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It's about responsibilities. A Model should encapsulate business logic, and business logic and persistence has nothing in common. Maybe you can code a loader/persister object and let your models rely on it to handle the instances? This way you can decouple you business logic from the data persistence, allowing you to change one of them without introducing bugs into the other. Suppose you need to change your Database engine = change the loader/persister. You need to add/remove/modify some new rules in your business logic = change the models Why don't you allow the view to use the model? This way you have... # the controller is responsible to instantiate the model(s) and view(s) # the model is responsible for the business logic # the view is responsible for the presentation -- Martin Scotta
Re: [PHP] FILTER_VALIDATE_INT - newbie question
Are you using the == operator or === ? maybe that's the problem the function could return false or 0. You need to use the === operator if( false !== ( $value = filter_var($value, FILTER_VALIDATE_INT))) { echo 'I need an Integer'; exit; } echo 'Thanks for the Int'; On Wed, Oct 7, 2009 at 2:13 PM, Ben Dunlap bdun...@agentintellect.comwrote: Also, I think you're getting confused over the zero with exactly what you are asking PHP to do. filter_var() returns true if the filter matches. If the 0 match is returned as a false, then filter_var() will filter_var() actually returns the filtered data if the filter matches, and FALSE if it doesn't. That's the whole point of the filter_XXX functions; to pass a tainted value through a filter and get a clean, safe value out the other end: $tainted = get_user_input(); $clean = filter_var($tainted, [FILTER_CONSTANT]); // now use $clean and never touch $tainted again From the original code above, it looks like the OP was misunderstanding the use of filter_var() and expecting it to return a boolean. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
On Tue, Oct 6, 2009 at 10:28 AM, Paul M Foster pa...@quillandmouse.comwrote: On Tue, Oct 06, 2009 at 08:51:17AM -0400, Bob McConnell wrote: From: Joost [mailto:joost.t.h...@planet.nl] Daevid Vincent wrote: From: Ben Dunlap [mailto:bdun...@agentintellect.com] $a = $a++; I just think this is an ambiguous line of code that wasn't thought through. The presence of the postfix operator makes the result undefined, no matter what language you are using. It will be an accident if you get the results you are expecting. The behavior of the ++ operator is the invention of Kernighan and Ritchie. I don't imagine they ever foresaw anyone doing something as silly as a = a++; except under the rarest of circumstances. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No matter how silly it can looks like (a = a++) it is still completely valid code and it SHOULD run without problems. If we analyse any portion of code (like a simple assigment) out of context it'll always looks like this, just silly (in this case it's really really silly). One point here, that nobody mention, is the side effect. ++$i has a totaly different side effect than $i++ Sometimes you don't need the side effect but in other situations it really matter. Does these behaves exactly? for($i=0; $i10; ++$i) for($i=0; $i10; $i++) There is no side effect on the incremental section because the result is not evaluated. and what about these? $array[ $index++ ] = $elem; $array[ ++$index ] = $elem; You can read more about the side effect at http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29 -- Martin Scotta
Re: [PHP] Re: Class variable value lost
On Wed, Sep 9, 2009 at 12:58 PM, Sumit Sharma sumitp...@gmail.com wrote: What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. -- Forwarded message -- From: Ashley Sheridan a...@ashleysheridan.co.uk Date: Wed, Sep 9, 2009 at 9:14 PM Subject: Re: [PHP] Re: Class variable value lost To: Shawn McKenzie nos...@mckenzies.net Cc: Sumit Sharma sumitp...@gmail.com, PHP General Mailing List php-general@lists.php.net On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote: Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) * use sessions like Shawn recommended If you use sessions, you can store the objects themselves as variables into the session. You should be careful with this, as you may not want too many sessions open with large objects in them as, depending on your server setup, sessions could last quite a while, and there may also be a limit on the amount of memory reserved for sessions. Thanks, Ash http://www.ashleysheridan.co.uk Unless you store the object state your application will not be able to remember it. There is a design pattern specially designed for this, the Memento Pattern ( http://en.wikipedia.org/wiki/Memento_pattern) There are many ways to persist an object: sessions, xml, text files, databases. Pick the one that fits better and you'll be fine. -- Martin Scotta
Re: [PHP] Overwrite value of true or false in PHP
On Mon, Sep 7, 2009 at 4:14 PM, Bobby Pejman bpej...@gmail.com wrote: Hi, I noticed that the following returns a 1. echo (12) ? True : False I was under the impression that true/false are of type boolean and not int. But in php anything other than 0 translates to true, meaning a 1. What I am trying to achieve is for a 1 to be a 1 and a true or false to be a true and false respectively and I do not want to put quotes around the word true/false either because then it is no longer a boolean but string. Is it possible to overwrite php's true/false and declare them as boolean? You often see in C++, some use Define(). Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Yes *true* and *false* are booleans. PHP convert natively different types to boolean in order to help write sentences like this if( $object ) { $object-something(); } while( $data = mysql_fetch_assoc( $resource ) ) { print_r( $data ); } But we you try to print a boolean variable PHP convert it to string: true becomes '1' and false becomes ''. That's why you can't just echo a boolean variable to see the value, but you can rely on var_dump to show this. $bool = true; echo $bool; var_dump( $bool ); $bool =! $bool; echo $bool; var_dump( $bool ); As other languages PHP as an special operator for checking types while comparing values. $a = 'false'; $b = true; var_dump( $a == $b, # -- true $a === $b # -- false ); This happens because values are converted before comparison so, 'false' becomes true. PHP converts everything different to an empty string as *true* This also affect any type of variable. -- Martin Scotta
Re: [PHP] Overwrite value of true or false in PHP
On Mon, Sep 7, 2009 at 4:19 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Mon, 2009-09-07 at 19:14 +, Bobby Pejman wrote: Hi, I noticed that the following returns a 1. echo (12) ? True : False I was under the impression that true/false are of type boolean and not int. But in php anything other than 0 translates to true, meaning a 1. What I am trying to achieve is for a 1 to be a 1 and a true or false to be a true and false respectively and I do not want to put quotes around the word true/false either because then it is no longer a boolean but string. Is it possible to overwrite php's true/false and declare them as boolean? You often see in C++, some use Define(). Thanks. The statement you gave does return a boolean value, but what you are doing is printing the resulting value out. PHP converts the boolean to the nearest printable value, which will be a 1 or 0. If you want it to output the value 'True' or 'False' then you need to output a string value. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I think php convert the boolean variable to string before print its content. That's why... echo true; # prints '1' echo false; # does not prints anything, or prints '' $bool = false; var_dump( (string) $bool, (int) $bool ); -- Martin Scotta
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The PHP_EOL is system dependent. If you want a solution that works on every type of file you have to code it yourself. Here you have a function made some time ago. Maybe you can improve it. If you want the result as a text format you can implode( PHP_EOL, $buffer ) Hope this helps you. function explode($code) { $lines = array(); $buffer = ''; for($i=0, $len = strlen($code); $i$len; ++$i) switch( $code{$i} ) { case \r: case \n: if( $i+1 == $len ) break 2; if( \r == ($next = $code{ $i+1 }) || \n == $next ) { ++$i; } $lines[] = $buffer; $buffer = ''; break; default: $buffer .= $code{$i}; } if( '' !== $buffer ); $lines[] = $buffer; return $lines; } -- Martin Scotta
[PHP] Array references - how to unset() ?
$ARR = array( 'a' = array('b' = 'blah') ); function set($key) { global $ARR; foreach ($key as $i = $k) { if ($i == 0) { $sourcevar = $ARR[$k]; } else { $sourcevar = $sourcevar[$k]; } } // unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how? $sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array references - how to unset() ?
Robert Cummings napsal(a): Martin Zvarík wrote: $ARR = array( 'a' = array('b' = 'blah') ); function set($key) { global $ARR; foreach ($key as $i = $k) { if ($i == 0) { $sourcevar = $ARR[$k]; } else { $sourcevar = $sourcevar[$k]; } } // unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how? $sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') ); unset( $ARR[$k] ) Cheers, Rob. Thanks for reply, but I want to: unset($ARR['a']['b']) Imagine I have this: $KEYS = array('a', 'b', 'c'); And I want to: unset($ARR['a']['b']['c']) It's probably impossible, unless I do something dirty like this: list($rootA, $rootB, $rootC) = $KEYS; if (isset($rootC)) unset($x[$rootA][$rootB][$rootC]); elseif (isset($rootB)) unset($x[$rootA][$rootB]); elseif (isset($rootA)) unset($x[$rootA]); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array references - how to unset() ?
AHA !!! OMG... how come I did not see that!? Instead this: $array = $array[$final]; unset($array); This: unset($array[$final]); 3 AM in the morning... that must be the reason! .) Thanks. This is possible. You're just not giving enough consideration to your exit strategy :) ?php function unset_deep( $array, $keys ) { $final = array_pop( $keys ); foreach( $keys as $key ) { $array = $array[$key]; } unset( $array[$final] ); } $value = array ( 'a' = array ( 'b' = array ( 'c' = 'C', 'd' = 'D', 'e' = 'E' ), ), ); $keys = array('a', 'b', 'c'); unset_deep( $value, $keys ); print_r( $value ); ? Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] LoginShare | How to authenticate once, and login to different websites
On Tue, Sep 1, 2009 at 2:22 AM, Behzad behzad.esl...@gmail.com wrote: Dear list, i'm trying to integrate two php-driven web applications, which both require the user to authenticate using a username and a password. Consider a situation where the user has logged-in to the 1st application. She clicks over a hyper-link, which directs her to the 2nd application. The challenge is to automatically authenticate the user on the 2nd application as well. i'm wondering how? Is it secure to store the username and password in the $_SESSION, and share the session between the two applications? Please let me know what do you think. Thank you in advance, -behzad The best approach to shared sessions are, commonly, database driven, but this can vary depending on your site/network topology. If the two sites are in the same server (and the server is unique) you can share sessions, but this is risky, so you have to develop with this issue in mind, let's say avoid things like this. ?php $_SESSION[ 'something' ] = $somewhat; # you can be, probably, breaking the other app ? If you have more than just one web server, or you are planning to scale it later, then the database driven fits better. You need to share a cookie between both sites, often the session_id, and store the user-session info in a table. If the user logs-in -no matter in which site- an entry on the user-session table is set with the cookie and the user id. When the user logs-out this entry is removed, and the user is not able to navigate to private areas in both sites. Avoid doing things like a form-post from SiteA to SiteB. This kind of things only make holes to your application security system. User credentials MUST not be handled at client-side. Keep them safetily at server-side where you are who decide which action should be taken. -- Martin Scotta
Re: [PHP] IRC and English
On Tue, Sep 1, 2009 at 9:44 AM, tedd tedd.sperl...@gmail.com wrote: At 9:06 PM -0400 8/31/09, Paul M Foster wrote: I'm sorry, but is anyone else annoyed by people who attempt to use IRC jargon on mailing lists? For example, substituting u for you. Oddly enough, I'm seeing this primarily in foreign language posters, not in native English speakers. It's often accompanied by English so broken I don't even bother trying to decypher it, and sometimes an *attitude* (after which, I blacklist the poster). Am I the only one? It's okay if I am. Just wondering. Paul Paul: u r not the only 1. I h8 that 2! l8er :) tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Yo estoy de acuerdo en que respetar el idioma es importante, aunque claro, redactando sobre la computadora tiene ciertos beneficios. Yo, por ejemplo, evito utilizar acentos. Entiendo que pueda molestarles el hecho de las comunes abreviaturas. Eso es lo malo del lenguaje. Es de todos y, al mismo tiempo, de nadie. Nadie puede cambiarlo individualmente, sólo se puede mutar a través de su uso por parte la población, éste va cambiando día a día. Lamentablemente, a mi modo de ver, los mas jóvenes son quienes incurren en este tipo de acciones, y no se reduce solamente al ingles, creo que este fenómeno se da tambien en otros lenguajes (supongo) impulsado por la deficiencia de los métodos de ingreso de texto de dispositivos moviles. ¿Por que utilizo el español? Después de todo hay una lista para ello. El mundo en internet esté en ingles y yo, como hispano-hablante debi pasar por un proceso de varios años para poder lograr entender, hablar y luego redactar en ingles. ¿pasaron ustedes por el mismo proceso para participar en esta lista? Aqui somos muchos, de diferentes paises y culturas, lo importante -a mi modo de ver- es la comunicación, no el medio o la forma. Con lo cual esta recriminación carece totalmente de sentido. Es realmente triste que en una lista de un lenguaje de codigo abierto que pregona la libre participación y el mutuo beneficio a través de compartir conocimiento se realize semejante acotación; aunque mucho mas triste es que una persona oficialmente perteneciente a dicha comunidad se sume a dicho reclamo. Please do not reply that It's a English based list. Or is it allowed to discriminate here? As a non-english speaker I feel very uncomfortable with this thread. With the best intentions for the community, sincerely yours, Martin Scotta Spanish Speaker
Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?
On Fri, Aug 28, 2009 at 9:36 AM, Floyd Resler fres...@adex-intl.com wrote: Another solution would be to use JavaScript. In your process.php script you could do this: printhere script language=javascript window.location.href=index.php /script here; Not strictly a PHP solution but it works. Take care, Floyd On Aug 28, 2009, at 5:34 AM, Ashley Sheridan wrote: On Fri, 2009-08-28 at 17:32 +0800, Keith wrote: I have a user sign up page that collects sign up information from user with form. This form will then be submitted to another process.php page for setting up the user account and send email to the user. After the email been sent out, the user will be directed back to homepage with header(location: index.php). However, error happen with warning: [Cannot modify header information - headers already sent by...] Any workaround for this? Thanks for help! Keith You don't need a workaround. The header(Location...) thing will only work if you have not sent any content to the browser yet. That includes even a single space or newline. It looks like in your process.php page, something is being output to the browser. Are you able to do a code dump of that page? Thanks, Ash http://www.ashleysheridan.co.uk -- 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 Actually there aren't a safe way to make a redirect. Every technique relies on the client-side to perform the redirection. We have 4 alternatives (correct me if I miss anything) to do a safe redirection. 1. header Location 2. meta tag refresh 3. javascript 4. the user We will try every one in the given order... Let's suppose we want to redirect the client to $url... ?php session_write_close(); header( 'Location: '. $url ); # redirect by http header (1) ?html head titleRedirecting.../title !-- redirect by meta tag (2) -- meta http-equiv=refresh content=2;url=?php echo $url? / script type=text/javascript/*![CDATA[*/ // redirect by javascript (3) window.location = '?php echo $url ?'; /*]]*//script /head body pYou are about to be redirected to ?php echo $url? in 2 seconds/p p !-- redirect by user (4) -- a href=?php echo $url? Click here if your browser do not redirect automatically /a /p /body /html ?php exit; ? It's recommended that your use a common redirect method in your site, this is not mandatory but it is a good practice. This simple script also helps to prevent session problems under some evil web-server by closing the session before any output. -- Martin Scotta
Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?
On Fri, Aug 28, 2009 at 10:39 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Fri, 2009-08-28 at 10:34 -0300, Martin Scotta wrote: Actually there aren't a safe way to make a redirect We have 4 alternatives (correct me if I miss anything) to do a safe redirection. Erm wtf?! The best bet is always going with a header() redirect. The only time I've seen that fail is when the developer of the PHP script has made a mistake. The browser should always honor this type of redirect, and you have none of the issues with Javascript turned off, browser plugins blocking redirects, or stupid users etc. Thanks, Ash http://www.ashleysheridan.co.uk What you are is truth if it only applies to computer browsers. There are many clients where the Location header don't work. Curl is a good example, you can determine to follow the Redirect or just skip it. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false) Another example could be mobile phones, especially wml based, do not follow a redirection and you have to provide a click here to redirect link and relies on the user to follow the redirection. Do not trust that your client is always a browser. It could be anything that can open a connection and send a request. Also you can't know who is at the other side. The client can provide fake UA, IP, everything... or can't send anything but the need to make a valid request. -- Martin Scotta
Re: [PHP] Re: Best way to test for form submission?
what about a simple if( count( $_POST )) All you need is to check a form submission On Fri, Aug 28, 2009 at 10:55 AM, Eric blueray2...@yahoo.com wrote: - Original Message - From: Adam Jimerson vend...@charter.net To: php-general@lists.php.net Sent: Friday, August 28, 2009 11:21 AM Subject: [PHP] Re: Best way to test for form submission? On 08/27/2009 11:09 PM, Adam Jimerson wrote: This question might give away the fact that I am a php noob, but I am looking for the best way to test for form submission in PHP. I know in Perl this can be done with if (param) but I don't know if that will work with PHP. I have read the Learning PHP 5 book and the only thing that was mentioned in the book was the use of something like this print pHello .$_POST['username']./p; Sorry copied and pasted the wrong line (long day) if (array_key_exists('username',$_POST)) Here is another way if (isset($_POST['username']) $_POST['username'] != '') { ... I'm sure that this is not the best/recommended way to do this but I'm hoping someone here will point me in the right direction. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Re: Best way to test for form submission?
On Fri, Aug 28, 2009 at 1:59 PM, Ben Dunlap bdun...@agentintellect.comwrote: Well, as far as I'm aware $_SERVER isn't reliable from server to server. That said, I've never had a problem using it. Thanks -- I just looked it up and the manual says: There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI 1.1 specification, so you should be able to expect those. So I guess it wouldn't make sense to rely on anything in $_SERVER if you're building an app for widespread use; e.g., CodeIgniter, as mentioned above. tend to use the $_REQUEST array instead of $_POST or $_GET. You get the benefit of being able to work with both arrays (as well as $_SESSION and $_COOKIE) without any drawbacks. For now I'm inclined against $_REQUEST, since it's not yet supported by filter_input(). I think filter_input() is the bee's knees and I've stopped touching $_POST or $_GET directly since I discovered it. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php When the request is PUT your $_SERVER['REQUEST_METHOD'] detection will fail, but the $_POST will be populated. I think the best way is by count( $_POST ) 0 but this only applies for application/x-www-form-urlencoded forms. Other content-type will not populate the $_POST and therefore need to be validated by other method. PHP provides non-yet-standard HttpRequest class that can handle this perfectly -- Martin Scotta
Re: [PHP] Sockets (reading)
On Wed, Aug 26, 2009 at 5:36 PM, Philip Thompson philthath...@gmail.comwrote: On Aug 26, 2009, at 2:47 PM, Bob McConnell wrote: From: Philip Thompson On Aug 26, 2009, at 11:56 AM, Bob McConnell wrote: From: Philip Thompson During a socket read, why would all the requested number of bytes not get sent? For example, I request 1000 bytes: ?php $data = @socket_read ($socket, 2048, PHP_BINARY_READ); ? This is actually in a loop, so I can get all the data if split up. So, for example, here's how the data split up in 3 iterations (for 1000 bytes): 650 bytes 200 bytes 150 bytes But if I can accept up to 2048 bytes per socket read, why would it not pull all 1000 bytes initially in 1 step? Any thoughts on this would be greatly appreciated! Because that's the way TCP/IP works, by design. TCP is a stream protocol. It guarantees all of the bytes written to one end of the pipe will come out the other end in the same order, but not necessarily in the same groupings. There are a number of buffers along the way that might split them up, as well as limits on packet sizes in the various networks it passed through. So you get what is available in the last buffer when a timer expires, no more, and no less. If you have serialized data that needs to be grouped in specific blocks, your application will need to keep track of those blocks, reassembling or splitting the streamed data as necessary. You could use UDP which does guarantee that packets will be kept together, but that protocol doesn't guarantee delivery. Thank you for your input. Is it guaranteed that at least 1 byte will be sent each time? For example, if I know the data length... ?php $input = ''; for ($i=0; $i$dataLength; $i++) { // Read 1 byte at a time if (($data = @socket_read ($socket, 1, PHP_BINARY_READ)) !== false) { $input .= $data; } } return $input; ? Or is this a completely unreasonable and unnecessary way to get the data? While I have written a lot of code to manage sockets over the years, and coded a UDP/IP stack, I have never done it in PHP. And unfortunately, I don't have time to experiment right now. My boss is waiting for the next product release from me. Getting one byte at a time is somewhat wasteful, as it requires more system calls than necessary. That's a lot of wasted overhead. Whether you always get one or more bytes depends on a number of factors, including whether the calls PHP uses are blocking or non-blocking, plus there may be ways to switch the socket back and forth. Have you tried doing a Google search on the group of PHP functions you expect to use. That should come up with some sample code to look at. Bob McConnell I agree that one byte at a time is wasteful. I'm sure others haven't implemented something along these lines, but I wrote a much more efficient way to make sure I grab all the data of a known length... ?php function readSocketForDataLength ($socket, $len) { $offset = 0; $socketData = ''; while ($offset $len) { if (($data = @socket_read ($socket, $len - $offset, PHP_BINARY_READ)) === false) { return false; } $offset += strlen ($data); $socketData .= $data; } return $socketData; } ? If not all the data is obtained on a read, it will loop until the amount of data is the same as the length requested. This is working quite well. Thanks Bob and the others! ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php socket related: Does this solution work on both, blocking and non-blocking sockets ? And what about different read method? solution related: Does strlen works fine with binary data? Does this snippet work for sending/receiving multibytes strings? -- Martin Scotta
Re: [PHP] Re: How to output a NULL field?
On Thu, Aug 27, 2009 at 9:37 AM, David Stoltz dsto...@shh.org wrote: You're a genius - that works! -Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Wednesday, August 26, 2009 2:02 PM To: Andrew Ballard Cc: Shawn McKenzie; php-general@lists.php.net; David Stoltz Subject: Re: [PHP] Re: How to output a NULL field? One option then, might be to format the result with SQL using a CASE WHEN THEN statement or ISNULL / IFNULL to set it to empty string -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Let me do this simple question... is your Sql Server legal? Then use it. If not, why don't you migrate to an open source alternative? there are a lot of DB you can use, and if you use an open source alternative then it's legal, that's mean you, or your client, do not have to pay for use it. I'm not going to say *that* DB is better that *this* other, this is a matter of taste. -- Martin Scotta
Re: [PHP] __destruct() not called ! we shot us in the foot try the script
__destruct is called only when the object is detroyed. The object is destroyed only when there is no references to it. ?php error_reporting( E_ALL | E_STRICT ); header( 'Content-Type: text/plain' ); class Foo { function __destruct() { echo __METHOD__, PHP_EOL; } } $a = new Foo; $b = $a; # try the script without this line or commented unset( $a ); # no destructor called echo '--', PHP_EOL; unset( $b ); # destructor called! On Mon, Aug 24, 2009 at 8:40 PM, Ralph Deffke ralph_def...@yahoo.de wrote: well I would call this an error in the first view , and some of u where right! and the stuff with the refernce counter seems to be right as well. however I can't see a reason for it as 5.x works through refernces. so unsetting a REFERENCE to the object does not destroy it. How to destroy the object then? ?php abstract class a { public function __construct(){ echo constructingbr; } public function __destruct(){ echo destructingbr; } } class b extends a{ public function doSomething(){ echo I'm doing ...but the reference c to the object is unset()br; } } $c = new b(); $d = $c ; // works $f[] = $c ; // works class e { public static $m; public static function setM( $m ){ self::$m = $m; } } $o = new e(); e::setM( $c ); // works echo unsetting ...br; unset( $c ); $d-doSomething(); echo script ending now ...br; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
[PHP] DOMNode children iteration (was Re: array() returns something weird)
-- Forwarded message -- From: Martin Scotta martinsco...@gmail.com Date: Tue, Aug 25, 2009 at 6:24 PM Subject: Re: [PHP] DOMNode children iteration (was Re: array() returns something weird) To: webmas...@strefarytmu.pl Fatal error: Call to a member function getAttribute() on a non-object in testme.php on line *121* I'm using a Apache/2.2.3 (Win32) PHP/5.2.6 Is the script correctly? I have removed the in the loop and the script returns the attached file. It looks like a bogus bug? 2009/8/24 Szczepan Hołyszewski webmas...@strefarytmu.pl Hi Lars and list! New facts about the strange bug initially diagnosed as array() returning NULL: Firstly, the issue is not really about array() returning null, but about full blown UndefinedBehavior(TM) progressively trashing local variables. It just so happened that I noticed it first with a variable to which array() had been assigned just before things began breaking. Secondly, I proudly present the culprit: things break when I iterate over a DOMNode's children *by reference* using firstChild and nextSibling: for($child=$node-firstChild; $child; $child=$child-nextSibling) { //processing... } No problems if iteration is done by value or by DOMNodeList (childNodes, DOMXPath...). HOWEVER, I still consider this a bug because it destablizes PHP. After the evil loop has finished, things happen that should never happen, like a variable being NULL immediately after being assigned array(). I attach a demonstration. It is a self-contained commented script that you can execute from command line. Also attached is output on my machine. Best regards, Szczepan Hołyszewski -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session variables - help
On Fri, Aug 14, 2009 at 12:25 PM, Allen McCabe allenmcc...@gmail.comwrote: Thank you all for your responses. Mike. I like the ii option better, mostly because I already have most of that in place (ie. order posts to process, and process has editable fields and hidden fields with the remaining complimentary values). Martin suggested I use the following code for my update script (which is posted to via the process page): [code] foreach($_POST as $key = $value) if( '0' == $value || '' == $value ) { /*if*/ session_is_registered( $key ) session_unregister( $key ); } [/code] I am not following the logic on the above code very well, but is this indeed a better option? And is not session_*whatever deprecated? The reason I am using $_SESSION is because it seems that php 6 will use solely this method, and it currently works with php 5. The other reason I am using it is so that I can keep the variables stored elsewhere for whenever I need them; I don't want to have to juggle all the information with POST and hidden inputs unless it will work seamlessly, and be ready for update at a later date (if I move to using a database to store show information, or when php 6 is mainstream). Keep in mind that once I get the update feature working, I need the process page to have a final submit button that will insert the order into a database table AND send a notification email to myself (and an email to the user). Am I setting myself up for failure with this udate order option? I ask because the update feature relies on a form, and are not forms limited to one submit button? Thanks all for your patience! I will work on this today and write back with any further questions I can't figure out on my own. And if anyone has any advice I will be checking my email regularly. Allen On Fri, Aug 14, 2009 at 7:52 AM, Ford, Mike m.f...@leedsmet.ac.uk wrote: -Original Message- From: Allen McCabe [mailto:allenmcc...@gmail.com] Sent: 14 August 2009 06:58 Here is some more complete code: [code = order_process.php] ?php session_start(); // POST ALL $_POST VALUES, CREATE AS VARIABLES IN SESSION foreach($_POST as $k=$v) { $_SESSION[$k]=$v; } $thisPage=AFY; //NAVIGATION PURPOSES include(afyshows.php); //CONTAINS ARRAYS FOR SHOW ENTITIES; POPULATES ORDER FORM ? . . . /pform name=update action=update_order.php method=post !-- HIDDEN FORM VALUES FOR SESSION PURPOSES -- Er wait, no! Sessions and hidden form fields are generally alternative solutions to the same problem -- you shouldn't be putting the same values both in the session and in hidden form fields. In this case, I'm beginning to suspect that the hidden fields are the better solution, but there is a certain amount of personal preference in this. input type=hidden name=School id=School value=?php $_SESSION['School']; ? / input type=hidden name=Grade id=Grade value=?php $_SESSION['Grade']; ? / input type=hidden name=Address id=Address value=?php $_SESSION['Address']; ? / input type=hidden name=City id=City value=?php $_SESSION['City']; ? / input type=hidden name=State id=State value=?php $_SESSION['State']; ? / input type=hidden name=Zip id=Zip size=9 value=?php $_SESSION['Zip']; ? / input type=hidden name=Contact id=Contact value=?php $_SESSION['Contact']; ? / input type=hidden name=Phone id=Phone value=?php $_SESSION['Phone']; ? / input type=hidden name=Fax id=Fax value=?php $_SESSION['Fax']; ? / input type=hidden name=Email id=Email value=?php $_SESSION['Email']; ? / . . . ?php function findTotalCost($b, $c) { $total = $b * $c; return $total; } function writeResultRow($a, $b, $c, $d, $e, $f) { if($a != '') { echo \ntr\n\t; echo td'.$b./tdtd.$c./tdtd.$d./td; echo td.$e./tdtdnbsp;/tdtdinput type='text' value='.$a.' name='.$a.' id='.$a.' size='2' //tdtd=/tdtd\$.$f./td; echo /tr; } } //SETS $Total_show_01 to PRICE * QUANTITY //FORMATS TOTAL //IF A QUANTITY IS ENTERED, WRITES THE ROW WITH CURRENT VARIABLES $Total_show_01 = findTotalCost($shows['show_01']['price'], $_SESSION['show_01_qty']); $Total_show_01_fmtd = number_format($Total_show_01, 2, '.', ''); writeResultRow($_SESSION['show_01_qty'], $shows['show_01']['title'], $shows['show_01']['date'], $shows['show_01']['time'], $shows['show_01']['price'],$Total_show_01_fmtd); //ABOVE LINES REPEATED FOR ALL 38 ENTITIES (show_01 to show_38) ? . . . input name=updates id=updates type=submit value=Update/ [/code] If I'm reading what you want to do correctly, it seems to me there are two obvious approaches to this: (i) Have a single form which posts back to itself, showing all the show information and requested quantities and calculated result fields
Re: [PHP] Re: ini files as config - hidden
2009/8/14 Ben Dunlap bdun...@agentintellect.com 2009/8/14 João Cândido de Souza Neto j...@consultorweb.cnt.br: I think a good solution is to put the ini file out of your html folder so only your scripts can read it. I agree, and I try to do the same, but I've noticed that most open-source CMSes I've looked at (Drupal, Joomla, Textpattern, CMS Made Simple) have always stored database credentials inside of DocumentRoot, by default. Not sure if this is a compromise to allow ease-of-use by less-technical users, or if my insistence on putting this sort of file outside of DocumentRoot is just paranoia (and not the good kind). I'd definitely be interested to hear how others on the list approach this problem. And that's only one part of the equation, if you're on a shared-hosting platform. Are you, or do you have your own server? Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A workaround to this is to simple let the browser get the ini as a php file. What? are you insane? no. it is really easy. 1) Name your ini files .php so, database.ini will be database.php 2) Put in the top of your script this line ;?php exit;? So, when the file is opened as an ini file the semilcolon indicates that it's a comment. But, when the browser call for this file... php just exit's in the first line. Our data will be safe as long as the first line will remains there. -- Martin Scotta
[PHP] PHP_SAPI
Hi all! I'm making a class for handling different things depending on what web server are you running PHP. Can you tell me the output of this script and your environment? ?php echo PHP_OS, PHP_EOL, PHP_SAPI; ? It'll be useful to me to have different values, especially from Windows or IIS ( Please reply this in private, so we keep the list clean, then I'll send the full list ) Is there any documentation about the possible value of PHP_SAPI? I was surfing the web and found this list, but I don't know if it complete: aolserver, apache, apache2filter, apache2handler, caudium, cgi, cgi-fcgi, cli, Continuity, embed, isapi, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux,webjames should I look at php source-code for these values? -- Martin Scotta
[PHP] literal strings vs variable strings
Hi all. Is this going to save me anything? ?php # literal foreach($items as $item) if( 'something' == $item-something() ) return true; ?php # variable $something = 'something'; foreach($items as $item) if( $something == $item-something() ) return true; -- Martin Scotta
Re: [PHP] Re: Re: Re: Design Patterns
Ralph Deffke napsal(a): NO NO NO OOP is the best ever inventet ! see my comments on this list, I will also come up with an pure oop opensource OMS very soon. I just think a dam big pattern catalog like this one is like an elephant chacing mice. I mean I can think of customers asking for a documentation of course of the page u created for them calling the next day asking wher the hell are the code for the page are documented in the 1000 pages of documentation u had to give them. I can think of two of my largest customers with their intranet application with 23000 members and more then 5 hits during working hours where I startet sweating while figting for every 1ms. I'm thinking of people with even more hits a day, they even dont start using PHP so I dont know if thats the right way to blow up with includes and thousands of classes. I deeply and completely agree. Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] design pattern
On Thu, Aug 13, 2009 at 4:04 PM, Ralph Deffke ralph_def...@yahoo.de wrote: so guys why u don't discuss Martins outcome? is there no advice, idears? isn't there a need for it? nobody want to use it? I WANT TO LEARN ralph_def...@yahoo.de -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I was following the entirely conversation, I must admit I wasn't expecting such thread. It is not common to see design patterns applied to PHP applications and, is more common to don't see PHP applications. They are just scripts. Many scripts in a simple folder puts together to do the dirty work. Of course there are many kicking-ass PHP Applications, but they are a minimum portion compared to old-fashioned scripts. So, how do we start writing good quality PHP Applications? That's a very good question, and I don't know the answer, but I think by talking about design patterns we are in a good way. It's true that using design patterns the code will run slower, but it'll be flexible, maintable, and the most important: simple. After all that's what we are looking for, something really simple that make our life as developers happier every day. How do you explain the crescent number of php frameworks for rapid development? PHP core team has taken OOP seriously. Do you note the new SPL objects? The core team creates those objects using many designs patterns. By example the RecursiveDirectoryIterator and it's family use the decorator pattern. Also features such as late static binding were added because a design pattern. I think there will be some separation in the community, those who will stay using scripts and those who will use heavily OOP. I do not know who the dark side will be, xD -- Martin Scotta
Re: [PHP] Calendar Problem
On Wed, Aug 12, 2009 at 10:25 AM, Robert Cummings rob...@interjinn.comwrote: tedd wrote: At 4:08 PM -0400 8/11/09, Robert Cummings wrote: tedd wrote: Hi gang: I want to show the dates for all Fridays +-30 days from a specific date. For example, given today's date (8/11/2009) the Fridays that fall +-30 days are July 17, July 24, July 31, Aug 7, Aug 14, Aug 21, Aug 28, and Sept 4. I'm curious, how would you guys solve this? ?php $fridays = array(); for( $i = -30; $i = 30; $i++ ) { $mod = $i 0 ? $i : '+'.$i; $time = strtotime( $mod.' day' ); if( date( 'D', $time ) == 'Fri' ) { $fridays[] = date( 'Y-m-d', $time ); } } print_r( $fridays ); ? Cheers, Rob. Rob: That's slick -- you never let me down with your simplicity and creativity. My solution was to find the next Friday and then cycle through +-28 days (four weeks) from that date, like so: ?php $fridays = array(); for( $i = 1; $i = 7; $i++ ) { $time = strtotime( $i . ' day' ); if( date( 'D', $time ) == 'Fri' ) { $start = 28 - $i; $end = 28 + $i; } } for( $i = -$start; $i = $end; $i += 7 ) { $time = strtotime( $i . ' day' ); $fridays[] = date( 'Y-m-d', $time ); } print_r( $fridays ); ? Your solution had 61 iterations (for loop) while mind had only 21, so mine's a bit faster. Here's the comparison: http://php1.net/b/fridays/ But I'll use your solution -- it's more elegant. Thanks for the code, tedd I think Shawn McKenzie's is the best. It seems his would take at most 12 iterations. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi all This is my point of view. I try to stay the most legible and simple as possible. @tedd: can you benchmark this script too? usualy legibility performance ?php $fridays = array(); # I'll store the friday here $day = strtotime('-1 month', time() ); # let's start at one month ago while( 5 != date('w', $day)) # advance to a friday $day = strtotime('+1 day', $day); # I'll stop when $day where ahead one month from today $end = strtotime( '+1 month', time() ); do{ $friday[] = date('Y-m-d', $day); # store the friday $day = strtotime('+1 week', $day); # advance one week } while( $day $end ); # job's done! print_r( $friday ); -- Martin Scotta
Re: [PHP] Re: Is select_db necessary?
Wed, Aug 12, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: I agree totally, are we not dicussing speed issues all the time? and then we recommend a code doing an unessesary job on every call? an ANSI selct db in the sql forces any database to run the internal select db because there would be no check if the databse is the current one. because, databasedevelopers can espext some smartness of us, the programmers. its a lot off stuff to do for the database to select a database. for shure, the database leafs that IN OUR hand to avoid to force time consuming server resources. ralph ralph_def...@yahoo.de Colin Guthrie gm...@colin.guthr.ie wrote in message news:h5ug1h$tj...@ger.gmane.org... 'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble: Jay Blanchard wrote: SELECT a.foo, a.bar FROM myDatabase.myTable a WHERE you set other conditions here All that is required is that you establish a connection to a server. If I recall correctly, this will cause issues with replication in MySQL... insofar as you perform amodifying query. [/snip] You're correct with regards to queries that modify on replicated systems. If all you're doing is gathering data then this will work just fine, is somewhat self-documenting (especially in lengthier code containers), and very flexible. It also leaves the selection in the database's hands, and as we almost always say, let the database do the work when it can. I'm interested to know why you consider this to be very flexible and how this leaves the selection in the database's hands? If I were to implement this and they try some destructive testing/demo on a sacrificial database, I'd have to use a whole other server instance (as all the queries would hardcode in the db name). Is it not more flexible if you omit the table name in every single query and specify it once in your bootstrap/connection code? Thus doing tests on other dbs etc. is a pretty simple switch of the connection code. Also telling the db engine what database you want to use in every query is not, IMO, leaving the selection in the the database's hands. Just curious as to the rationale here :) Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ?php $link = mysql_connect( /* settings */); mysql_select_db( 'database', $link); $result = mysql_query( 'SELECT * FROM table', $link ); What SQL was sent to the database? Looking at bin logs I've found this. 1. use database = mysql_select_db 2. use database: SELECT * FROM table = mysql_query The DB is usually a common bottle-neck for most applications. You can have several webservers, but can't do that with the DB... of course, you can have multiples slaves but just 1 master. is this the best way to send queries? What's the better and faster way? -- Martin Scotta
Re: [PHP] Calendar Problem
On Wed, Aug 12, 2009 at 12:07 PM, tedd tedd.sperl...@gmail.com wrote: At 9:50 AM -0500 8/12/09, Shawn McKenzie wrote: tedd wrote: Your solution had 61 iterations (for loop) while mind had only 21, so mine's a bit faster. Here's the comparison: http://php1.net/b/fridays/ But I'll use your solution -- it's more elegant. Thanks for the code, tedd Actually, if you refresh your page you have different winners. When I first visited the page yours was fastest by approximately .001, but on refresh yours is slower by .001. You need to execute the test let's say 100 or 1000 times or more (more is better) and take either the average or I would say the minimum. -- Thanks! But of course -- no one try is definitive, you need many. For example, I wrote a script to show that PHP's rounding function had an upward bias, which it does, but it took thousands of iterations to see it. Not worth the effort to correct. In any event, it's interesting to see how we all approached the problem from different directions. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Well, this was a nice experiment. What do we must learn about this? performance legibility Stuart solutions look that's the faster, but in the other hand Shawn's solution 2 looks the most legible (so far). -- Martin Scotta
Re: [PHP] Re: Is select_db necessary?
On Wed, Aug 12, 2009 at 11:41 AM, Ralph Deffke ralph_def...@yahoo.dewrote: what are telling the logs on that code? ?php $link = mysql_connect( /* settings */); mysql_select_db( 'database', $link); $result = mysql_query( 'SELECT * FROM table', $link ); $result = mysql_query( 'SELECT * FROM anothertable', $link ); $result = mysql_query( 'SELECT * FROM anothertable', $link ); $result = mysql_query( 'SELECT * FROM anothertable', $link ); $result = mysql_query( 'SELECT * FROM anothertable', $link ); $result = mysql_query( 'SELECT * FROM table', $link ); would be interesting to see. I personaly woudn't spend the time on logs, a computer is logical, I try to be logical, and I would try to create code which is logical speedy. I expect the database kernel programmer the same. I think then we are on the secure side. ralph_def...@yahoo.de -- *Von:* Martin Scotta martinsco...@gmail.com *An:* Ralph Deffke ralph_def...@yahoo.de *CC:* php-general@lists.php.net *Gesendet:* Mittwoch, den 12. August 2009, 16:18:01 Uhr *Betreff:* Re: [PHP] Re: Is select_db necessary? Wed, Aug 12, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: I agree totally, are we not dicussing speed issues all the time? and then we recommend a code doing an unessesary job on every call? an ANSI selct db in the sql forces any database to run the internal select db because there would be no check if the databse is the current one. because, databasedevelopers can espext some smartness of us, the programmers. its a lot off stuff to do for the database to select a database. for shure, the database leafs that IN OUR hand to avoid to force time consuming server resources. ralph ralph_def...@yahoo.de Colin Guthrie gm...@colin.guthr.ie wrote in message news:h5ug1h$tj...@ger.gmane.org... 'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble: Jay Blanchard wrote: SELECT a.foo, a.bar FROM myDatabase.myTable a WHERE you set other conditions here All that is required is that you establish a connection to a server. If I recall correctly, this will cause issues with replication in MySQL... insofar as you perform amodifying query. [/snip] You're correct with regards to queries that modify on replicated systems. If all you're doing is gathering data then this will work just fine, is somewhat self-documenting (especially in lengthier code containers), and very flexible. It also leaves the selection in the database's hands, and as we almost always say, let the database do the work when it can. I'm interested to know why you consider this to be very flexible and how this leaves the selection in the database's hands? If I were to implement this and they try some destructive testing/demo on a sacrificial database, I'd have to use a whole other server instance (as all the queries would hardcode in the db name). Is it not more flexible if you omit the table name in every single query and specify it once in your bootstrap/connection code? Thus doing tests on other dbs etc. is a pretty simple switch of the connection code. Also telling the db engine what database you want to use in every query is not, IMO, leaving the selection in the the database's hands. Just curious as to the rationale here :) Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ?php $link = mysql_connect( /* settings */); mysql_select_db( 'database', $link); $result = mysql_query( 'SELECT * FROM table', $link ); What SQL was sent to the database? Looking at bin logs I've found this. 1. use database = mysql_select_db 2. use database: SELECT * FROM table = mysql_query The DB is usually a common bottle-neck for most applications. You can have several webservers, but can't do that with the DB... of course, you can have multiples slaves but just 1 master. is this the best way to send queries? What's the better and faster way? -- Martin Scotta Mysql only stores the SQL in the log when the query affect something in the DB. So, SELECTS do not appear in the binlog. That said, this is the script I have runned $link = mysql_connect( /*settings*/ ); mysql_select_db('devtool', $link); mysql_query( 'TRUNCATE TABLE dev_activities', $link ); mysql_query( 'TRUNCATE TABLE dev_files', $link ); mysql_query( 'INSERT INTO dev_activities VALUES (1, 1)', $link ); mysql_query( 'INSERT INTO dev_files VALUES (1, 1)', $link ); mysql_query( 'INSERT INTO dev_activities VALUES (2, 2)', $link ); mysql_query( 'INSERT INTO dev_files VALUES (2, 2
[PHP] Design Patterns
Hi all! I've written a little Design Patterns Catalog in PHP. The patterns where taken from GoF: *Design Patterns: Elements of Reusable Object-Oriented Software* (ISBN 0-201-63361-2http://en.wikipedia.org/wiki/Special:BookSources/0201633612) This catalog includes (for each pattern): 1. general description 2. class responsibilities 3. UML 4. structural source 5. documentation 6. implementation example Also I've upload the documentation into my site for online purposes. http://martinscotta.com.ar/DesignPatterns/ I don't know if I can send files attached through this list... so, if you want a copy just reply to this message. Any bug, comment, or anything you like to say is welcome! -- Martin Scotta
Re: [PHP] Re: Design Patterns
On Wed, Aug 12, 2009 at 6:27 PM, Ralph Deffke ralph_def...@yahoo.de wrote: it would help if u would tell us what u want to accomplish with this ativity cheers ralph_def...@yahoo.de Martin Scotta martinsco...@gmail.com wrote in message news:6445d94e0908121323x721254c4ja389978d67bc0...@mail.gmail.com... Hi all! I've written a little Design Patterns Catalog in PHP. The patterns where taken from GoF: *Design Patterns: Elements of Reusable Object-Oriented Software* (ISBN 0-201-63361-2http://en.wikipedia.org/wiki/Special:BookSources/0201633612 ) This catalog includes (for each pattern): 1. general description 2. class responsibilities 3. UML 4. structural source 5. documentation 6. implementation example Also I've upload the documentation into my site for online purposes. http://martinscotta.com.ar/DesignPatterns/ I don't know if I can send files attached through this list... so, if you want a copy just reply to this message. Any bug, comment, or anything you like to say is welcome! -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I have uploaded the files into mi site. http://martinscotta.com.ar/DesignPatterns/ -- Martin Scotta
Re: [PHP] how to say inverse your value (to a boolean)?
On Tue, Aug 11, 2009 at 10:09 AM, tedd tedd.sperl...@gmail.com wrote: At 8:46 AM -0400 8/11/09, tedd wrote: At 4:16 PM -0600 8/10/09, John Butler wrote: quick Q: I have this inside a foreach{} that I want to alternate between on and off so I can alternate the background-color of my tr's. $tableRowBGcolorBoolCounter != $tableRowBGcolorBoolCounter; //-boolean on and off I am looking thru' docs and books, but can't remember (nor find now) in PHP how to say inverse your value (to a boolean). ? TIA! -G John: Here's my solution: http://webbytedd.com/b/color-rows/ Cheers, tedd However, my solution (after reading others) is for an alternating row color (a boolean operation). The problem was NOT making every third row a different color or making every row a different color. Those problems would require different solutions. There is nothing wrong with embedding php within html, which is really a misnomer because it's the php interpreter that's sending the resultant html to the browser. It is not sending php snip-its for the browser to handle. So, embedding code such as: tr class=row?php echo($i++ 1);? Is a valid statement that works. It would be nice if you initialize the $i value, but it will work either way. My solution, provided via the above link, is a valid solution. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php A change request just came in - the interaction designer wants every third line to have a grey background, instead of every second line. # before was $styles = array( 'even', 'odd' ); # after new requirements it is... $styles = array( 'white', 'white', 'gray' ); foreach($items as $item) { printf( 'li class=%s%s/li', current( $styles ), $item ); next( $styles ) or reset( $styles ); } The simplest solution is always the best choice. This provides maintainability and flexibility to changes ( that we don't know yet ) -- Martin Scotta
[PHP] Single quoted strings (was: ereg_replace to preg_replace translation)
On Tue, Aug 11, 2009 at 12:21 PM, Ford, Mike m.f...@leedsmet.ac.uk wrote: -Original Message- From: m a r k u s [mailto:queribus2...@hotmail.com] Sent: 11 August 2009 15:34 I see that from PHP 5.3.0 ereg_replace() function is deprecated and throws a warning. I would like to use the preg_replace() function as an alternative of ereg_replace() function but... can't undestand the \n#[^\n]*\n expression. $sql = ereg_replace(\n#[^\n]*\n, , $sql); Generally the only change you need to make for transition from ereg to preg (for simple expressions, anyway) is the addition of pattern delimiters. So the above becomes, for example: $sql = preg_replace(|\n#[^\n]*\n|, , $sql); Although I would argue that those \ characters should be escaped (and should have been even for ereg), so the more correct version of this is: $sql = preg_replace(|\\n#[^\\n]*\\n|, , $sql); Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You can use a single quote string (instead of escape the \n) The result is the same, but is more legible. $sql = preg_replace('|\n#[^\n]*\n|', '', $sql); Personally I try to not use double quoted. PHP parses single quoted very much faster. # for this echo Hi, $name, wellcome $home; # I use echo 'Hi, ', $name, ', wellcome ', $home; # or printf( 'Hi, %s, wellcome %s', $name, $home ); And of course, this is a matter of taste! -- Martin Scotta
Re: [PHP] reason for a Notice:.. on one site but not another? (Same code.)
Why do you all always use isset? Why do you don't use array_key_exists instead? is it a more semantic solution? ?php $key = 'UserWishesDateRange'; # just to make statement shorter if( array_key_exists($key, $_POST ) 'T' == $_POST[$key] ) { echo ' the key exists... and it is a T ''; } *isset*: Determine if a variable is set and is not NULL* array_key_exists: *Checks if the given key or index exists in the array On Mon, Aug 10, 2009 at 1:42 PM, John Butler govinda.webdnat...@gmail.comwrote: If you switch it around you'll get a notice because the IF evaluates from left to right. So you just want to make sure you check isset() first. This would throw a notice: if($_POST['UserWishesDateRange'] == 'T' isset($_POST['UserWishesDateRange'])) { Aha! That must be what I tried and was still getting the notice! Interesting that it works (without notice) if we check against the isset () one first. It makes if() look more intelligent that I would think... as if it saying, good now that we've established that the var isset, now is it also equal to '___'., as opposed to just, is var set, and is var equal to ___'. -- Martin Scotta
Re: [PHP] reason for a Notice:.. on one site but not another? (Same code.)
This intelligence is given by the laziness of the operator. $res = a() b(); # if a() is false then b() does not evaluate $res = a() b(); # b() evaluates no matter a()'s result so, order matters. On Mon, Aug 10, 2009 at 3:29 PM, Andrew Ballard aball...@gmail.com wrote: On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffkeralph_def...@yahoo.de wrote: this is not intelligence its just pure math. the '' says if BOTH expressions are true then the whole expression is true. so if the first one is false, the whole is false, why checking the next one in the underlaying C it would be something like this { if ( expression == false ) return false; if ( expression == false) return false; return true; } ralph ralph_def...@yahoo.de That's logically correct, and while PHP does implement this short-circuit logic, not all languages do. In that regard, I appreciate what John meant by saying it makes it look more intelligent. Some languages evaluate each of the conditions to their respective boolean results before evaluating the logical operators. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] how to say inverse your value (to a boolean)?
You can do this... for( $b=true; your-statement; $b = !$b ) { your-code } I usually use this solution $types = array( 'one', 'two' ); foreach( $list as $item ) # -- your set of (many) items { echo current( $types ); # -- this prints the current class # code next( $types ) or reset( $types ); # and this do the magic } Hey! look, this solution can work with more than 2 types... try it with many types: $types = array( 'one', 'two', three', 'four' ); On Mon, Aug 10, 2009 at 7:16 PM, John Butler govinda.webdnat...@gmail.comwrote: quick Q: I have this inside a foreach{} that I want to alternate between on and off so I can alternate the background-color of my tr's. $tableRowBGcolorBoolCounter != $tableRowBGcolorBoolCounter; //-boolean on and off I am looking thru' docs and books, but can't remember (nor find now) in PHP how to say inverse your value (to a boolean). ? TIA! -G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] how to say inverse your value (to a boolean)?
Use... $dr = !$dr if you want Notice: Undefined variable: dr All variables MUST be initialized before using. If you PHP does not complains about it you should read about error_reporting On Mon, Aug 10, 2009 at 8:18 PM, Daevid Vincent dae...@daevid.com wrote: NO! For the love of God and all that is holy, don't do that accumulator / mod hack. That's so 1980's. And why make the CPU do all that math for every row... Just do this. It's quick and simple: CSS: .dataRow1 { background-color: #DFDFDF; } .dataRow2 { background-color: #FF; } foreach ($foo_array as $foo) { ?tr class=?= ($dr = !$dr) ? dataRow1 : dataRow2 ?td?= $foo ?/td/tr?php } No need to initialize $dr as by default PHP will make it a boolean false, then each itteration, it will toggle true/false and substitute the CSS class -Original Message- From: Jim Lucas [mailto:li...@cmsws.com] Sent: Monday, August 10, 2009 4:03 PM To: John Butler Cc: PHP-General List Subject: Re: [PHP] how to say inverse your value (to a boolean)? John Butler wrote: quick Q: I have this inside a foreach{} that I want to alternate between on and off so I can alternate the background-color of my tr's. $tableRowBGcolorBoolCounter != $tableRowBGcolorBoolCounter; //-boolean on and off I am looking thru' docs and books, but can't remember (nor find now) in PHP how to say inverse your value (to a boolean). ? TIA! -G ?php $arr = range(1, 10); $i = 0; foreach ( $arr AS $row ) { $row_color = ( ( $i++ % 2 ) ? 'green' : 'red'); echo $row_color; } ? -- 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 -- Martin Scotta
Re: [PHP] Displaying user data and picture
http://php.net/header take a look at the comments sections, there are a lot of examples of how to send an image to a browser, only think that instead of a file your are using a blob database field On Thu, Aug 6, 2009 at 10:45 AM, Ralph Deffkeralph_def...@yahoo.de wrote: hi there, u want help? break down ur question to the point, none is going to downlod unknown zips searching for the spot. its fun to help, but its for free, so make it easier for us to help u u r lucky that i'm sick at the moment and a bit bored, but anyway i'm not downloading a zip. however, the most common error for newbies on that issue is, that thex don't pay attention to the fact that a browser treats a picture as a separate file to download. u can store pictures in a databas, and a blob field in mysql is the right thing, however u have to have a little php scrip, however with a .png extention to get the browser displaying the picture. u have to tell apache that a .png (or jpeg, gif etc) extention is to be parsed by the php interpreter where u then can place ur database retrival of the picture. in that script u then have to make shure ur are sending the right header out. to give u all the details is worth some time and time is money. the amount of documentation to figure out the details is not small. start with some w3c and rfc standard to get the clue. regards ralph ralph_def...@yahoo.de nashrul anas_a...@yahoo.com wrote in message news:24839092.p...@talk.nabble.com... I am new to php... I try to make a php page that displays form submitted data and image. There are 3 php files, tampil_tamu_admin.php, edit_tamu.php and display_img.php. The user lists are displayed in the tampil_tamu_admin.php, and when the user clicks one record, it shows edit page (edit_tamu.php) that display user data and picture. (edit_tamu.php file includes img tag that calls display_img.php with user id) The problem is the user data is displayed but the image is not displayed... How can I display this image ? The codes are attached Thanks http://www.nabble.com/file/p24839092/guest-book.rar guest-book.rar http://www.nabble.com/file/p24839092/guest-book.zip guest-book.zip -- View this message in context: http://www.nabble.com/Displaying-user-data-and-picture-tp24839092p24839092.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 6 and MySQL 5 for Dynamic Web Sites Book
On Thu, Aug 6, 2009 at 1:59 PM, Eddie Drapkin oorza...@gmail.com wrote: On Thu, Aug 6, 2009 at 12:24 PM, Tony Marstont...@marston-home.demon.co.uk wrote: Eddie Drapkin oorza...@gmail.com wrote in message news:68de37340908060841x129a9096w6c0907f85614c...@mail.gmail.com... snip Does no one see the inherent issues in buying a book about a not-feature-complete version of the language? PHP 6 does not exist yet, and no hosting companies provide it as an option, so describing existing versions of PHP as not-feature-complete is a bit premature. As the book is simply an update to his original version which was published in 2003, and again in 2005, it is about using PHP and MySQL to build a dynamic web site, and as such every version is still perfectly valid and useful to the novice programmer. This not a book which is supposed to describe every possible feature within the PHP language as it is not necessary to use every possible feature in order to build a dynamic website. -- Tony Marston http://www.tonymarston.net http://www.radicore.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I meant that PHP6 was not feature-complete in that the spec of PHP6 will change before it's released. We don't know at this point what will or will not be included in PHP6 and writing a book about an incomplete version of the language seems silly. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That probably seems silly to you... but there are authors (and editors) who thinks writing a book about the last version of PHP is a good business, and don't care if the language is full featured or even released It is up to you to read the book or not. -- Martin Scotta
Re: [PHP] PHP 6 and MySQL 5 for Dynamic Web Sites Book
You all are speaking about the same... But there is a good point you all are missing... It has non sense to read a book about php6... but what about to sell a php6 book? Hey! we are up to today! All the php5 book's are outdated. That's probably what editors thought when they decide to edit that book. Anyway... I'll like to read a book of how php6 was born, what was the challenges, and how the community have worked to get this product in the market. There must be someone that has anything to say about this? That'll be a very interesant book to read On Thu, Aug 6, 2009 at 4:33 PM, Eddie Drapkin oorza...@gmail.com wrote: On Thu, Aug 6, 2009 at 3:22 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Thu, 2009-08-06 at 20:16 +0100, Tony Marston wrote: Don't be so pedantic. PHP 6 does not exist in a live, production-ready version. It is still under development and has not even reached the beta stage. Anyone who writes a book which documents the features of PHP 6 is being very premature as those features may change at any moment. The features will not be frozen until the first GA release. -- Tony Marston http://www.tonymarston.net http://www.radicore.org Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1249585209.2818.0.ca...@localhost... On Thu, 2009-08-06 at 17:24 +0100, Tony Marston wrote: PHP 6 does not exist yet, Funny, that's not what the PHP site says: http://snaps.php.net/ Thanks, Ash http://www.ashleysheridan.co.uk What I'm trying to say is that writing a book is not premature, as the feature list is likely not to change much, if at all. So what makes you think it is premature of the authors? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I'd be surprised if the feature stays the same at all. Just take a look at http://wiki.php.net/summits/pdmnotesmay09 and see what they're cooking up. Like I said before, PHP6 isn't feature-complete, and I don't suspect it's near it either, so it's definitely way premature to write a book on PHP6 and silly to buy one. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Warning: OutsourcingRoom.com
Nobody can actually do anything. This happen all the time. Sites like facebook or myspace send invitations to all your mail's contacts, but that's not the problem. What I can't understand is why do they do pre-signup just you for the easy of you. I have _created_ an account just to edit my personal data, that's nonsense!!! If you give your contact info you are allowing this kind of issues, but if you don't... well, you can't use internet if you don't. On Wed, Aug 5, 2009 at 10:56 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Wed, 2009-08-05 at 09:54 -0400, Eric Butera wrote: On Wed, Aug 5, 2009 at 3:06 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-08-04 at 20:49 -0700, Steve wrote: Daniel Brown wrote: Just as a heads-up, in case you guys weren't yet aware (cross-posting): Elance.com was the victim of an SQL injection attack earlier this summer (they apparently missed our billions of threads on sanity). According to their folks, only names, company names, phone numbers, and email addresses were taken. Whether or not that's true, I don't know, but that's beyond the scope of this warning. The most recent attempt to get more of your personal information comes from a (*possibly* legitimate) website named OutsourcingRoom.com. If you have been a member of Elance, you may have already received the message from OSR that claims that you signed up with them, and gives you a username and password. Now, I'm not here to tell you guys and gals what to do, but taking the facts into account - the stealing of private information by breeching the security of a competitor - it's entirely up to you as to whether or not you'll consider OSR a trustworthy business. Chances are, they'll not only charge you for using the service, but will also be so kind as to reuse (or redistribute) your private and financial information, should you be willing to give it to them. We've already received numerous hits on our network for OutsourcingRoom.com and one or two other shoddy attempts to gain more information. Today the emails seem to have picked up significantly, and appear to be not only valid, but professionally-crafted. Thankfully, we were anticipating such, after being alerted to the attack by Elance themselves. Perhaps a bit embarrassing for them, but it was a good move to mitigate the damage post-fact, in my opinion. That's it. Just trying to keep everyone from getting scammed and screwed. For more information, check Google, as always. ;-P I got that email. I was wondering what that was about. Thanks for the info! Well, I try not to give out my details to too many people each month, and this month they were beat to it by a nice fellow in Nigeria who I'm helping out by letting him put some money into my account. Next month I had originally planned to invest in those berrys everyone is talking about and some watches, and then after that, I need to update my account details on Ebay (I forgot I even had an account with them!) as they keep asking me to go and do it because of a security update they've made. Ho hum... Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Har har. This was not a mindless 411 scam. It is a bit different when an actual site people use gets hacked and their personal information stolen. I too received one of these emails and it was very convincing. It has my exact username from the Elance site and was crafted in such a way that it seems this new site was a partner with Elance somehow. -- http://www.ericbutera.us/ Is there nothing that anybody can actually do about this? Where is the new company based? Are there laws in that country about this sort of thing? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning: OutsourcingRoom.com
What we can do is make a Report Web Forgery for this site. If you use Firefox there is an option in the help menu. Also you can report to search engines like Google or Yahoo (that's what I did) well... in this thread we are doing something On Wed, Aug 5, 2009 at 11:14 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Wed, 2009-08-05 at 11:10 -0300, Martin Scotta wrote: Nobody can actually do anything. This happen all the time. Sites like facebook or myspace send invitations to all your mail's contacts, but that's not the problem. What I can't understand is why do they do pre-signup just you for the easy of you. I have _created_ an account just to edit my personal data, that's nonsense!!! If you give your contact info you are allowing this kind of issues, but if you don't... well, you can't use internet if you don't. On Wed, Aug 5, 2009 at 10:56 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Wed, 2009-08-05 at 09:54 -0400, Eric Butera wrote: On Wed, Aug 5, 2009 at 3:06 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-08-04 at 20:49 -0700, Steve wrote: Daniel Brown wrote: Just as a heads-up, in case you guys weren't yet aware (cross-posting): Elance.com was the victim of an SQL injection attack earlier this summer (they apparently missed our billions of threads on sanity). According to their folks, only names, company names, phone numbers, and email addresses were taken. Whether or not that's true, I don't know, but that's beyond the scope of this warning. The most recent attempt to get more of your personal information comes from a (*possibly* legitimate) website named OutsourcingRoom.com. If you have been a member of Elance, you may have already received the message from OSR that claims that you signed up with them, and gives you a username and password. Now, I'm not here to tell you guys and gals what to do, but taking the facts into account - the stealing of private information by breeching the security of a competitor - it's entirely up to you as to whether or not you'll consider OSR a trustworthy business. Chances are, they'll not only charge you for using the service, but will also be so kind as to reuse (or redistribute) your private and financial information, should you be willing to give it to them. We've already received numerous hits on our network for OutsourcingRoom.com and one or two other shoddy attempts to gain more information. Today the emails seem to have picked up significantly, and appear to be not only valid, but professionally-crafted. Thankfully, we were anticipating such, after being alerted to the attack by Elance themselves. Perhaps a bit embarrassing for them, but it was a good move to mitigate the damage post-fact, in my opinion. That's it. Just trying to keep everyone from getting scammed and screwed. For more information, check Google, as always. ;-P I got that email. I was wondering what that was about. Thanks for the info! Well, I try not to give out my details to too many people each month, and this month they were beat to it by a nice fellow in Nigeria who I'm helping out by letting him put some money into my account. Next month I had originally planned to invest in those berrys everyone is talking about and some watches, and then after that, I need to update my account details on Ebay (I forgot I even had an account with them!) as they keep asking me to go and do it because of a security update they've made. Ho hum... Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Har har. This was not a mindless 411 scam. It is a bit different when an actual site people use gets hacked and their personal information stolen. I too received one of these emails and it was very convincing. It has my exact username from the Elance site and was crafted in such a way that it seems this new site was a partner with Elance somehow. -- http://www.ericbutera.us/ Is there nothing that anybody can actually do about this? Where is the new company based? Are there laws in that country about this sort of thing? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta Nicely said, but doesn't answer the question. Sites like that will send out emails all the time as invites, because they have the permission of whoever they are sending the emails on behalf of, hence why they can access the contacts list. This is a different situation, where the site was hacked, and the company is not only sending out invite links to all the email
Re: [PHP] navigation include not functioning
I think you are looking for something like this: $page = array_key_exists( 'page', $_GET ) ? GET['page'] : 'index'; Then you MUST sanitize the $page variable. I often use the querystring to wrapp the module you are requesting: www.example.org/?path/to/molude (note that .htaccess is required) # the you can access by echo $path = $_SERVER['QUERY_STRING']; On Wed, Aug 5, 2009 at 2:19 PM, Allen McCabeallenmcc...@gmail.com wrote: Sure. When I load my site, default.php loads ( displaying: http://uplinkdesign.hostzi.com/ in the browser as expected). $thisPage is set to about via: ?php if (!isset($thisPage)) { $thisPage=about; } else { $thisPage = addslashes($_GET['page']); } ? in the head tags. I am seeing this: The first 2 includes work just fine, loading to proper middle section and proper right-hand-side page content, the navigation include also loads, but all the of tabs (background images) are the currentpage image, as opposed to not, as they should be (the the exception of the About Us background image). It seems that $thisPage is equal to all four values, so all the if statements within navigation tell PHP to load the current page image for all 4 links. Does this help? On Wed, Aug 5, 2009 at 10:10 AM, Jerry Wilborn jerrywilb...@gmail.comwrote: I'm having trouble understanding your description of the problem. Can you tell us what you're seeing and what you expect to see? Jerry Wilborn jerrywilb...@gmail.com On Wed, Aug 5, 2009 at 12:00 PM, Allen McCabe allenmcc...@gmail.comwrote: I am trying to generate pages by importing content in includes, and using my navigation include to tell PHP to replace a $thisPage variable which all the includes use ?php include('phpincludes/' . $thisPage . '.php') ? The idea behind it (I know tons of people do it, but I'm new to this concept), is to have a 'layout' page where only a variable changes using $_GET on an href (index.php?page=services or index.php?page=about) to load the new 'pages'. PROBLEM: All my links are displaying the current page state, and links are not building around the link text (hrefs are built conditionally with if $thisPage != services then build the link, otherwise leave it as normal text). Same thing with the background image behind the link text (to indicate a page's current position). If the condition is not true, all the links (except the true current 'page') are supposed reload index.php and pass a variable to itself to place into $thisPage using href=index.php?page= (after which I have a variable which stores about or services within the if statement near the link text. If this sounds like something you are familiar with (former issues and whatnot) please let me know what I'm doing wrong. I would be happy to give you any code you want to look at (index.php or navigation.php, whatever). Thanks again for your help PHP gurus! -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] navigation include not functioning
a predefined list of all modules which can be included. Else, there is some nasty things like: ?page=../index.php (infinity recurssion) ?page=http://otherhost.com/hacker. (inclusion of malicious script) and so on. On Wed, Aug 5, 2009 at 10:10 AM, Jerry Wilborn jerrywilb...@gmail.com wrote: Look I'm having trouble understanding your description of the problem. Can you tell us what you're seeing and what you expect to see? Jerry Wilborn jerrywilb...@gmail.com On Wed, Aug 5, 2009 at 12:00 PM, Allen McCabe allenmcc...@gmail.com wrote: I am trying to generate pages by importing content in includes, and using my navigation include to tell PHP to replace a $thisPage variable which all the includes use ?php include('phpincludes/' . $thisPage . '.php') ? The idea behind it (I know tons of people do it, but I'm new to this concept), is to have a 'layout' page where only a variable changes using $_GET on an href (index.php?page=services or index.php?page=about) to load the new 'pages'. PROBLEM: All my links are displaying the current page state, and links are not building around the link text (hrefs are built conditionally with if $thisPage != services then build the link, otherwise leave it as normal text). Same thing with the background image behind the link text (to indicate a page's current position). If the condition is not true, all the links (except the true current 'page') are supposed reload index.php and pass a variable to itself to place into $thisPage using href=index.php?page= (after which I have a variable which stores about or services within the if statement near the link text. If this sounds like something you are familiar with (former issues and whatnot) please let me know what I'm doing wrong. I would be happy to give you any code you want to look at (index.php or navigation.php, whatever). Thanks again for your help PHP gurus! -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] dynamically naming PHP vars on the fly?
You can use variable variables ?php $nombre = 'Martin'; $name = 'nombre'; echo $$name; # === Martin You can make more complicated statements with this technique. $var1 = 'apple'; ${ 'Fruit_' . $var1 } = 'organic'; echo $Fruit_apple; // here you are When your statements are complex use the ${ statement } syntax. I often use this for hidden global variables. ${ 'try to use this variable directly' } = 'something'; print_r( get_defined_vars() ); # [try to use this variable directly] = something On Wed, Aug 5, 2009 at 7:17 PM, Govindagovinda.webdnat...@gmail.com wrote: HI all One thing I have been working around but now would love to just do it finally (and save workaround/longer code hassle) is when: I need to be able to create a variable (name it, and assign it a value) whose name is built up from a fixed string concatenated with another string which comes from the value of another (already set) variable. Ie: I want to do this: (I am just assuming it won't work; I haven't even tried it yet) $var1='apple'; $Fruit_$var1=organic; echo $Fruit_apple; // I want this to return organic Or how are you guys dynamically naming PHP vars on the fly? John Butler (Govinda) govinda.webdnat...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP 5.2.9 + NCurses
Hi all I have start a shell script and I want to use ncurses. It was a quite difficulty to get it working, but now I'm done to start to develop. I have already search on sf.net and phpclasses and found a couple, but I'm looking more stable or with a better OO design. Do you know any set of classes that handle ncurses easily? -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP as Language
Hi all Is there a formal definition for the php language? Where I can found it? I've STW with no results. -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: unsetting a referenced parameter in a function
I think he is confusing the unset semantic. Unset just destroy a variable, but not the content of it. Take a look at the output of this simple script: function avoid_global_scope() { $a = 'foo'; var_dump( get_defined_vars() ); $b = $a; var_dump( get_defined_vars() ); unset( $a ); var_dump( get_defined_vars() ); unset( $b ); } avoid_global_scope(); This is the output in my apache2 / php 5.2.6... but yours MUST be the same array(1) { [a]= string(3) foo } array(2) { [a]= string(3) foo [b]= string(3) foo } array(1) { [b]= string(3) foo } Note in the second array both variables was converted to references. But in the third b is just a common variable. This behaviour is cause by how PHP handles the references? 1) $a = 'foo'; Here we have an string 'foo' and a variable a which points to the string. 2) $b = $a; Now we have anothe variable b which refers to _contents_ of variable a Variable a is converted to a reference to it contents 3) unset( $a ); When a is destroyed only b refers to 'foo', PHP handles b as a common var 3) unset( $b ); When b is destroyed PHP notes that no one is referencing 'foo'... so, it's removed too. Remember... unset destroy variables, not it's content. class Foo { public static $last; function __construct() { self::$last = $this; } } $a = new Foo; $a = null; unset( $a ); var_dump( Foo::$last instanceof Foo ); # bool(true) On Thu, Jul 23, 2009 at 9:35 AM, Shawn McKenzie nos...@mckenzies.netwrote: Tom Worster wrote: On 7/22/09 6:09 PM, Shawn McKenzie nos...@mckenzies.net wrote: Tom Worster wrote: though the manual is perfectly clear that this should be expected, i was a bit surprised that the result of the following is 42 ?php function foo($a) { $a = 42; unset($a); $a = 'meaning'; } foo($a); print($a\n); ? normally i would expect unset() to free some memory. but in this example it doesn't and has a different behavior: it releases foo's reference to the global $a, allowing the next line to define a local $a. i think i'd have preferred compile error. Well, you unset the reference and then you assigned 'meaning' to a local function variable $a. Why would you get a compile error? when you state it in those terms (which are clearly correct) i wouldn't. but if the way i think is unset() destroys the specified variables (as the manual puts it) then i expect that the specified variable would be destroyed, not the reference. so, as i said, i was a bit surprised when the variable wasn't destroyed. once i understood what was happening, i thought it a bit confusing to have such scope-dependent differences in behavior of a language element. It might be easier to understand if you don't use the same var names: function foo($arg) { $arg = 42; unset($arg); $arg = 'meaning'; } $a = 0; foo($a); print($a\n); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Renaming all variables in a repository
function toCamelCase( $string ) { return str_replace( ' ' , '', ucwords( strtolower( strtr($string, '_', ' ') ) )); } echo toCamelCase( 'this_is_not_properly_written' ); You can use this simplest function to translate a string to camelCase. The process could be... 1) parse by PHP 2) translate tokens to camelCase 3) writte the file with changes You can easily parse a php file using http://php.net/token_get_all On Thu, Jul 23, 2009 at 1:56 PM, Eddie Drapkin oorza...@gmail.com wrote: Hey all, we've got a repository here at work, with something like 55,000 files in it. For the last few years, we've been naming $variables_like_this and functions_the_same($way_too). And now we've decided to switch to camelCasing everything and I've been tasked with somehow determining if it's possible to automate this process. Usually, I'd just use the IDE refactoring functionality, but doing it on a per-method/per-function and a per-variable basis would take weeks, if not longer, not to mention driving everyone insane. I've tried with regular expressions, but I can't make them smart enough to distinguish between builtins and userland code. I've looked at the tokenizer and it seems to be the right way forward, but that's also a huge project to get that to work. I was wondering if anyone had had any experience doing this and could either point me in the right direction or just down and out tell me how to do it. Thanks so much --Eddie -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Re: newbie question - php parsing
This is how I'd write this snippet ?php if ( 'Home' !== ( $title = the_title('','',FALSE))) { echo 'h2 class=entry-header', $title, '/h2'; } ? On Wed, Jul 22, 2009 at 6:31 PM, Lenin le...@phpxperts.net wrote: Ted Turner http://www.brainyquote.com/quotes/authors/t/ted_turner.html - Sports is like a war without the killing. 2009/7/23 Shane Hill shanehil...@gmail.com 2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br You made a mistake in your code: ?php the_title(); ? must be: ?php echo the_title(); ? ?= the_title(); ? Short tag and not recommended as its deprecated now, would be void at PHP 6.0 -- Martin Scotta
Re: [PHP] Re: unsetting a referenced parameter in a function
On Wed, Jul 22, 2009 at 9:27 PM, Tom Worster f...@thefsb.org wrote: On 7/22/09 6:09 PM, Shawn McKenzie nos...@mckenzies.net wrote: Tom Worster wrote: though the manual is perfectly clear that this should be expected, i was a bit surprised that the result of the following is 42 ?php function foo($a) { $a = 42; unset($a); $a = 'meaning'; } foo($a); print($a\n); ? normally i would expect unset() to free some memory. but in this example it doesn't and has a different behavior: it releases foo's reference to the global $a, allowing the next line to define a local $a. i think i'd have preferred compile error. Well, you unset the reference and then you assigned 'meaning' to a local function variable $a. Why would you get a compile error? when you state it in those terms (which are clearly correct) i wouldn't. but if the way i think is unset() destroys the specified variables (as the manual puts it) then i expect that the specified variable would be destroyed, not the reference. so, as i said, i was a bit surprised when the variable wasn't destroyed. once i understood what was happening, i thought it a bit confusing to have such scope-dependent differences in behavior of a language element. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php RTM: http://php.net/unset The behavior of *unset()* inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is *unset()* inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before *unset()* was called. / ... / If a variable that is PASSED BY REFERENCE is *unset()* inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before *unset()* was called. I think the manual is very clear about unset. -- Martin Scotta
[PHP] Re: file_set_contents() do several times?
David Otton napsal(a): 2009/7/20 Martin Zvarík mzva...@gmail.com: ?php $i = 0; do { $i++; $r = file_put_contents('file.txt', 'content'); } while($r === false $i 3); if ($r === false) die('error'); ? Makes sense? or is it enough to do it just once? Assuming 'content' changes, and this is the cut-down example... $r = file_put_contents('file.txt', 'content', FILE_APPEND); There's a small overhead in opening/closing the file three times instead of one, but I doubt that's going to be an issue for you. I am not appending anything, just ensuring that it will be written (and giving it max. 3 tryes). === Martin Scotta replied: In my experience file_put_contents never fails, except about file permissions, but this is not the case. --- Thanks for your replies. Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] file_set_contents() do several times?
?php $i = 0; do { $i++; $r = file_put_contents('file.txt', 'content'); } while($r === false $i 3); if ($r === false) die('error'); ? Makes sense? or is it enough to do it just once? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Exception not being caught
There are many examples of error_handlers at http://ar.php.net/manual/es/function.set-error-handler.php The handler only have to cast the error to exception. YOu can write a simple handler or a fully featured one, but the essence is the same... function errorHandler(/*args*/) { $e = new Exception( $message, $code ); throw $e; } On Thu, Jul 16, 2009 at 8:42 AM, David Otton phpm...@jawbone.freeserve.co.uk wrote: 2009/7/15 Weston C west...@gmail.com: ?php class A { } $a = new A(); // Ayn would be proud, right? try { echo a is ,$a,\n; } catch(Exception $e) { echo \nException Caught: ; echo $e, $n; } ? This does not run as expected. I'd think that when the implicit string conversion in the try block hits, the exception would be thrown, caught by the catch block, and relayed. Instead you don't ever see the words exception caught and you get Catchable fatal error: Object of class A could not be converted to string. If it's catchable, why isn't it caught in my example? It's not an exception, it's a fatal error. Fatal errors are caught by error handling functions, not by catch blocks. Consequence of having (at least) two separate error handling mechanisms in the same language. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Sub Menu System?
you can make the menu based on the files. Open the directory, read the files and save some sort of cache that use the site. When you need to move something, just delete the cache an let php do the rest. On Thu, Jul 16, 2009 at 9:55 AM, David Stoltz dsto...@shh.org wrote: Folks, I'm developing a rather large site in PHP. The main horizontal nav bar never changes, no matter how deep you are in the site. However, on the left side is a vertical sub-menu system. This menu is proving to be a real pain to program. I have it limited the menu system to 3 levels: MAIN: |___Secondary pages |___Tertiary pages For each level, and each folder, I have a file called subnav.php, which contains the links for that page. It has its own code to determine the page it's on, and highlight the appropriate menu item. The problem is when I need to move pages, or add pages, it's proving to be a REAL PAIN to maintain this type of structure. Does anyone know of any off-the-shelf product that can create/maintain a sub-menu system like this? I don't mind starting over at this point, but I'm hoping there is something I can just purchase, so I can concentrate on the rest of the sitehopefully the menu system would support PHP and ASP. Thanks for any information! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta
Re: [PHP] Alphabetical pagination (RESOLVED)
On Thu, Jul 16, 2009 at 12:01 PM, Miller, Terion tmil...@springfi.gannett.com wrote: One question I still have...I had help with this script of course and I'm confused with the %s what does it do? On 7/16/09 9:53 AM, Martin Scotta martinsco...@gmail.com wrote: On Thu, Jul 16, 2009 at 11:01 AM, Andrew Ballard aball...@gmail.com wrote: On Thu, Jul 16, 2009 at 9:33 AM, Miller, Teriontmil...@springfi.gannett.com wrote: Here is what finally worked: ?php$letter = isset($_GET['letter']) ? $_GET['letter'] : A; //alphabetical pagination links echo 'div align=centerb'; foreach(range('A','Z') as $c){ ($letter == $c)? printf('%snbsp',$c) : printf('a href=?letter=%s%s/anbsp;',$c,$c); } echo /b/divp; //Show all restaurants that start with $letter $sql = SELECT * FROM restaurants WHERE name LIKE '{$letter}%'; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ printf('div align=left width=100b%s/bbr%s/br%s/br/divhr color=#000 width=200/hr',$row['name'],$row['address'],$result['cviolations']); } ? Thanks again everyone!! Terion, I hope that isn't your final answer. This has SQL injection written all over it since you are neither validating that $letter is actually a letter, nor are you escaping it before passing it off to MySQL. ?php $letter = isset($_GET['letter']) ? $_GET['letter'] : 'A'; if (!preg_match('/^[A-Z]$/i', $letter) { $letter = 'A'; /* Rather than setting $letter to 'A' and continuing, you could generate an error if you end up in here so you can let the user know that what they passed was invalid. */ } // ? In this case, it should be safe to use $letter directly in the query without passing it through mysql_real_escape_string() since it should only contain a single harmless alphanumeric letter, but it wouldn't hurt (and may still be a good idea) to go ahead and escape the value in the query anyway just in case something in your code changes later that might cause some cruft to slip in. Andrew My point of view: # i'll use constants for these values assert( ord('A') == 0x41 ); assert( ord('Z') == 0x5A ); # 1. get the ascii code of the 1st character or from A=0x41 $letter = ord( array_key_exists('letter', $_GET) ? strtoupper( $_GET['letter']{0} ) : 'A' ); # 2. different solutions # 2.a check if it is range ussing = ussing constants (faster) $letter = chr( 0x41= $letter $letter = 0x5A ? $letter : 0x41 ); # 2. different solutions # 2.b check if it is range min/max and with constants (faster) $letter = chr( min( max(0x41, $letter), 0x5A) ); I'd use the 2.b but this has different behaviour when $letter Z (should this ever happen?) In the other hand I think it is the faster one. printf has it's own mini-syntax. This was implemented in C. PHP's printf syntax is very similar, but with some cool add-ons http://php.net/printf The detailed description of format are here: http://php.net/sprintf -- Martin Scotta
[PHP] Add php.net to my browser search box
Hi all! I'd like to add php.net to my browser search box. Most browser can do it by looking at some XML provided by the site. The HTML must contain a simple link tag like this link rel=search type=application/opensearchdescription+xml title=PHP.net href=http://php.net/osd.xml; / and osd.xml should be something like this ?xml version=1.0 encoding=utf-8? OpenSearchDescription ShortNamePHP.net/ShortName DescriptionQuick search in PHP.net!/Description Tagsphp quick search/Tags Image height=16 width=16 type=image/x-icon http://php.net/images/logos/php-icon-white.gif/Image Url type=text/html method=GET template= http://search.php?pattern={searchTerms}/ InputEncodingUTF-8/InputEncoding AdultContentfalse/AdultContent /OpenSearchDescription I know php.net use method=POST, but it's quite easy to provide a GET mechanism. is this the correct place for posting this? -- Martin Scotta
Re: [PHP] Invalid Argument why?
foreach iterates over an array or a object (see Traversable ). If you pass anything different he complains ?php if( !is_scalar( $collection ) ) foreach( $collection as $element ) print_r( $element ); On Thu, Jul 16, 2009 at 4:53 PM, Kyle Smith kyle.sm...@inforonics.comwrote: Miller, Terion wrote: Why is this an invalid argument? foreach(($row['inType']) as $inType){ echo $inType,'br';} I am trying to output results from a data base that may have multiple results for the same name So trying to use an array and foreach that is the right track ...right? Looks like you meant to do something like this: // Always better to be plural when you have an array. $rows = whatever_your_rows_come_from(); foreach($rows as $row) { $inType = $row['inType']; echo $inType . 'br /'; } HTH, Kyle -- Martin Scotta
Re: [PHP] Alphabetical pagination
SET @letter := 'B'; SELECT name FROM table WHERE SUBSTRING(name, 1) == @letter; SELECT name FROM table WHERE name like concat(@letter, '%'); I don't know a faster way to do it On Wed, Jul 15, 2009 at 12:57 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Wednesday 15 July 2009 16:46:53 Andrew Ballard wrote: On Wed, Jul 15, 2009 at 11:30 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Wednesday 15 July 2009 16:21:22 tedd wrote: At 12:38 PM -0700 7/14/09, Miller, Terion wrote: I am trying to make a page that displays a-z like a b c d e etc as links then when you click open one it reloads itself and shows only the query results that go with that letter...i'm not getting itI get a page that says ARRAY over and over... What I have so far: -snip- Why not have MySQL sort the data instead of using php? For example (from memory -- use with caution) SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1 Then just change the offset to go up and down the list. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com You could do what Tedd suggested, but use MySQL to actually limit the results it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'. *ducks to avoid people throwing things at him. I know it's slow!* -- Thanks, Ash http://www.ashleysheridan.co.uk Why would that be slow? Using LIKE isn't always a bad thing. In this case, the LIKE condition begins with a constant rather than a wildcard, so it should perform well. It can even benefit from an index on `somefield` if one exists. I only see a couple issues with tedd's query: 1) As written, it only returns one row. To get it to return a list, you'd have to call it repeatedly inside a for...loop where $offset increments begins at some value and increments/decrements to an ending value. But then he did say from memory -- use with caution. The general idea is correct. 2) It implements numeric pagination, which is usually based on a fixed number of rows per page. The OP wanted alphabetical pagination (like an address book) with each page containing all entries that begin with the selected letter. Andrew I just had a query doing the same thing one time, and that did take it's time (about 2-3 seconds) but it did have a few million records to look at, so I can understand why it was slow! And it was on MSSQL, with no indexes set up :( I nearly cried when I saw what I was dealing with! -- Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: I have an idea
On Wed, Jul 15, 2009 at 4:55 AM, Carlos Medinai...@simply-networks.de wrote: Martin Scotta schrieb: Hi Do you noted that all the discussion here are about problems, bugs, or just urgent pleaaase help me I have an idea. It is not really THE idea... but it is. What happen if tell this idea to the community? I don't know, so, let's take a look. PHP is a great language. You can do a lot of things with him, even have fun with it. My idea is to make a simple game where your have to write some AI to beat the other players AI The idea, as simple as it looks, is really difficult to implement specially about security so, do you like me idea? Hi Martin, i think is a good idea. How do you think to implement this? Carlos Medina -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Well, that's is exactly the main problem. First I think that users must provide a set of classes to participate. Then there will be some matches between the classes. The problem here is the security, you are allowing to execute arbitrary code! So, if the user classes can be executed remotely this issue is solved, maybe using webservices... This also free the user to implement the AI in PHP but has a great limitation for the players. Not all player has the resources / knowledge to set a webservice... Another approach can be create some sort of scripting language. This can be parsed / translated by PHP and all solved... but this will not be a PHP game. I want players to write the AI using PHP but, if possible, not restricting to it -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I have an idea
On Wed, Jul 15, 2009 at 10:38 AM, Govindagovinda.webdnat...@gmail.com wrote: PHP is a great language. You can do a lot of things with him, even have fun with it. My idea is to make a simple game where your have to write some AI to beat the other players AI The idea, as simple as it looks, is really difficult to implement specially about security so, do you like me idea? -- Martin Scotta sorry if this is getting OT: Martin, I wrote a really fun and charming remake of a great that 2 others wrote in the 1980's. My version has really fun graphics and sounds. I used visual basic as that is what I had then on my then windows laptop, without internet, literally in the mountains in north India where we only had electricity a couple hours per day, let alone no internet. It is a simple but very fun strategy game with more depth than say checkers (by far!), but less complex/daunting than say chess. It has 2-player option, but writing the AI for the various levels of difficulty when playing against the computer was the most challenging and fun part of the project. I often thought of taking it the next step and doing just what you propose here. I don't know what is LISP, but I assume that post meant to say that PHP is not the best language for this. (?) I say, so? If you know PHP, (and what, AJAX to go with it?) then you can do it, and HAVE FUN, regardless that it is very inefficient way to do it. For myself I can't afford to take time for that much programming fun, just now.. but let me know in case you (or anyone) would like a copy of that game.. it may give you some ideas, not to mention it is perfect fun for unwinding at the end of a day of coding. Takes 5 minutes to play. The expert level is not at all easy to beat! ;-) (for windows 98--Vista. Windows-7 I don't know... I use Mac when I have a choice.) -Govinda That's the idea. You will have fun programming the AI and looking how it match between others. I'd like to see your game, do you still have it? -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I have an idea
On Wed, Jul 15, 2009 at 12:29 PM, teddtedd.sperl...@gmail.com wrote: At 1:21 AM -0300 7/15/09, Martin Scotta wrote: Hi Do you noted that all the discussion here are about problems, bugs, or just urgent pleaaase help me I have an idea. It is not really THE idea... but it is. What happen if tell this idea to the community? I don't know, so, let's take a look. PHP is a great language. You can do a lot of things with him, even have fun with it. My idea is to make a simple game where your have to write some AI to beat the other players AI The idea, as simple as it looks, is really difficult to implement specially about security so, do you like me idea? -- Here's an AI (rule based) php game: http://sperling.com/quarters/ Get your AI to beat mine. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com nice game tedd, I played it a lot of times and still can't beat it. Also I have pass the link about 2 weeks ago in the office... and the AI always wins quite frustrating, but really entertained -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] boolean vs int comparison
I always have doubts about comparison between boolean and integers. Lets PHP shows hows is that he does. The results where: false$int === true / $int !== 0 false = $int === true false$int === false false = $int === false / $int !== 0 false == $int === false / $int !== 0 false === $int === false false != $int === true / $int !== 0 false !== $int === true true $int === false true = $int === true / $int !== 0 true $int === false / $int !== 0 true = $int === true true == $int === true / $int !== 0 true === $int === false true != $int === false / $int !== 0 true !== $int === true ?php # the script I used function bol2string($boolean) { return $boolean ? 'true' : 'false'; } $results = array(); foreach(array(false, true) as $boolean) foreach(array(' ', '= ', ' ', '= ', '== ', '===', '!= ', '!==') as $test) for($i=-1; $i1; ++$i) { @eval( '$value =' . ( $_test = bol2string($boolean) . ' ' . $test . ' ' . $i ) . ';' ); $results[ $boolean][ $test ][ $i ] = $value; } foreach($results as $boolean = $_boolean) foreach($_boolean as $test = $_test) echo bol2string($boolean) , $boolean ? ' ': ' ' , $test ,' $int === ' , bol2string($_test[-1]), $_test[0] !== $_test[-1] ? ' / $int !== 0' : '' , PHP_EOL; ? -- Martin Scotta
Re: [PHP] Need Help.
hahahahahaha How are you to delete my history? The fact that you develop a website does not allow you to take the control of my browser. But you can avoid the history to be populated by using javascript a href=lalalal.html onclick=document.location.replace(this.href) Click to lalalal /a The replace() method loads a new page, specified by URL, in the current browser window. The new page replaces the previous page's position in the history list. On Tue, Jul 14, 2009 at 5:51 AM, kranthikranthi...@gmail.com wrote: Hi Girish, 1. You cannot modify the browser Back button (any thing on the client's computer for that matter). 2. I strongly oppose the use of Cookies for tracking the user login, due to security reasons. Cookies are saved on the client's computer and he/she can easily modify the information present. But that is impossible with sessions. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Scope of Variables and use of global and this-var
do you need to use global? IMO you should use just 1 global variable, thats is what I call entry point My scripts looks like... require_once 'loader.php'; Loader::registerAutoload(); $foo = new Foo(); $foo-doStuff(); This way you can develop faster and do maintenance better avoiding problems with third-party. Here you have some rules for remember how to access you want a $var from outside and you are outside an object or function? = use the $var you want a $var from outside you are inside an object or function? = global $var o $GLOBALS['vars'] (better to pass it as arg) you want a $var from an object and you are inside the same object? = use $this-var (better $this-getVar() ) you want a $var from an object and you are inside other object? = use $object-getVar() or Class::getVar() It is a good practice to declare the object members as protected and provide s/getters for each member (when your design allow it). Also you can overload by using the __get, __set and __call It is really easy to make an automagic object Class AutoMagic { protected $_vars = array(); public/*mixed*/ function __get(/*string*/$name) { return isset( $this-{ $name } ) ? $this-_vars[ strtolower($name) ] : null; } public/*mixed*/ function __set(/*string*/$name,/*mixed*/$value) { return $this-_vars[ strtolower($name) ] = $value; } public/*boolean*/ function __isset(/*string*/$name) { return array_key_exists( strtolower($name), $this-_vars ); } public/*void*/ function __unset(/*string*/$name) { if( isset( $this-{ $name } )) unset( $this-_vars[ strtolower($name) ] ); } public/*mixed*/ function __call(/*string*/$method,array $args) { $type = strtolower( substr( $method, 0, 3 ) ); $property = substr( $method, 3 ); switch( $type ) { case 'get': return $this-{ $property }; case 'set': if( !array_key_exists(0, $args) ) trigger_error( 'Bad call in ' . get_class($this) . '::' . $method .'. Method needs an argument' ); return $this-{ $property } = $args[0]; case 'has': return isset( $this-{ $property } ); case 'del': unset( $this-{ $property } ); return; } trigger_error( 'Bad call in ' . get_class($this) . '::' . $method ); } } On Tue, Jul 14, 2009 at 10:01 AM, Darren Karstensdarrenkarst...@googlemail.com wrote: Oh and if one class uses methods in another class do I instansiate a new object of the other class I have seen use of OtherClass::Method is this better method of $obj = new OtherClass() use The :: is used to access static methods of a class. Static methods can be used without creating an instance of the class because they dont use any of the classes member variables. For example say you have a class with a function for calculating the area of a rectangle: class SomeMathFunctions { public function calculateRectangle($width, $height) { return $width*$height; } } To use this function you would need to first create an instance of the class then call the method using the normal - : $funcs = new SomeMathFunctions(); $area = $funcs-calculateRectange(10,15); But if you create the function as static by using public static function calculateRectangle($width, $height) { then you can access the method by using just 1 call: $area = SomeMathFunctions::calculateRectange(10,15); So for creating utility functions its better to use static methods since you dont get the overhead of creating a new instance of the class. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need Help.
I know... this is not for a php thread... but... If you look at the HTML the a tag is made completely unobtrusive. The link will still working without javascript. This is the original tag (with javascript) a href=lalalal.html onclick=document.location.replace(this.href) Click to lalalal /a This is how the browser looks it without javascript a href=lalalal.html Click to lalalal /a I've said it is not for a php thread On Tue, Jul 14, 2009 at 10:29 AM, Bob McConnellr...@cbord.com wrote: From: Martin Scotta hahahahahaha How are you to delete my history? The fact that you develop a website does not allow you to take the control of my browser. But you can avoid the history to be populated by using javascript a href=lalalal.html onclick=document.location.replace(this.href) Click to lalalal /a That would prevent me from navigating the site since I won't enable JavaScript in my browser until I have trust in your website not to allow any installation of malware on my computer. That trust must be earned by you, since trust is not associative. Yes, there are a lot of sites that I can't visit because of that. Right now I won't even enable JS for either my bank or credit card issuer since neither has demonstrated the knowledge, desire or ability to protect their servers or my browser. Bob McConnell -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [GD] Image errors
$immagine = $tipo($this-updir.$id.'.png'); $tipo is undefined On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino volantetuxs...@codeinside.it wrote: Hi to all I get a problem processing an image with GD libraries. This is my function public function showPicture($id) { header('Content-type: image/jpeg'); $mime = mime_content_type($this-updir.$id.'.png'); $type = explode('/',$mime); $type = 'imagecreatefrom'.$type[1]; $immagine = $tipo($this-updir.$id.'.png'); imagejpeg($immagine,null,100); imagedestroy($immagine); } If i commentize the header function i get a lot of strange simbols (such as the code of a jpeg image!) but no errors. The result of this code is a blank page. In Firefox the title sets to picture.php (JPEG image) and if i right-click it and click on Proprieties i get 0px × 0px (resized as 315px × 19px). P.S.: I get the same result when I write $immagine = imagecreatefromjpeg(...) (Sorry for my english) Thanks in advance, Alfio. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [GD] Image errors
He is calling the function by variable something like this $func = 'var_dump'; $func( new Foo ); On Tue, Jul 14, 2009 at 1:30 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote: $immagine = $tipo($this-updir.$id.'.png'); $tipo is undefined On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino volantetuxs...@codeinside.it wrote: Hi to all I get a problem processing an image with GD libraries. This is my function public function showPicture($id) { header('Content-type: image/jpeg'); $mime = mime_content_type($this-updir.$id.'.png'); $type = explode('/',$mime); $type = 'imagecreatefrom'.$type[1]; $immagine = $tipo($this-updir.$id.'.png'); imagejpeg($immagine,null,100); imagedestroy($immagine); } If i commentize the header function i get a lot of strange simbols (such as the code of a jpeg image!) but no errors. The result of this code is a blank page. In Firefox the title sets to picture.php (JPEG image) and if i right-click it and click on Proprieties i get 0px × 0px (resized as 315px × 19px). P.S.: I get the same result when I write $immagine = imagecreatefromjpeg(...) (Sorry for my english) Thanks in advance, Alfio. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta Also, it doesn't look like you're actually doing anything with $type Thanks Ash www.ashleysheridan.co.uk -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [GD] Image errors
On Tue, Jul 14, 2009 at 1:48 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-07-14 at 13:41 -0300, Martin Scotta wrote: He is calling the function by variable something like this $func = 'var_dump'; $func( new Foo ); On Tue, Jul 14, 2009 at 1:30 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote: $immagine = $tipo($this-updir.$id.'.png'); $tipo is undefined On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino volantetuxs...@codeinside.it wrote: Hi to all I get a problem processing an image with GD libraries. This is my function public function showPicture($id) { header('Content-type: image/jpeg'); $mime = mime_content_type($this-updir.$id.'.png'); $type = explode('/',$mime); $type = 'imagecreatefrom'.$type[1]; $immagine = $tipo($this-updir.$id.'.png'); imagejpeg($immagine,null,100); imagedestroy($immagine); } If i commentize the header function i get a lot of strange simbols (such as the code of a jpeg image!) but no errors. The result of this code is a blank page. In Firefox the title sets to picture.php (JPEG image) and if i right-click it and click on Proprieties i get 0px × 0px (resized as 315px × 19px). P.S.: I get the same result when I write $immagine = imagecreatefromjpeg(...) (Sorry for my english) Thanks in advance, Alfio. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta Also, it doesn't look like you're actually doing anything with $type Thanks Ash www.ashleysheridan.co.uk -- Martin Scotta Bottom post ;) $type = explode('/',$mime); $type = 'imagecreatefrom'.$type[1]; $immagine = $tipo($this-updir.$id.'.png'); imagejpeg($immagine,null,100); imagedestroy($immagine); I'm not sure you understood what I meant. line 2 above $type is assigned to the string 'imagecreatefrom'.$type[1]; Now I assume that was to be used later in some sort of eval() statement, but its never called again, so the line really does nothing. Thanks Ash www.ashleysheridan.co.uk Mmmm, No $type = explode('/',$mime); # type is array $type = 'imagecreatefrom'.$type[1]; # type is a string He is actually re-assigning the var ussing the content of the var. Sounds crazy, but I use this method a lot, it helps to keep the scope clean. -- Martin Scotta ps. tipo is type in Spanish -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [GD] Image errors
Why are you ussing GD? All you need is output the image to the browser? try this... I didn't test/run this code, but it may work... public function showPicture( $id ) { header('Content-type:' . mime_content_type( $this-updir . $id . '.png' ) ); readfile( $this-updir . $id . '.png' ); } hey, look, just 2 lines! On Tue, Jul 14, 2009 at 2:20 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-07-14 at 14:16 -0300, Martin Scotta wrote: On Tue, Jul 14, 2009 at 1:48 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-07-14 at 13:41 -0300, Martin Scotta wrote: He is calling the function by variable something like this $func = 'var_dump'; $func( new Foo ); On Tue, Jul 14, 2009 at 1:30 PM, Ashley Sheridana...@ashleysheridan.co.uk wrote: On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote: $immagine = $tipo($this-updir.$id.'.png'); $tipo is undefined On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino volantetuxs...@codeinside.it wrote: Hi to all I get a problem processing an image with GD libraries. This is my function public function showPicture($id) { header('Content-type: image/jpeg'); $mime = mime_content_type($this-updir.$id.'.png'); $type = explode('/',$mime); $type = 'imagecreatefrom'.$type[1]; $immagine = $tipo($this-updir.$id.'.png'); imagejpeg($immagine,null,100); imagedestroy($immagine); } If i commentize the header function i get a lot of strange simbols (such as the code of a jpeg image!) but no errors. The result of this code is a blank page. In Firefox the title sets to picture.php (JPEG image) and if i right-click it and click on Proprieties i get 0px × 0px (resized as 315px × 19px). P.S.: I get the same result when I write $immagine = imagecreatefromjpeg(...) (Sorry for my english) Thanks in advance, Alfio. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta Also, it doesn't look like you're actually doing anything with $type Thanks Ash www.ashleysheridan.co.uk -- Martin Scotta Bottom post ;) $type = explode('/',$mime); $type = 'imagecreatefrom'.$type[1]; $immagine = $tipo($this-updir.$id.'.png'); imagejpeg($immagine,null,100); imagedestroy($immagine); I'm not sure you understood what I meant. line 2 above $type is assigned to the string 'imagecreatefrom'.$type[1]; Now I assume that was to be used later in some sort of eval() statement, but its never called again, so the line really does nothing. Thanks Ash www.ashleysheridan.co.uk Mmmm, No $type = explode('/',$mime); # type is array $type = 'imagecreatefrom'.$type[1]; # type is a string He is actually re-assigning the var ussing the content of the var. Sounds crazy, but I use this method a lot, it helps to keep the scope clean. It's not crazy, I do it a lot, but he *does nothing with it* after that, and the scope of the variable is limited to the function. Thanks Ash www.ashleysheridan.co.uk -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] I have an idea
Hi Do you noted that all the discussion here are about problems, bugs, or just urgent pleaaase help me I have an idea. It is not really THE idea... but it is. What happen if tell this idea to the community? I don't know, so, let's take a look. PHP is a great language. You can do a lot of things with him, even have fun with it. My idea is to make a simple game where your have to write some AI to beat the other players AI The idea, as simple as it looks, is really difficult to implement specially about security so, do you like me idea? -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RFC/Survey for Our Newer Folks (Including Lurkers)
That's exactly how I inlist here. I usually follow threads and even sometime reply I've here about 90 days (I suppose) The list is really interesting, but I was expecting more ninja threads. I know this list is wide open to anyone, ninja or newby, but I was expecting more. Anyway I'm really happy to be part of. Mrtn ps. top-posting xD On Sun, Jul 12, 2009 at 4:54 AM, Ashley Sheridana...@ashleysheridan.co.uk wrote: I was using the php.net website for ages for syntax reference, saw the mailing list and figured why not. No amazing story, but now you're all stuck with me :p -- Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] runtime access to static variable
On Fri, Jul 10, 2009 at 4:25 PM, Madbreaksnab...@vektral.com wrote: Jack Bates-2 wrote: How do I access a static variable when I do not know the name of the class until runtime? Why not just: eval('$staticVal = '.get_class($myClass).'::staticVarName;'); ...now the value is in $staticVal. Or am I missing something here? No need to tell me eval is evil ;) -- View this message in context: http://www.nabble.com/runtime-access-to-static-variable-tp21041719p24433169.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php if you need to access to a class constant use the built-in function if( defined( get_class($myClass) .'::THE_CONST' ) ) constant( get_class($myClass) .'::THE_CONST' ); They are very helpful -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Obeying the rules (was Simple login form with cookies)
Hi all I haven't read any post from here. I want to read PHP threads. is this going somewhere? I think not. On Thu, Jul 9, 2009 at 4:13 PM, teddtedd.sperl...@gmail.com wrote: At 2:38 PM -0400 7/9/09, Bob McConnell wrote: It will be even more interesting to see if anyone on this list pays any attention to him in the future. Bob McConnell Bob: You won't have to wonder about me. I've already set email filters to trash any incoming from him. A *few* on this list don't appreciate is that there are many of us who donate our time freely in an attempt to help others. We do this without any compensation nor profitable credit. We all come from various skill levels, diverse backgrounds, and each usually provide an unique solution and perspective to the problem presented. In short, what we have to say matters. What I offer is pretty basic as compared to the truly great ones on this list (i.e., Daniel, Stuart, Rob, et all). I feel privileged that my humble offerings are even permitted, but I think my contribution is to answer the more obvious questions thereby freeing the more knowledgeable to answer the more difficult ones. However, when I see a debate over such minor points, I can't help but note the waste of time and talent and thus the reason for my post. I just hope that the other contributors on this list fully understand the value of their contribution and spend their time and talents where they are appreciated and not waste them on such nonsense. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple login form with cookies
$sql = 'SELECT * FROM your-table WHERE username = \''. $username .'\' and passwd = md5( concat( \'' . $username .'\', \'@\', \'' . $password .'\'))'; I use this solution because md5 run faster in Mysql On Wed, Jul 8, 2009 at 10:28 AM, Andrew Ballardaball...@gmail.com wrote: On Tue, Jul 7, 2009 at 11:05 PM, Michael A. Petersmpet...@mac.com wrote: Carl Furst wrote: ? $salt = 'someglobalsaltstring'; # the salt should be the same salt used when storing passwords to your database otherwise it won't work $passwd = crypt($_GET['passwd'], $salt); I personally use the username and the salt. That way two users with identical passwords have different hashes. With large databases, many users will have the same password, there are some that are just commonly used. The hackers know what they are, and if they get your hash dump, they try their list of commonly used passwords against the user names that have the common hashes. By using the username as part of the salt, you avoid that issue because identical passwords will have different hashes. It does mean the password has to be reset if you allow them to change their login name. The password does not need to be reset. You could require that they provide the password again (even though they are already authenticated) on the same form with the new username. Then you can do the same encrypt/compare that you do for authentication, and if it matches you just update the username and the hash at the same time. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Lookup domain in directories VS database
Imagine you are hosting 10.000 subdomains. SOLUTION #1: you create directories like: a/ b/ ... s/ s/some-subdomain.freehosting.com/ (this includes CONF.php, where you store some basic infos) Everytime visitor hits the page you do: @include('t/test-subdomain.freehosting.com/conf.php') if (!isset($CONF)) die('such a subdomain does not exist'); SOLUTION #2: Everytime visitor hits the page you connect search in a MySQL table having 10.000 rows with each domain name and a text field (export_var()) that has some parameters you need. --- What's better? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php