Re: [PHP] Get country from Phone number
- Original Message - From: Jim Lucas [EMAIL PROTECTED] To: Dani Castaños [EMAIL PROTECTED] Cc: PHP LIST php-general@lists.php.net Sent: Saturday, March 01, 2008 2:36 AM Subject: Re: [PHP] Get country from Phone number Dani Castaños wrote: Hi all! I'm looking for some piece of code or class which giving a phone number it returns me from wich country is this phone. Do you know where I can find something like this? Thank you in advanced! As a little project, I took the link provided by the other Rob and make this little search tool. It only looks at the beginning numbers. It does no number validation. I don't validate the length of the number. ie: I would have to know the min/max lenth of each phone number for that given country/region, and I didn't search for that information. You can't check for length, that depends on each national administration and while some countries have all phone numbers exactly the same length, some other countries do it the old style: small phone exchanges have few digits, larger have more, which gets compensated by the smaller exchanges having longer area codes. The idea is that within small towns, you dial short numbers to reach your neighbour and, if someone dials from outside the area, they have to dial a longer area code prefix, but since the town is small, there is a lesser chance that many people will have any business dialing them anyway so, overall, you get to dial less. Also, in electromechanical phone exchanges, each extra digit (actually couple of digits) requires an extra row of 'selectors', which are (were) expensive. This still happens at the country level, not because it really matters nowadays but due to the existing technology when it was agreed on it. Large countries in Latin America have two digit country codes (political maneuvering at the time of assignment distorted this somewhat, letting Peru and Cuba get 2 digits which don't fit their actual number of phone lines). Thus, from 51 to 58 they are assigned to the larger countries. The 59x and 50x ranges (in phone numbering the zero is after the nine within the same decade) go to countries with less phone lines. Satyam Let me know what you'll think. http://www.cmsws.com/examples/php/areacodes/countrycodes.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.21.2/1305 - Release Date: 29/02/2008 18:32 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get country from Phone number
It is not as bad as it looks. The only important columns are the first two, the last two are how you dial from within the country to place long distance international or national calls. In many countries, when there are several low cost international call providers, they use different prefixes, actually, it is quite absurd that they list all options for low cost carriers for, say, Venezuela, while they don't for the USA where there are as many or more. The only tough part is that several countries, share the +1 prefix, the USA and Canada are the larger, but many Caribean countries, which originally got their service through the US phone system, are also mixed in. So, in those cases, you have to check through the 'area codes'. A similar thing happens with the ex-Soviet republics, they all share the 7 prefix. As for the rest, it is quite straighforward. 1 is North America 2 is Africa 3 and 4 Europe 5 rest of the Americas 6 Oceania 7 Russia and ex-soviet republics 8 FarEast 9 rest of Asia Most prefixes are of varying lenghts. The countries with the most phone lines get the shorter prefixes so the overall number is more or less the same for all. Thus, Mexico and Brazil get two digit codes in the 5 range while smaller Nicaragua gets three. Satyam - Original Message - From: Andrés Robinet [EMAIL PROTECTED] To: 'Dani Castaños' [EMAIL PROTECTED]; 'PHP LIST' php-general@lists.php.net Sent: Friday, February 29, 2008 11:17 AM Subject: RE: [PHP] Get country from Phone number -Original Message- From: Dani Castaños [mailto:[EMAIL PROTECTED] Sent: Friday, February 29, 2008 5:03 AM To: PHP LIST Subject: [PHP] Get country from Phone number Hi all! I'm looking for some piece of code or class which giving a phone number it returns me from wich country is this phone. Do you know where I can find something like this? Thank you in advanced! -- Seems like you'll have a hard time if you want to include all the possibilities: http://www.kropla.com/dialcode.htm But probably Rob (Cummings) will come up with a solve-it-all regex that will save your day. Regards, Rob(inet) Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 | TEL 954-607-4207 | FAX 954-337-2695 | Email: [EMAIL PROTECTED] | MSN Chat: [EMAIL PROTECTED] | SKYPE: bestplace | Web: bestplace.biz | Web: seo-diy.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.21.1/1303 - Release Date: 28/02/2008 12:14 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global address collection
Actually, phone numbers should not be prefixed with 00. The prefix for international dialing depends on the local phone regulations and it is different in different countries (for example, 011 in the USA). The recommendation from the telephone union (http://www.itu.int/) is to use a plus sign to indicate that the phone number starts with the country prefix. Thus, it would be: +44 1623 123456 or +1 408 555 1212. Americans also get often confused because the first 1 is both the country code for the US, Canada and a good chunk of the Caribbean and it is, at the same time, the prefix they use to dial national long distance. That's why the + is important. In most of the world, the leading zeros are like ../. You can thing of local phone numbers as your current directory. If you want to dial another area code, you first dial a zero, which is like using ../ in a file system, and then the area code, like the folder for that local number folder. If you want to dial international, you dial 00, which is like doing ../../, which gets you to the world root (eventually there might be three zeros to dial interplanetary!) and then dial the 'folder name' of the other country. Which reminds me of an observation by Arthur C Clarke that once humankind becomes an intergalactic civilization each group will lose communication with the rest, can you just imagine what phone numbers might be! (Brits always had a peculiar sense of humor) There is no mandatory format to separate international dialing prefix, country code, area code and actual number, it is better to have them separated at least with a blank space, but there is no standard regarding that and none should automatically impossed, the spacing provided by the user should be respected. Once again Americans are use to see their numbers as 1-408-555-1212 because all their area codes are 3 digits long and all the local numbers contain 7 digits grouped as 3 and 4, but most countries use a variable number of digits for area codes so only the person who entered the number can know how to split it. Do not delete the whitespace and then reformat the numbers assuming a fixed format because none actually exists. Tables of international dialing codes are available just googling around (for example, http://www.kropla.com/dialcode.htm), it is not a bad idea to check country against the first part of the phone number but then, a warning is all you could possibly issue since a person might have a postal address in, say, Monaco (+377) and a French mobile (+33). I wouldn't imagine that the Vatican has a separate mobile network from that of Rome so though they have an international prefix different from that of Italy which they might use for their land lines, their mobiles are probably Italian. Also, it should be Province/County/State, and it should be optional since some cities are autonomous (usuall federal capital cities), just don't make it mandatory. And don't force anything on postal codes. Some countries have letters in them and the number of characters varies. I just hate it when they ask to enter the full 9 digit zip code. Satyam - Original Message - From: Richard Heyes [EMAIL PROTECTED] To: tedd [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Monday, January 07, 2008 11:56 PM Subject: Re: [PHP] global address collection In other words, in the USA we ask for name, address, city, state, zip, and phone number. What would be a global equivalent that could cover all (or most) address and phone numbers? Full name (optionally forename/surname) Address 1 Address 2 (optional) Address 3 (optional) Town/City County/State Postal/Zip code Country Full international phone number (eg. 0044 1623 123456) -- Richard Heyes http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support ** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.17.13/1212 - Release Date: 06/01/2008 22:55 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looking for ways to prevent timeout
- Original Message - From: Jochem Maas [EMAIL PROTECTED] Dan Brown (the nice guy on this list, not the twat that wrote the 'daVinci Code') suggests a *much* better way to go- namely using a CLI script. the fun part is getting a button push on an admin page to somehow initiate the CLI script. one way of doing this could be to have a 'job' table in your database to which 'jobs' are inserted (e.g. 'do my 3 record import') and that your [CLI] script checks the database to see if it should start a 'job' and just exit if it does not need to do so ... lastly in order to have the [CLI] script regularly check if it needs to do something you can use cron to schedule that the script runs at regular intervals (e.g. every 15 minutes) many ways to skin this cat - my guess is all the decent ways of doing it will involve a CLI script probably in conjunction with a cronjob. if you arent familiar w/ ajax, no worries; the main concept in my suggestion is sending a number of requests rather than a single request. that way you can execute a fraction of the queries on each request. this will ensure that you dont hit the maximum execution time. Just to comment an alternative on how to break the job. It is just something that happened to me once and might be useful. My particular job could be naturally broken in several stages. Actually, it had to. Though it could be solved with a huge complex SQL query with several joins and subqueries (which were not available), it could also be perfomed with the help of a few intermediate auxiliary tables. So I had a query (which would have been the sub-query) inserting records into a flat table with no indexes. On a second step I added the index, then there was another join in between this auxiliary table and another table (and this one was pretty complex and at that time, with no stored procedures, it required some processing with PHP) and the final step that produced the result. At that time, before AJAX was popular, I showed the progress on an iframe on which I changed the src attribute for each successive step (poor man's AJAX), but it could also be done via AJAX or reloading the whole page instead of an iframe within it. Some time later I tried to redo one other such process into a single query with subqueries and I found that using the auxiliary tables was faster. I admit that my attempt was half-hearted, I wanted to either see a big improvement or ignore the whole business. The improvement wasn't that big so I dropped it and assumed the other processes would not show any big improvement either. After all, I knew the data and optimized it as much as possible so I can't assume the SQL optimizer could do much better than I had. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compilers
In the works: http://phpcompiler.org/ The guys working on it are still actively developing and answering the support list. It does not compile to executable yet (I understand it mostly does except for some tricky parts of the language) but it helps development with other tools that you will find in their site. Satyam - Original Message - From: Wolf [EMAIL PROTECTED] To: php-general php-general@lists.php.net Sent: Tuesday, October 30, 2007 4:36 PM Subject: [PHP] Compilers Anyone use compilers (linux based or Windoze) and which do you use? Looking for something free (best) or low cost as we are doing some investigation on what methods are best for some of the stuff we have, and I'm thinking a compiled PHP app should run faster. Thanks! Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.15.12/1098 - Release Date: 29/10/2007 9:28 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] the opposite of a join?
- Original Message - From: Zoltán Németh [EMAIL PROTECTED] it's not very efficient, but I don't have any better idea. someone else? Indeed, that sort of query is one of the worst and there is little you can do to improve it save making sure you have an index on the field of the table pointed at, even if you create it for this query and drop it once done. greets Zoltán Németh Thanks J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.488 / Virus Database: 269.13.39/1045 - Release Date: 02/10/2007 18:43 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP to determine if user has Java installed
I would think that if you put an applet in the page with some public property or method which you could then query from JavaScript if it succeeds it means you do have Java, not only installed but available and enabled to the browser, then you could either send a AJAX message to the server or navigate to some other page. The client might still have Java but not enabled for the browser though and this test would fail. The Java applet itself might communicate to the server but then you wouldn't be able to do much with that page as I don't believe an applet has that much control over the page it resides in. - Original Message - From: Matt Livingston [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, September 05, 2007 11:17 PM Subject: [PHP] Using PHP to determine if user has Java installed Hey List, I want to know if it is possible to use PHP to find out if a visitor has Java Runtime Environment installed on a computer. Is there a way to use PHP to find this similiar to how PHP can be used to find out browser info? Thanks in advance for your help. -- -Matt Livingston No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.485 / Virus Database: 269.13.5/990 - Release Date: 04/09/2007 22:36 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dealing with auto-increment in MySQL
I was wondering if people is asking this in the belief that the autoincrement field is the record position in the database table and that by not reusing those positions, the space of the deleted records is wasted. Perhaps when they say renumbering what they are meaning is compacting the database reusing the empty slots they assume those autoincrement fields point to. Someone remembers dBaseIII .dbf files? Well, perhaps that is the picture they have in mind. Satyam - Original Message - From: Jay Blanchard [EMAIL PROTECTED] To: Steve Finkelstein [EMAIL PROTECTED]; php-general php-general@lists.php.net Sent: Tuesday, September 04, 2007 12:53 PM Subject: RE: [PHP] Dealing with auto-increment in MySQL [snip] Do you use logic in your code to find a missing ID and insert new records based on that? Or do you just ignore it, let mysql handle the numbering and go on with your lives? [/snip] The answer is B. There is a long standing discussion on this right now. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.485 / Virus Database: 269.13.3/986 - Release Date: 03/09/2007 9:31 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] crypt salt question
No chance. Unless you have the salt stored along each password, your passwords are as good as random texts Satyam - Original Message - From: Andras Kende [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Thursday, August 30, 2007 11:42 PM Subject: [PHP] crypt salt question Hello, I'm trying to move some app from postgresql to mysql but unable to find out how to authenticate against the current crypted passwords with php.. insert to database: $cset = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./; $salt = substr($cset, time() 63, 1) . substr($cset, time()/64 63, 1); $password = crypt($password, $salt); //pass crypted version of password for further processing $result = pg_query (INSERT INTO users (username, password) VALUES ('$username', '$password')); I read the crypt is one way encryption but how to compare the password entered with the encrypted version if don't know the salt ?? Thanks, Andras No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.484 / Virus Database: 269.12.12/979 - Release Date: 29/08/2007 20:21 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Internet Explorer Caching
I'm sending these headers: header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past I don't remember where I took them from, but they are working fine for me. Satyam - Original Message - From: Richard Heyes [EMAIL PROTECTED] To: Charlene [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Wednesday, August 29, 2007 5:50 PM Subject: Re: [PHP] Internet Explorer Caching Charlene wrote: I've been having problems with Internet Explorer caching php programs. I'm using the following code: header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1 header(Pragma, no-cache); header(Expires, -1); And it used to work, but now, according to Windows Explorer its giving it 3 hours to expire. Are you sure? By default PHP pages/scripts don't send any caching headers and hence don't get cached. You can check this using: http://www.fiddlertool.com -- Richard Heyes +44 (0)844 801 1072 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.484 / Virus Database: 269.12.10/977 - Release Date: 28/08/2007 16:29 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] javascript in head or in body ?
Check: http://developer.yahoo.com/performance/rules.html Satyam PS: The answer is, put styles at the top, scripts at the bottom., but there are many other tricks to improve performance. Otherwise, as for the standards, they can go anywhere. - Original Message - From: C.R.Vegelin [EMAIL PROTECTED] To: [EMAIL PROTECTED] php-general@lists.php.net Sent: Tuesday, August 07, 2007 10:19 PM Subject: [PHP] javascript in head or in body ? Are there any rules when to include javascript in head or in body ? For example, script type=text/javascript function reload(form) { var val=form.Chapter.options[form.Chapter.options.selectedIndex].value; self.location='QueryForm.php?Chapter=' + val ; } /script TIA, Cor No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.8/940 - Release Date: 06/08/2007 16:53 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loss of precision in intval()
It is most definitely not if what you want is the square root, or the hyperbolic cosine or any other of a zillion things. - Original Message - From: Mark Summers [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, August 01, 2007 6:52 PM Subject: [PHP] Loss of precision in intval() This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.0/929 - Release Date: 31/07/2007 17:26 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need insights on encrypting and uploading ASCII file using PHP
- Original Message - From: tedd [EMAIL PROTECTED] To: John A DAVIS [EMAIL PROTECTED]; php-general@lists.php.net Sent: Sunday, July 29, 2007 4:32 PM Subject: Re: [PHP] need insights on encrypting and uploading ASCII file using PHP Finally, you could get your users to ZIP the files with a password before sending them, which is not so secure but is good enough for many uses. IT all depends on what you want. Satyam You can also send pieces and parts at different times to be assembled afterwards and, if needed, each to have their own protection scheme. Or you could burn a CD and sent it through the mail, publish keys in the newspaper under personal ads, flash Morse code on clouds, or try smoke signals -- all work in one fashion or another to transmit data. I think that about covers it. :-) Perhaps you are missing a station wagon full of 6250BPI magnetic tapes as Tanenbaum's classic Computer Networks mentions, with an armed guard on the passenger seat, for the sake of security. Satyam PS: I wonder if he took that out in later editions or replaced 'van' for 'station wagon' and 'CDs' for 'magnetic tapes'. 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.23/924 - Release Date: 28/07/2007 15:50 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOT - Ajax definitiondear all,
- Original Message - From: Jay Blanchard [EMAIL PROTECTED] To: Yeni Setiawan [EMAIL PROTECTED]; php-general@lists.php.net Sent: Friday, July 27, 2007 1:51 PM Subject: RE: [PHP] OOT - Ajax definitiondear all, [snip] We all knew that AJAX is an achronym of Asynchronous Javascript And XML. When I use another data format like YAML or CSV, will it still be called as AJAX? Or just yet another asynchronous method? [/snip] AJAX makes a good catch-all term since the API is called XMLHttpRequest and the API can be used with all sorts of text data. The asynchronous method is still JavaScript (or is it ECMAScript?). Its original intent was XML data (just text with mark-up). Besides, AJAP (Asynchronous JavaScript and PHP) just doesn't sound right somehow. AJAH - and HTML AJAA - and ASP AJA.N - and .NET AJAC - and CSV AJAT - and TXT AJACF - and Cold Fusion AJAPL - and PERL Just let the X stand for 'unknown'. Satyam And so on. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.22/921 - Release Date: 26/07/2007 23:16 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need insights on encrypting and uploading ASCII file using PHP
There are two different things you might want, ensure that the data is not seen by eavesdroppers while in transit or ascertain that the data comes from who says it is. The first, you manage with SSL as with any other secure transaction, as already sugested. For the second is what you might want to use a digital signature, that's why someone might have sugested it to you. As a sample of how this would work you read the file into memory, add a long string, the signature, that is never transmitted but that both ends know, and pass it all through an algorithm like MD5 or such. At the receiving end, you get the data and the MD5 but, as I said, the signature is never transmitted, but you know it as well. You do the same process as in the sending end and you should reach the same MD5. Since MD5 is not reversible, knowing the MD5 of this long string, the data plus the signature, cannot reveal the signature even if the data is transmitted in clear text, but no other except someone who has the signature can produce the right MD5. Notice that the data itself is transmitted in clear text, the goal is to ensure that who sends it is who is meant. A similar process has been in use in the banking industry for wire transfers when they were really sent via telex. As mentioned PGP is a far better solution since it covers both requirements and it uses two keys, one for encoding and one for decoding so that each end knows just half of the information and won't require you to use SSL, the problem is that you have to do some processing at the client side and JavaScript alone won't allow you to access the file system. You would have to deploy ActiveX controls or Konfabulator widgets (plust the widget runtime). On the other hand, many eMail clients can send PGP protected messages. Finally, you could get your users to ZIP the files with a password before sending them, which is not so secure but is good enough for many uses. IT all depends on what you want. Satyam - Original Message - From: John A DAVIS To: php-general@lists.php.net Sent: Friday, July 27, 2007 10:21 PM Subject: [PHP] need insights on encrypting and uploading ASCII file using PHP We have various labs that submit coliform sample results in an ASCII file, quoted/comma delimited. We are being asked to encrypt this file for internet transfer. We are also being asked to create a secure process by which to transfer this file across the interent. Currently: the lab pushes and button and generates the ASCII file (12 columns) the lab logs in to a PHP webpage and uses the file upload input to submit the file. If data is valid, file is saved on our server in a folder where we can pull it into the respective tables. Be nice to have some insights on how to encrypt this file at the source and how to transfer the file securely. We keep hearing the words, digital signature. Thanks in advance, John A. Davis Programmer State of Oregon DHS OIS CNE, MCSE Don't think of the problem, think of the solution -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.22/921 - Release Date: 26/07/2007 23:16
Re: [PHP] Authentication
If memory doesn't fail me, if you work with IIS and protect the source pages of the application so that IUSR_x (the generic anonymous user) doesn't have access to those files and instead grant access to the NT users or groups which you want, the IIS when working with IE clients will take care of that as long as they are all in the same domain. I did it with IIS 3 and IE4 and it worked, I am not completely sure about the details, but it is something you do in the server administration and you don't need to do any programming at all, if the person reaches the page it is because it is who he says it is. Otherwise, no browser will give you access to any sensitive information on the client machine, nothing that someone, anyone, might pick on the server side just by receiving a page request. Satyam - Original Message - From: Dan Shirah [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: php-general php-general@lists.php.net Sent: Friday, July 27, 2007 11:02 PM Subject: Re: [PHP] Authentication My application is only used within my company. I want to pull the NT Authenticated user that is logged in, cross reference that user with what I have pulled from ldap and verify the user's name is valid. If the username is valid I will assign it to a variable and use that variable to store the name of the user that submitted the requests. Yes, I am trying to get a single sign on method if possible. $_SERVER['REMOTE_ADDR'] works in bringing back the IP Address of the computer I'm kaing the request from, but $_SERVER['REMOTE_USER'] does not return anything. On 7/27/07, Richard Lynch [EMAIL PROTECTED] wrote: On Fri, July 27, 2007 12:51 pm, Dan Shirah wrote: I looked on PHP.net but I couldn't not find anything suitable to answer my question. Within PHP, is there a way to pull the name of the user that is currently logged into the PC? That data is not transmitted, by design, in an HTTP request. I know with some of the _SERVER functions you can pull the IP of the machine and other data, is there a function within this family that would work? If you can find a JavaScript function to snoop the username, you could then write that into the URL, I suppose... But I suspect that, by design, JavaScript does not do this either. Basically, the username on the visitor's computer is both meaningless and far far far too private to be handing it out arbitrarily. It's meaningless in that any user can buy a PC and set up any username they want on it, and your webserver has NO IDEA what that username means. It's far far far too private, because it's none of your business to know who I am when I'm surfing. If you're trying to get some kind of one login system going, there may or may not be some useful info in the ever-reappearing thread regarding Active Directory and/or LDAP. If you're trying to do something else, post whatever it is you are trying to do, and perhaps you'll get some help. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.22/921 - Release Date: 26/07/2007 23:16 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No is_date() function?
There is no such a thing as a date datatype in PHP. Dates are stored as an integer representing seconds since a base time (1/1/1970) and they cannot be distinguished from other integers. In PHP 5.1 they added a DateTime class which is a good thing for the future, to solve issues like yours, but for the time being, a 'timestamp' as returned by, for example' mktime, is a plain integer. Satyam - Original Message - From: Ken Tozier [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, July 25, 2007 3:55 PM Subject: [PHP] No is_date() function? Hi I wrote a serialization function to turn arbitrary PHP variables into Macintosh plist compatible XML but see that there is no is_date tester as there is for bool, object, array etc. Is there a relatively simple (and robust) way to detect if a variable is a date? For example: $person = array('name'='bob', 'sex'='male', 'date_of_birth'= $someDateHere); Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.19/917 - Release Date: 25/07/2007 1:16 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Displaying HTML characters in real format
Unless you have set the character encoding of the document to the same as what you have, say, in the database, you would have trouble showing, for example, your last name, with that umlaut. Anyway, I would read the comments for the function because I believe there are some issues beyond the characters handled by htmlspecialchars. I just prefer to set the character encoding compatible from end to end. Satyam - Original Message - From: Nisse Engström [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, July 17, 2007 9:03 PM Subject: Re: [PHP] Displaying HTML characters in real format On Fri, 13 Jul 2007 01:24:09 -0500 (CDT), Richard Lynch wrote: htmlspecialchars ONLY escapes four characters: htmlentities escapes ALL characters that need it What characters other than the four (or five) NEED escaping, and why? /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.8/904 - Release Date: 16/07/2007 17:42 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OK to have many files in one folder?
Since it depends on many factors, some out of your control, some others that might vary over the lifetime of the application, one thing you might do, to be on the safe side is try to put files in different directories, for example, by breaking up their filenames every three characters and making each segment a folder but no more than three levels deep so that the file ./abcdefghijkl.jpg would be located at ./abc/def/ghijkl.jpg. This breakup would allow even to mount extra disk volumes for some of the folders, should they exceed certain capacity or to split the risk. Whether to break filenames every two, three or more characters might be a matter of optimization, but I would guess that around three (or four) for the first two segments and whatever is left for the filename would be a reasonable number. I wouldn't go more than three levels deep either, because jumping from one directory level to the next also takes some time, thus it is a compromise in between searching sequentially in a directory for a filename (for those filesystems that do so) and going deep into the directory tree. Satyam - Original Message - From: Brian Dunning [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Friday, June 15, 2007 9:38 PM Subject: Re: [PHP] OK to have many files in one folder? Thanks for the replies but I'm not sure I know what to do with them. Is the problem with the number of files, or is the problem with the activity? Can you dumb down your answers at all for me? :) On Jun 15, 2007, at 11:51 AM, Daniel Brown wrote: 6/15/07, Jay Blanchard [EMAIL PROTECTED] wrote: [snip] Server is running Linux, and PHP is constantly creating and modifying images in a directory. Apache is constantly serving these same images. There are about 250,000 of them in the same directory. Seems to be running OK, no problematic CPU load, but I'm wondering if anyone knows whether I'm living dangerously having that many docs in one directory with that much activity. It is an extremely busy server. Sorry is this seems like more of a linux sysad question than a PHP question. Thanks... :) [/snip] Two words. Beware the inode. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If that directory is all on one single partition, God help you if there's any corruption. Check into RAID 0+1/RAID 5 disk striping if you've got that many images. And remember, the fact that they're all in one directory doesn't matter at all to the system, as directories, folders, et cetera, are just representations for human readability and organization. In fact, those files reside on several sectors throughout the drive, and each file itself is probably fragmented many times. Just for fun, though, if you want to crash your server, you could always do: `while [ 1 = 1 ]; do ls -l;done` -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.472 / Virus Database: 269.8.16/849 - Release Date: 14/06/2007 12:44 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL Connection in Session ?
In most systems, database connections are pooled, meaning that when you give them up, they are not completely closed but the sql client software keeps them in a pool available for the next script asking for a similar connection, thus saving on the time to establish a connection.It is the connection between your script and the sql client that gets cut, the database does not know your script is gone, since the sql client doesn't tell it. For the pooling to work, it is necesary that all the connections requested have the same parameters, including user name and password. If you change username for each page, then the client software has to actually establish a connection for that user to retrieve the proper permisions. Of course, that connection would also be sent to the pool once the page is processed, but then the pool would soon fill up with many connections, one per username, each seldom used and in a really busy server, the connection would be dropped out of the pool before it gets a chance to be reused. Storing those many connection in session variables only moves the problem from having the sql client manage a large pool of little used connections to have PHP sessions do the same thing, far more inneficiently. The best thing is to make sure all connections you use are opened with exactly the same parameters, use just one connection for all the script (unless, of course, you actually have to connect to different databases) and let it go as fast as you can to give the next in line a chance to reuse it from the pool. Satyam - Original Message - From: PHP Mailing List [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Monday, June 11, 2007 6:53 PM Subject: [PHP] MySQL Connection in Session ? Can I maintain just one mysql connection resource to all my pages per user session. As far as I knows create connection is more expensive than executing queries ? Any reference how to make efficient for connection resources ? Thanks, Dino -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.472 / Virus Database: 269.8.13/843 - Release Date: 10/06/2007 13:39 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: Return or not to return, that is the question
- Original Message - From: Richard Davey [EMAIL PROTECTED] That is all my original thread was ever really asking - I was just curious what other people thought about returning from functions that don't actually require a return value. So far the responses have been pretty varied, from the (somewhat blinkered) 'how can a function never return something?', to 'yes I always return' to 'no I just let it run out'. My rule is to write what you mean, and if you don't mean to return anything valid or worth anything, just don't. If you explicitly put a return it should be for a reason, whatever you return should be meaningful. If I find a 'return true' at the end of a piece of code, I will check if there is any condition where it returns false, because I will assume that the return true is significant and so should be its obvious alternative. I would also wonder why the caller doesn't use that return value or if it does, why is there no 'else' part. In a similar line, I use 'null' in databases when I mean 'I have no valid information for this field'. Basically, the idea is to be clear in what you mean. If you put a return it should be because you mean to return something. If you mean you don't know, use 'null', don't default to zero or any other implausible value for that field. This kind of arbitrary conventions dilute the self-documenting value of well-written code, quite the opposite, they would need to be documented themselves to avoid missinterpretations. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ajax?
I´ve been using the YUI library and, specifically for AJAX, the Connection Manager (http://developer.yahoo.com/yui/connection/), but also many of the other components in YUI. I find that some of the frameworks are a little heavy, covering both the JavaScript side and the PHP server side. In some you deal with the PHP side and in some misterious way JavaScript gets sent to the client, but they are too obscure for my taste, I prefer to know what goes on. YUI coupled with Firefox with the FireBug debugger plugin is a great combination and on the server side you are quite free to do and use whatever you want. And don't miss the videos of the presentations of Douglas Crockford on JavaScrit and the DOM. Satyam - Original Message - From: Emil Edeholt [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, May 09, 2007 5:04 PM Subject: [PHP] Ajax? Hi! What do you guys use to develop ajax applications and do you have any good articles on the subject? I've just about finished an ajaxish site but it wasn't fun. A lot of nesting javascript inside php calls, having to write the logic both in javascript and php and so on. The source looks ugly and was time consuming to debug. Thanks! Kind regards Emil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.467 / Virus Database: 269.6.6/794 - Release Date: 08/05/2007 14:23 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how to detect type of image
Sorry I'm late to this thread, I don't know if it has been mentioned, but most files have a 'magic number' at the begining of the file, which usually reads as a couple of letters or more. I think EXE files start with MZ, gifs with GIFxx where xx is the last two digits of the year of the standard. Just open files of the types you are concerned about and check the first few characters. Satyam - Original Message - From: Richard Lynch [EMAIL PROTECTED] To: Jonathan [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Wednesday, April 25, 2007 4:30 AM Subject: Re: [PHP] Re: how to detect type of image On Sun, April 22, 2007 10:35 am, Jonathan wrote: Alain Roger wrote: Hi, In my web application, end user is able to load images (png, jpeg, gif,..) into database. I would like to know how can i detect automatically the type of image (pnd, jpeg,...) ? i do not want to check the extension because this is easily faked... just by renaming it. Does it exist a technique for that ? thanks a lot, Is there anything wrong with just using $_FILES['upload_name']['type']? Yes. The first thing wrong, is that the idiot browser-makers can't even agree on what to cram into that when a user uploads a simple JPEG, much less some more esoteric document. So, right there, what you have in there under normal circumstances is pretty much garbage. The second thing wrong is that the Bad Guys can cram any dang thing they want in there, regardless of what they are uploading. So they can upload a nice .exe binary file and cram image/jpeg into the type. If your script is equally insecure throughout, then you could easily end up having an executable file up on your server that the Bad Guy wrote, and all they have to do is surf to it for it to run. That would be bad, just in case it's not terribly obvious. :-) Other than that, though, it's fine and dandy to use it... :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.463 / Virus Database: 269.6.0/775 - Release Date: 24/04/2007 17:43 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ${}
- Original Message - From: Man-wai Chang [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, April 25, 2007 3:23 PM Subject: [PHP] ${} where can I find the documentation about this symbol? It is one of those almost hidden treasures that is documented, a little bit here and there, but it doesn't have a page on its own. It is used to dissambiguate complex variables, specially when embedded within double-quoted strings, so the interpreter knows how far does the variable name and its parts go and when the rest of the string goes. For example, if withing a double-quoted or heredoc string, the variable name is immediately followed by a text or number without any spaces in between, the interpreted can't know whether those characters are part of the variable name or not. Also, when you want to refer to an array element or an object property, the resulting expression might get somewhat more complicated and there might be ambiguities as to how far does the variable goes and where the rest of the string goes. It might also be used to generate variable names on the fly, ${'variable' . $i} will produce the contents of $variable0 for $i = 0. I think it was also used to refer to individual characters within a string as if it was a character array, but that is deprecated in favour of square brackets. Satyam -- .~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Ubuntu 6.10) Linux 2.6.20.7 ^ ^ 21:22:01 up 6 days 2:08 0 users load average: 1.00 1.00 1.00 news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.463 / Virus Database: 269.6.0/775 - Release Date: 24/04/2007 17:43 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Find MAC Address in PHP
I'm sorry, I missed that, you are right, unless there are subnets within the company, several offices in distant locations. Satyam - Original Message - From: Zoltán Németh [EMAIL PROTECTED] To: Satyam [EMAIL PROTECTED] Cc: Nathaniel Hall [EMAIL PROTECTED]; php-general@lists.php.net Sent: Saturday, April 21, 2007 9:10 AM Subject: Re: [PHP] Find MAC Address in PHP The OP said he wants MACs for the machines on his local LAN. In that case I don't think he would have meet the things you said. greets Zoltán Németh 2007. 04. 21, szombat keltezéssel 07.49-kor Satyam ezt írta: Don't bother, if you manage to get a MAC, it won't be that of the client machine in the majority of cases since the IP you get for the request is not, in most cases, the one for that machine, but that of the proxy, router and zillion of other things that step in the middle and change the IP. Satyam - Original Message - From: Nathaniel Hall [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Friday, April 20, 2007 10:00 PM Subject: [PHP] Find MAC Address in PHP Hi all, I am attempting to find the MAC address of systems visiting my page from the local LAN. I have tried several things, but it appears it will not let me run system commands. For example, running ?php $MAC = system(arp 192.168.200.254); echo $MAC; ? does not give me any output. I have copied arp to a place that the apache user can execute from and ensured arp is executable. This is on a Fedora Core 6 box running PHP 5.1.6-3.4 and Apache 2.2.3-5. Any help is appreciated. -- Nathaniel Hall -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 17:56 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.463 / Virus Database: 269.5.6/770 - Release Date: 20/04/2007 18:43 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Find MAC Address in PHP
Don't bother, if you manage to get a MAC, it won't be that of the client machine in the majority of cases since the IP you get for the request is not, in most cases, the one for that machine, but that of the proxy, router and zillion of other things that step in the middle and change the IP. Satyam - Original Message - From: Nathaniel Hall [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Friday, April 20, 2007 10:00 PM Subject: [PHP] Find MAC Address in PHP Hi all, I am attempting to find the MAC address of systems visiting my page from the local LAN. I have tried several things, but it appears it will not let me run system commands. For example, running ?php $MAC = system(arp 192.168.200.254); echo $MAC; ? does not give me any output. I have copied arp to a place that the apache user can execute from and ensured arp is executable. This is on a Fedora Core 6 box running PHP 5.1.6-3.4 and Apache 2.2.3-5. Any help is appreciated. -- Nathaniel Hall -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 17:56 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Appending into associative arrays
$fmtime = filemtime($d); if (!array_key_exists($fm,$dir)) $dir[$fm] = array(); $dir[$fm][] = $d; This would give you an array indexed by filetime containing arrays of filenames. You may try and see if the last line is enough on its own, but I believe it once happened to me that it failed to create a two levels deep array of arrays in just one shot, that's why the second line. Alternatively you could use the filename as key of the second array and store in it any information as data, for whatever you might need: $dir[$fm][$d] = some data related to $d. Satyam - Original Message - From: Otto Wyss [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, April 15, 2007 9:20 PM Subject: [PHP] Appending into associative arrays I want to sort directories according there modification time and thought accociative arrays would be perfect. But when I add an element like $dirs = array (filemtime($d) = $d) the previous ones are lost. I tried array_push but that doesn't seems to work, at least I always get syntax errors. Next try was array_merge(array (...)). So what next? O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.4.0/761 - Release Date: 14/04/2007 21:36 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Json.php
www.json.org lists all json resources in any language you care to think of. Satyam - Original Message - From: Otto Wyss [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, April 14, 2007 10:11 AM Subject: [PHP] Json.php I've seen a json.php file somewhere in a project for cases where the json module isn't installed (e.g. PHP4), yet I can't find that project again. Is there an official or unofficial download site for json.php? Why isn't this available in the PHP manual (http://ch2.php.net/manual/de/ref.json.php)? O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.4.0/760 - Release Date: 13/04/2007 20:04 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'lang' file editor ...
maybe I should consider moving my 'shit' into gettext format. That was just what I was going to sugest: using gettext format. Nevertheless, I find php-gettext far more flexible and, since it is in source format, you might want to modifiy the part that reads in the compiled translation file and use it to read in whatever format you find suits your needs. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'lang' file editor ...
- Original Message - From: Jochem Maas [EMAIL PROTECTED] Satyam wrote: maybe I should consider moving my 'shit' into gettext format. That was just what I was going to sugest: using gettext format. yeah, but I curerntly have 30 odd files each with upwards of 2000 strings in them, and it would also require changing the code base to use gettext (which is the easy part since I already use a wrap function for all the string/translation grabbing) Nevertheless, I find php-gettext far more flexible and, since it is in source format, you might want to modifiy the part that reads in the you mean this?: http://savannah.nongnu.org/projects/php-gettext/ I'm not sure I want to use userland code that does what gettext extension does [faster] (I'm quite happy to install/configure gettext and all the relevant locales) especially given that the author begins with I don't like php much ... but none the less I'll check it out. It is the gettext used by Wordpress and some other software that doesn't rely on people being happy installing and configuring gettext, so I guess it will be supported well beyond the likes or dislikes of the original developer. Nevertheless, since you already have the part of wrapping the translatable strings done, you might also want to check the PHP Compiler: http://phpcompiler.org/ as an alternative way of finding tokens. compiled translation file and use it to read in whatever format you find suits your needs. Satyam -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.2.0/757 - Release Date: 11/04/2007 17:14 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] free allocated memory: HOW ?
When you free memory you are only marking memory as available for reclaiming, but it doesn't mean it will actually reclaim it at all. The garbage collector usually runs at a very low priority and if you don't give your process a break, it will never catch up. One thing I would try is to insert a call to sleep() within the loop and see if that gets the garbage collector to do some catching up (and if it does, please let us know). Another thing would be to have a master process shelling out processes to process a template one at a time. It might either be either through exec() or using curl to request Apache to deal with handling the processes. The end of each individual process would free all its memory and, after all, that is the way PHP is meant to run and has been highly optimized to do. Using some shared memory to communicate whatever needs to be shared would avoid too much repetition. If the templates to be processed are large, perhaps you can get some external utility to process it far more efficiently. Nevertheless, I wouldn't try any of that until I exahusted all that can be done on the programming side. Are you using file_get_contents to read whole chunks at a time? Is it really necesary? Can you manage to read a line at a time? If having the whole template in memory is required, can you break it up into an array with explode() and operate on each line at a time or whatever unit you have? Or better yeat, have it read a line at a time into an array and avoid the explode(). Memory gets a better chance of being reused if it is split into many smaller chunks. Using square brackets to access and specially modify individual characters as if the string is an array of characters works on the string right in place, avoiding copying and trashing the memory, though it might not be faster. Anyway, these are no more than random thoughts and nothing beats a good application design, something that nowadays, with so much memory and powerful processors tends to be overlooked. Someone famous once said that 64kbytes was all the memory anyone would ever need. Satyam - Original Message - From: Arthur Erdös [EMAIL PROTECTED] To: [EMAIL PROTECTED]; Jochem Maas [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, April 12, 2007 3:13 PM Subject: Re: [PHP] free allocated memory: HOW ? I am using PHP version 5.1.2. on my dev machine. The same problem with PHP 5.2.1 on webserver. I am generating mails based on a HTML Template. If you look at the appended screenshot you'll see that after reading the template with fread() memory_get_usage() says ~386 MB in use... Then the placeholders in the read template are replaced by customized values within a loop. The size of the used memory grows permanently in each loop by approx 30 MB. any ideas what i am doing wrong and where i [ab]use php? ^^ Jochem Maas schrieb: Arthur Erdös wrote: Hello all, is there a way to free memory allocated by variables in PHP?? This is a very important issue concerning long running scripts... this is a recurrent problem - not much can be done about it AFAIK ... I'd be very glad to be proved wrong. I have a script that generates 5000 Newsletters and when the script finishes it uses 1.8 GB (!!) of RAM. Although I am using unset() to clean up variables (tried with $var = null too). okay this does suggest your doing something else very wrong - I personally have code that regularly generates upto 20,000 individualised newsletters without going anywhere near this ammount of memory - granted I've hit my memory limit a couple of times and had to jack it up to 128Megs (in practice the script grab just over 64Megs when it's doing it's worst). what version of php are you [ab]using? I've read sth about php not giving the allocated memory back to the OS until a script finishes, is that right?? Is it possible to free the memory by hand? Any suggestion is appreciated! thx in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.2.0/757 - Release Date: 11/04/2007 17:14 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dates and different time zones
- Original Message - From: Richard Davey [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, April 10, 2007 3:43 PM Subject: Re: [PHP] Dates and different time zones Niklas Karlsson wrote: I am creating an international site that is going to get used in both American and Europe. And I wonder how to handle the different time zones, because I want the date and time to be correct after the place your using the application. I now have the date_default_timezone_set() to Europe/Stockholm, and all dates that is saved into the database is timestamp with time zone (using PostgreSQL). So a wonder who to handle different time zones? Have any of your experience of this? Store all of your dates as GMT. Perform all date based calculations around GMT also, and then offset the values for localised display only. This way you only need to store the GMT offsets for each user, i.e. GMT+1 or GMT-8 when it comes to displaying the dates to them. The trick is to use a constant base date for all data, and only being the user timezones into play when needed. Actually, I find that it is better not to bother storing anything for the user at all. At the first chance, get some JavaScript to read the local time of the client machine and send it back to the server, either with the login data, using some AJAX or along with any link the user might click on the welcome screen, for example, the language choice. Then use the offset from his local time to the server time for every time information, substract it from any time information you read from them, add it to anything you send them. This works whether the user is registered or not, whether he/she travels or remains in the same time zone and spares you the trouble of keeping your IP to country to timezone table updated. It assumes that the user updates the time zone on his/her machine and if he doesn't it means she doesn't care, so why should you. (some travellers prefer to keep their portable machines set to their home-base time zone) Satyam Cheers, Rich -- Zend Certified Engineer http://www.corephp.co.uk Never trust a computer you can't throw out of a window -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/754 - Release Date: 09/04/2007 22:59 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dates and different time zones
- Original Message - From: Lester Caine [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, April 10, 2007 4:37 PM Subject: Re: [PHP] Dates and different time zones Satyam wrote: Store all of your dates as GMT. Perform all date based calculations around GMT also, and then offset the values for localised display only. This way you only need to store the GMT offsets for each user, i.e. GMT+1 or GMT-8 when it comes to displaying the dates to them. The trick is to use a constant base date for all data, and only being the user timezones into play when needed. Actually, I find that it is better not to bother storing anything for the user at all. At the first chance, get some JavaScript to read the local time of the client machine and send it back to the server, either with the login data, using some AJAX or along with any link the user might click on the welcome screen, for example, the language choice. Then use the offset from his local time to the server time for every time information, substract it from any time information you read from them, add it to anything you send them. This works whether the user is registered or not, whether he/she travels or remains in the same time zone and spares you the trouble of keeping your IP to country to timezone table updated. It assumes that the user updates the time zone on his/her machine and if he doesn't it means she doesn't care, so why should you. (some travellers prefer to keep their portable machines set to their home-base time zone) Of cause the major fault with this is that it can only display the CURRENT time offset. You *ALSO* need the users Daylight Saving Zone as well. This has been giving us great fun since the winter dates and times need a different offset to the summer ones. Something that simplistic browser time offset does not supply. :( The point is that you don't store the time offset in any user profile or anywhere but a session variable, which you keep for the duration of the session so it lasts only while the user is connected, whether logged in or not, profile or not. Next time he/she connects you get the new offset. If the time has changed due to daylight savings or the user travelling elsewhere, you'll get a new offset. The only time it fails is if the user is connected while the time switch is happening, but so will most of the clocks, watches and whatever is on at the time. Satyam The only way to get this working properly at present is to get the user to set their time/daylight settings in their profile, and then you can provide the correct offset for all days on a calendar. Remember that for users WITH a daylight saving offset, one day each year has 23 hours and one 25 hours ;) -- Lester Caine - G8HFL - Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact L.S.Caine Electronic Services - http://home.lsces.co.uk MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/ Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/754 - Release Date: 09/04/2007 22:59 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dates and different time zones
- Original Message - From: Niklas Karlsson [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, April 10, 2007 5:32 PM Subject: RE: [PHP] Dates and different time zones Thanks for good answers. Okay, so I should set the default time zone to central GMT time, and then save GMT offset for every user. This sounds realistic, because I don't think that I need to correct the time for users that doesn't login. Well, that was my whole point. If you store the GMT offsets for each user at a certain time in the year, they will turn invalid when they switch from daylight savings to no savings. Not all countries use daylight savings and even those that do don't switch at the same time. Furthermore, northern and southern hemispheres switch in opposite directions, if and when they do. If your users have to log in, that is the perfect time to read their current local time from the browser and keep it just for the session. Don't store it permanently. In PHP dates are stored as seconds from an arbitrary zero set at Jan 1st, 1970, so does MySql with date/time values though it shows them formatted but you can use the UNIX_TIMESTAMP function to get the actual timestamp. JavaScript uses milliseconds from the same base date. The rest is plain arithmetic. Satyam So, if I now have the GMT offset for every user, how do I display the right date? Can someone please show some phpcode? I would be very grateful if someone could do that. Satyam wrote: Store all of your dates as GMT. Perform all date based calculations around GMT also, and then offset the values for localised display only. This way you only need to store the GMT offsets for each user, i.e. GMT+1 or GMT-8 when it comes to displaying the dates to them. The trick is to use a constant base date for all data, and only being the user timezones into play when needed. Actually, I find that it is better not to bother storing anything for the user at all. At the first chance, get some JavaScript to read the local time of the client machine and send it back to the server, either with the login data, using some AJAX or along with any link the user might click on the welcome screen, for example, the language choice. Then use the offset from his local time to the server time for every time information, substract it from any time information you read from them, add it to anything you send them. This works whether the user is registered or not, whether he/she travels or remains in the same time zone and spares you the trouble of keeping your IP to country to timezone table updated. It assumes that the user updates the time zone on his/her machine and if he doesn't it means she doesn't care, so why should you. (some travellers prefer to keep their portable machines set to their home-base time zone) Of cause the major fault with this is that it can only display the CURRENT time offset. You *ALSO* need the users Daylight Saving Zone as well. This has been giving us great fun since the winter dates and times need a different offset to the summer ones. Something that simplistic browser time offset does not supply. :( The only way to get this working properly at present is to get the user to set their time/daylight settings in their profile, and then you can provide the correct offset for all days on a calendar. Remember that for users WITH a daylight saving offset, one day each year has 23 hours and one 25 hours ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/754 - Release Date: 09/04/2007 22:59 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dates and different time zones
You are totally right, I am sorry. I would hate to miss my plane or train due to such mistake. Satyam - Original Message - From: Lester Caine [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, April 10, 2007 6:29 PM Subject: Re: [PHP] Dates and different time zones Satyam wrote: Of cause the major fault with this is that it can only display the CURRENT time offset. You *ALSO* need the users Daylight Saving Zone as well. This has been giving us great fun since the winter dates and times need a different offset to the summer ones. Something that simplistic browser time offset does not supply. :( The point is that you don't store the time offset in any user profile or anywhere but a session variable, which you keep for the duration of the session so it lasts only while the user is connected, whether logged in or not, profile or not. Next time he/she connects you get the new offset. If the time has changed due to daylight savings or the user travelling elsewhere, you'll get a new offset. The only time it fails is if the user is connected while the time switch is happening, but so will most of the clocks, watches and whatever is on at the time. Please read what I wrote. The time offset from the browser is only of use to map CURRENT time. It is no use to display dates and times stored in the database that are reliant on the daylight saving offset. If TOMORROW is after the change in daylight saving, then the browser offset will not give you the right offset for tomorrows. The problem is convincing people that there *IS* a real problem, and trying to display the correct times JUST from a timezone offset is wrong for at least half of the year! You need to know that the time is changing tonight so that you can display tomorrows calendar correctly? -- Lester Caine - G8HFL - Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact L.S.Caine Electronic Services - http://home.lsces.co.uk MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/ Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/754 - Release Date: 09/04/2007 22:59 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sense last record
I would use some JavaScript on the client side to go through the table and change the classes once the whole page is loaded. Otherwise, for a pure PHP solution, I might either load the whole table on an array, which is wasteful in memory, or defer the actual output of each record until the next record is read so, if no further records exist, I would change the class name of the row still in a variable and output the row right after the loop ends before the end of the table. Satyam - Original Message - From: Mário Gamito [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Monday, April 09, 2007 3:31 PM Subject: [PHP] Sense last record Hi, I'm doing this site that has three news in the homepage. You can see the static version here: http://www.telbit.pt As you can see, the two first news have blocoTexto class and the third, blocoTextoLast Now, i'm developing a dinamyc structure where the news are stored in a MySQL database and retrieved from there. My problem is with the third news and it's different class. I'm using AdoDB recordSet to get the news from the database. You can see it here: http://www.telbit.pt/2/ How can i sense that i've reached the last row and apply the blocoTextoLast class to it ? My code follows my signature. Any help would be appreciated. Warm Regards -- :wq! Mário Gamito -- div id=blocoNews ?php include('config.php'); include('adodb/adodb.inc.php'); // connect to MySQL $conn-debug=1; $conn = ADONewConnection('mysql'); $conn-PConnect($host,$user,$password,$database); // get news data $recordSet = $conn-Execute(SELECT date, now, title, lead, body FROM news ORDER BY date DESC LIMIT 3); if (!$recordSet) print $conn-ErrorMsg(); else while (!$recordSet-EOF) { print 'div class=blocoTexto' . ' h3' . $recordSet-fields[2] . '/h3' . 'p class=data' . $recordSet-fields[0] . '/p' . 'p' . $recordSet-fields[3] . '/p' . '/div'; $recordSet-MoveNext(); } echo br class=\clear\; $recordSet-Close(); $conn-Close(); ? !-- end #secContent -- /div -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/752 - Release Date: 08/04/2007 20:34 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql if empty
An empty result is still a valid result. As long as the SQL statement is valid, you will get a result set. This doesn't meant that the variable holding the reference to the result set is itself empty, but that you will fail to fetch any results from it. Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Monday, April 09, 2007 11:18 PM Subject: [PHP] mysql if empty If I search for something in mysql that returns an empty result I cant get it to return No result found always returns Found even though the recoed does not exist... $sql = SELECT Client FROM booked WHERE Name = 'larry'; $result = mysql_query($sql); if ($result == ) { echo No result found; } echo Found; - Original Message - From: Martin Marques martin@bugs.unl.edu.ar To: Stut [EMAIL PROTECTED] Cc: Tijnema ! [EMAIL PROTECTED]; tedd [EMAIL PROTECTED]; Peter Lauri [EMAIL PROTECTED]; Ólafur Waage [EMAIL PROTECTED]; php-general@lists.php.net Sent: Monday, April 09, 2007 9:45 PM Subject: Re: [PHP] Session Authentication Stut escribió: As with most things these days it probably breaches the DMCA. But frankly speaking, if doing that works then the developers of the application, and by extension the company, deserve everything they get. DMCA is a real piece of crap. -- select 'mmarques' || '@' || 'unl.edu.ar' AS email; - Martín Marqués | Programador, DBA Centro de Telemática | Administrador Universidad Nacional del Litoral - -- 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/752 - Release Date: 08/04/2007 20:34 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] keeping credit card info in session
Check the local legislation regarding keeping such sensitive information. Many countries do have strict requirements for handling credit card info. Your bank might help you find what the rules are. Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, April 08, 2007 8:26 PM Subject: [PHP] keeping credit card info in session Hi All, I've got quite a bit or php experience, but I've never had to deal with credit card info before. Now for a property rental site, I'm adding a way for users to be able to fill out a form which also has some credit card info in it. After they submit the form, there are a couple of more steps and to pass credit card info to the last page, I'm storing all the info in my session. Now, I did go and bought an SSL certificate, so the booking section of the site is on SSL (https). I'm just wondering if this is secure enough. as far as I know, SSL means connection to server is secured, so session variables should be secured too. no? Also after I get credit card info, I'm storing them in a mysql table until an admin would log in to the site, see new reservations, charge them manually and contact the customer, and then that entry will be removed from my database for ever. Is this ok? or is it a really bad idea? originally the plan was to send an email to the admin with credit card info, but then I realized that emails are very unsecure. so I decided to keep the info on the SSL section of the site. just because I'm dealing with credit cards, I'm so afraid of doing anything now. Any suggestions? or perhaps any links to how to make it all more secure? Thanks a lot in advance, Siavash -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/751 - Release Date: 07/04/2007 22:57 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] keeping credit card info in session
Notice the URL starts with 'usa'. In other countries you do have to go by the local laws. - Original Message - From: Dan Harrington [EMAIL PROTECTED] To: 'Satyam' [EMAIL PROTECTED]; [EMAIL PROTECTED]; php-general@lists.php.net Sent: Sunday, April 08, 2007 11:32 PM Subject: RE: [PHP] keeping credit card info in session Its not the country rules to worry about, it is Visa and MasterCard who will come down hard on you with $$ penalties if you don't maintain cardholder security correctly. http://usa.visa.com/merchants/risk_management/cisp.html?ep=v_sym_cisp Dan -- Dan Harrington NXGEN Payment Services 112 12th Ave. S. Nampa, ID 83651 208-498-1666 (voice) 208-498-1667 (fax) [EMAIL PROTECTED] -Original Message- From: Satyam [mailto:[EMAIL PROTECTED] Sent: Sunday, April 08, 2007 3:25 PM To: [EMAIL PROTECTED]; php-general@lists.php.net Subject: Re: [PHP] keeping credit card info in session Check the local legislation regarding keeping such sensitive information. Many countries do have strict requirements for handling credit card info. Your bank might help you find what the rules are. Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, April 08, 2007 8:26 PM Subject: [PHP] keeping credit card info in session Hi All, I've got quite a bit or php experience, but I've never had to deal with credit card info before. Now for a property rental site, I'm adding a way for users to be able to fill out a form which also has some credit card info in it. After they submit the form, there are a couple of more steps and to pass credit card info to the last page, I'm storing all the info in my session. Now, I did go and bought an SSL certificate, so the booking section of the site is on SSL (https). I'm just wondering if this is secure enough. as far as I know, SSL means connection to server is secured, so session variables should be secured too. no? Also after I get credit card info, I'm storing them in a mysql table until an admin would log in to the site, see new reservations, charge them manually and contact the customer, and then that entry will be removed from my database for ever. Is this ok? or is it a really bad idea? originally the plan was to send an email to the admin with credit card info, but then I realized that emails are very unsecure. so I decided to keep the info on the SSL section of the site. just because I'm dealing with credit cards, I'm so afraid of doing anything now. Any suggestions? or perhaps any links to how to make it all more secure? Thanks a lot in advance, Siavash -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/751 - Release Date: 07/04/2007 22:57 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.0.0/751 - Release Date: 07/04/2007 22:57 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help me to solve this math maze
You'll give 100 'units' to 6 of them, and 75 to 6, thus: 6 * 100 + 6 * 75 == 1050 units Each 'unit' is valued at: 3000 / 1050 == 2.8571 Thus, you give: 6 * 285.71 + 6 * 214.28 == 2999.94, and you may keep the change ;-) Satyam - Original Message - From: Faisal Murad [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, April 04, 2007 11:44 AM Subject: [PHP] help me to solve this math maze i am making a program to give money to a group of people lets say that i have to distribute 3000 among 12 people 6 of them are adult and will get 100% 6 them are children those will get 75% from the overall amount. a common solution might appear as divide 3000 to 12 which is 250 give 250 to adults and 75% percent of it to children which is 187.5 after this kind of calculation i have 375 more to give which was supposed to be equally distributed among them can anyone understand my problem and assists me. faisal No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.25/745 - Release Date: 03/04/2007 12:48 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] storing functions
- Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Ross [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Wednesday, April 04, 2007 3:29 PM Subject: Re: [PHP] storing functions Ross wrote: I am wondering how you store and recall your functions. I have an external file - functions.php, this includes all the functions for the site. It is included in the pages head and then I just use the functions when I need them. Does anyone have a better way to store/recall functions? having an army of chinese type in the required files from memory using altair 8000 interface for every request. only joking. How I miss front panels in octal: http://en.wikipedia.org/wiki/Image:Altair8800.jpg This modern thing of having two hexadecimal digits that fit exactly on a byte boundary is child play. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Language detection with PHP
- Original Message - From: Zoltán Németh [EMAIL PROTECTED] In formal english, it's not allowed to use 've 'm etc, I'm should be written as I am. So that's not gonna work i think. But words like and are really english i think :) Keep in mind that this is quite a hard way i think, but i don't have a better solution. Just for example, Dutch and Afrikaans are not very different, so it's really hard to see which of the 2 the text is written in. Tijnema ps. If you can't get the difference between Dutch and Afrikaans, guess for Dutch :) It's a lot more used then Afrikaans. yeah, looking for very frequently used words seems better idea. greets Zoltán Németh In Spanish, as it happens with many languages that use diacritical marks, in informal chatting you often skip them. This has a long tradition in the internet since years ago the support for those extra characters was non-existent and today it is still somewhat patchy. I used to have two modes of writing in Spanish, formal writing with all proper accents, tilde and umlauts and email mode, without any of those. Nowadays, with support for languages using the Roman alphabet widely available, there is no need to omit diacritical marks, but you will often find them missing, particularly in comments to blogs and other informal writing, just because of laziness or carelessness or simply lack of formal education and in that I include foreigners who more or less handle the language but not the minor details. If English had accents, I would probably skip them. So, using a spelling dictionary is not a good idea unless you can count your input to be properly written. A text in Spanish with its accents missing will give you lots of errors, and we use just one sort of accent (acute) plus tilde and umlaut. The French use three sorts of accents, there is a far higher chance of getting misspellings. I don't know how abundant accents are in Magyar, for me Zoltan Nemeth is the same as Zoltán Németh, but the first is a misspelling. This problem also affect the frequency of individual letters. Should you first convert accented vowels to their plain version? Because if you find accented letters, it is a sure sign that it is not English, but if there is none, it doesn't mean it is English, it might be some non-English text without the correct accents. Should you count 'a' and 'á' separate or add them together because people often omit the accent? So, I also vote for the frequently used words approach and against the lowest number of misspellings. And I would first convert everything to plain, with no accents, both for the needle and the haystack. Satyam PS: also, it is accepted practice to omit accents on uppercase letters such as in headings. It is not gramatically correct but a typographical convention which the printing industry has been using for ages: the accents simply don't fit nicely. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Timezone offset
- Original Message - From: Chris Boget [EMAIL PROTECTED] My server's timezone is set to (GMT) Greenwish Mean Time : Dublin, Edinburgh, Lisbon, London. There you have why, you set it to GreenwiSh, which is kind of Greenwich but not quite. I think that being on the western end of Europe, those countries decided to adopt a more pan-European time zone, even if that does not match precisely their astronomical hour. That makes cross border businesses easier by having common working hours. It might also have to do with whether it is Savings Time or not. I remember going to the Greenwich observatory and the big clock there didn't show the local time at all. (and the line carved on the floor is not 0 longitude either, that line is more than a hundred meters east of the real geographical 0), Satyam But when I echo out date( 'O' ), it's returning the offset as +0100 and not +. Why? I would think that it should return +. Am I wrong? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.20/736 - Release Date: 27/03/2007 16:38 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Timezone offset
Since about the US and most of the world that still do daylight savings started doing so, which was bout WWII. Most of Europe does, we changed this past weekend. We don't match the US in the dates, but we do it. In the Southern Hemisphere they do it the opposite way, since summer and winter come in opposite months of the calendar, so time differences with countries in different hemispheres (north south) might move about 2 hours along the year. Satyam - Original Message - From: Chris Boget [EMAIL PROTECTED] To: Tijnema ! [EMAIL PROTECTED] Cc: PHP General php-general@lists.php.net Sent: Wednesday, March 28, 2007 4:35 PM Subject: Re: [PHP] Timezone offset On 3/28/07, Chris Boget [EMAIL PROTECTED] wrote: My server's timezone is set to (GMT) Greenwish Mean Time : Dublin, Edinburgh, Lisbon, London. But when I echo out date( 'O' ), it's returning the offset as +0100 and not +. Why? I would think that it should return +. Am I wrong? What about DST? Hmm, I didn't think the UK observed DST already. When did that happen? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.20/736 - Release Date: 27/03/2007 16:38 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] short open tags not working even if enabled - lighttpd + fastcgi
- Original Message - From: Tijnema ! [EMAIL PROTECTED] On 3/27/07, Matt Arnilo S. Baluyos (Mailing Lists) [EMAIL PROTECTED] wrote: Hello everyone, I have a working lighttpd + fastcgi + PHP + eaccelerator installation. I have also enabled short tags on the /usr/local/lib/php.ini but I'm having problems with PHP not escaping the short tags. To better illustrate, my phpinfo() file can be accessed at http://202.171.164.70/phpinfo.php - if you notice short_open_tag is set to On. But when you access a PHP page at http://202.171.164.70/admin/login.php and try to view the source, the short open tag is not escaped. Any reason why this isn't working as expected? Regards, Matt You also use XML in your page, and thereby i would NOT recommend using short tags. as xml tags also start with ? Indeed, ?xxx is called a 'Processing Instruction' (PI) and the ? should be followed by some identifier indicating the nature of that PI, the identifier XML, in any combination of upper and lower case letter is reserved. So, contrary to other means of escaping out of HTML mode, such as ASPs % tags, the ?php prefix is perfectly valid. A short tag, though, a simple ? is invalid since it lacks the identifier of the expected recipient of that PI. Though it doesn't work that way, PIs would in principle, allow several interpreters each to handle a section of an XML file so if you could chain interpreters or it there were a master PI dispatcher, a single source file could mix several processors of whatever is contained within PIs, not only procedural languages such as PHP but any other kind of process. Satyam Better learn to start PHP tags with ?php and disable the short tags. This way i cannot ever give problems with the ?xml tags.s Tijnema -- Stand before it and there is no beginning. Follow it and there is no end. Stay with the ancient Tao, Move with the present. -- 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.18/734 - Release Date: 26/03/2007 14:31 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] POST a variable
Do a 'select @@identity', it will give you the last record id. The gap in between steps 3 and 4, brief as it may seem, is enough to get you in trouble. Satyam - Original Message - From: Dan Shirah [EMAIL PROTECTED] To: Németh Zoltán [EMAIL PROTECTED] Cc: php-general php-general@lists.php.net Sent: Friday, March 23, 2007 4:07 PM Subject: Re: [PHP] POST a variable The reason I have to use it as I posted is because I am using Microsoft SQL server instead of MySQL. And I haven't found a php function for MSSQL that works the same as mysql_insert_id() So, to come out with a comparable function with pretty reliable results, I follow this process: 1. User enters data into form 2. User submits form 3. Save page inserts info into the database 4. Directly after the insert statement is my SELECT MAX query 5. I assign the retrieved value to a hidden field 6. I pass this value to the next form I figure the odds of another record being inserted inbetween the time it takes to go from step 3 to step 4 are very, very minimal. We're talking about MAYBE a 2-3 millisecond gap? On 3/23/07, Németh Zoltán [EMAIL PROTECTED] wrote: 2007. 03. 23, péntek keltezéssel 10.45-kor Dan Shirah ezt írta: Okay, I feel like the correct answer to this is about 2mm back in my grey matter. 1. I have a query that pulls the last row number when a newly inserted record is added: $maximum=SELECT MAX(payment_id) FROM payment_request; $max_result=mssql_query($maximum); while($max=mssql_fetch_row($max_result)){ } $max_id = $max[0]; 2. I have multiple selections for the user to pick, but regardless of what they choose I want the $max_id variable to be passed to the next page. 3. Would I go about this by assigning $max_id to a hidden field like below? input type=hidden value=?php echo $max_id; ? size=5 maxlength=10 name=max_id / 4. And then to retrieve this value on my next page just get it out of $_POST['max_id'] ?? Does that all sound correct? basically yes but if you want the id of the row you just inserted, using mysql_insert_id() is better because if another insert is happening at the same time, select max() may give you incorrect result greets Zoltán Németh No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 22/03/2007 7:44 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Add New Records Only!
Delete from table where id = (select min(id) from table group by field1, field2 ,... having count(id) 1) Id is the unique primary key, fieldn are the fields that can be duplicated. Each time this runs it will remove one occurence of the all duplicated records. You'd have to run it several times until it deletes no more records. In MySql, you cannot have the same table in the 'delete' and in the subquery, thus, you will have to first insert the id's in an auxiliary table and then delete the records. Satyam - Original Message - From: Rahul Sitaram Johari [EMAIL PROTECTED] To: Mark markw@mohawksoft.com; PHP php-general@lists.php.net Sent: Friday, March 23, 2007 5:24 PM Subject: Re: [PHP] Add New Records Only! Ave, Three: Insert everything and remove duplicates later. Out of the suggested options, this option is sounding the most sane attainable on my end. I don't have a complete grip on how to accomplish this, but certainly sounds feasible. Let me look at ways to achieve this. Thanks! On 3/23/07 11:36 AM, Mark markw@mohawksoft.com wrote: Rahul Sitaram Johari wrote: As far as I can see, there is probably only three ways to do this: One: Make sure your dbase system contains unique primary key capability, and use it to avoid duplicates. Two: query for the row, if it isn't there insert it. (You'll have to deal with concurrency with locking or something) Three: Insert everything and remove duplicates later. Ave, Let me explain what I¹m trying to do. Unfortunately it¹s not a very simple Add/Update transaction. Basically I gather records from multiple mySQL tables and add them to a DBF (dbase) database. I wrote a code which was able to accomplish this without any problems and the add_records goes very smooth. However, I have to modify this program now so that only ³New² records, i.e., records that have not yet been transferred, are added into the DBF. In other words, any records that are being added, which already exist in the DBF, should not be added. If it were just adding records from one mySQL to another mySQL, I could easily use INSERT IGNORE or the Unique Key fundamental however, since I¹m adding from multiple mySQL tables into DBF, I¹m not sure how to go about doing this. Here¹s my code that takes records from multiple mySQL tables and adds them to a DBF. // define the array with mySQL Table Names Identifier $tChoice = array( lodispo = VB, lodispo_osma = ATL, lodispo_osmh = HOU, lodispo_osmn = NSV, lodispo_osmp = PAA, lodispo_osmj = JAX, lodispo_osmt = TPA, lodispo_dmam = MET, lodispo_osmf = FTM, lodispo_hfglend = GLEND, lodispo_hfmesa = MESA, lodispo_hfphenx = PHENX, ); // open DBF in read-write mode $db2 = dbase_open($theDBFfile, 2); if (!$db2) { echo BRBRSTRONGFatal Error:/STRONG Unable to open databaseBRBR; exit; } else { // Let's Run Array Loops! foreach ($tChoice as $tblQ = $bxQ) { // connect to mySQL tables one by one mysql_select_db($database_imslead_transfer, $imslead_transfer); $query_loDispo = SELECT * FROM $tblQ; $loDispo = mysql_query($query_loDispo, $imslead_transfer) or die(mysql_error()); $row_loDispo = mysql_fetch_assoc($loDispo); $totalRows_loDispo = mysql_num_rows($loDispo); // write mySql data to Dbf do { dbase_add_record($db2, array( $row_loDispo['phone'], $row_loDispo['comments'], $row_loDispo['starttime'], $row_loDispo['endtime'], $row_loDispo['dispo'], $row_loDispo['loanofficer'], $row_loDispo['verifier'], $bxQ)); } while ($row_loDispo = mysql_fetch_assoc($loDispo)); } dbase_close($db2); } Any suggestions would be highly appreciated. Thanks, ~~~ Rahul Sitaram Johari CEO, Twenty Four Seventy Nine Inc. W: http://www.rahulsjohari.com E: [EMAIL PROTECTED] ³I morti non sono piu soli ... The dead are no longer lonely² -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 22/03/2007 7:44 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] POST a variable
It seems to me @@identity should sufice, and it certainly does not need to be any 'new' function, since it had been there for quite a while. My feeling is that those added functions might be used for elaborate stored procedures, where you might be dealing with multiple tables or some fancy administrative uses. You certainly DON'T want any function that gives you the last identity of some other connection! $get_max = SELECT @@identity; $max_result = mssql_query($get_max) or die(mssql_error()); $max_id = mssql_fetch_row($max_result); echo $max_id[0]; Though the fetch will return only one record with only one field, it will still return that as an array, even if it only contains one element, so you still need to add the [0]. Unfortunately, PHP doesn't allow the brackets to a function that returns an array. You might use mssql_result instead: $get_max = SELECT @@identity; $max_result = mssql_query($get_max) or die(mssql_error()); $max_id = mssql_result($max_result,0,0); echo $max_id; Satyam - Original Message - From: Dan Shirah [EMAIL PROTECTED] To: Satyam [EMAIL PROTECTED] Cc: php-general php-general@lists.php.net Sent: Friday, March 23, 2007 7:48 PM Subject: Re: [PHP] POST a variable Sorry, I was more tailoring my question to the syntax of my query. It wasn't displaying anything for my echo. I've changed it to this now: $get_max = SELECT scope_identity(); $max_result = mssql_query($get_max) or die(mssql_error()); $max_id = mssql_fetch_row($max_result); echo $max_id; But all my echo returns is array instead of the number. Below are brief explanations of the different _identity uses you have. SELECT *@@IDENTITY* Returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value. SELECT *IDENT_CURRENT(*'*tablename*'*)* This new function returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value. SELECT *SCOPE_IDENTITY()* This new function returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value. On 3/23/07, Satyam [EMAIL PROTECTED] wrote: I don't really know about the scope_identity() function, neither much about @@identity. I know that the names preceded by @@ are MSSQL internal variables and I think that is the one you are looking for, I just checked in the on-line MS documentation, but have no SQL server active at this moment, nor have I dealt with one for the last few years, though I did use auto-increment fields and I certainly was able to retrieve the last id, somehow. I might be wrong and there might be another function or variable that gives you the value, but it looks to me @@identity is the one you are looking for. There is no need in your code to do any while, if the SQL statement doesn't fail and triggers the die(), you can rest assured you'll get a record with a single field, even if it only contains a null, that's the way with variables, you can't fail on them, though they might return null. Satyam - Original Message - *From:* Dan Shirah [EMAIL PROTECTED] *To:* Satyam [EMAIL PROTECTED] *Sent:* Friday, March 23, 2007 7:14 PM *Subject:* Re: [PHP] POST a variable Satyam, I'm trying to retrieve the id using the identity method, but I do not get anything returned. Do you see anything wrong with this code? $get_max = SELECT scope_identity(); $max_result = mssql_query($get_max) or die(mssql_error()); while($max=mssql_fetch_row($max_result)){ } $max_id = $max[0]; echo $max_id; On 3/23/07, Satyam [EMAIL PROTECTED] wrote: Do a 'select @@identity', it will give you the last record id. The gap in between steps 3 and 4, brief as it may seem, is enough to get you in trouble. Satyam - Original Message - From: Dan Shirah [EMAIL PROTECTED] To: Németh Zoltán [EMAIL PROTECTED] Cc: php-general php-general@lists.php.net Sent: Friday, March 23, 2007 4:07 PM Subject: Re: [PHP] POST a variable The reason I have to use it as I posted is because I am using Microsoft SQL server instead of MySQL. And I haven't found a php function for MSSQL that works the same as mysql_insert_id() So, to come out with a comparable function with pretty reliable results, I follow this process: 1. User enters data into form 2. User submits form 3. Save page inserts info into the database 4. Directly after the insert statement is my SELECT MAX query 5. I assign the retrieved value to a hidden field 6. I pass this value to the next form I figure the odds of another record being inserted inbetween the time it takes to go from step 3 to step 4 are very, very minimal. We're talking about MAYBE a 2-3 millisecond gap? On 3/23/07, Németh Zoltán [EMAIL PROTECTED] wrote: 2007. 03. 23, péntek
Re: [PHP] Re: Random Unique ID
I'm sorry if I am repeating something that has been said, but in the comments to: http://es2.php.net/manual/en/function.uniqid.php there is a little piece of code that generates UUID as per RFC 4122, and those get as unique as they come. MySql has a UUID() function and so do any database engine that supports replication, since that's the only way to ensure keys won't get repeated over multiple servers. Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Friday, March 23, 2007 7:48 PM Subject: [PHP] Re: Random Unique ID Robert Cummings writes: Bleh, you can solve this with at most 2 queries. Thanks. That is a bit different than what I was thinking about but it might work for my purposes. Thanks also to all the other people who made suggestions. It appears to me that ther are 3 distinct approaches. 1) Generate a random number. Query the DB to see if it has been used before and if so generate another random number and repeat. It seems to me that this would require that the DB be locked for the checking and insertion to make sure a duplicate was not slipped in. 2) Generate a random number. Make a trial insertion for a unique field. If the insertion fails repeat. This functions just like the above but uses Mysql's native behavior to handle the checking so no user locking is necessary. Almost all the time this will require only 1 insertion whereas the above will require 2 or more accesses. 3) Generate a unique identifier from the record sequence number. Since the sequence number is guaranteed to be unique the identifier will also be unique and can be used without any worry. There are various schemes I can think of by which the unique identifier, altho uniquely determined by the sequence number, can be generated so that it will not reveal the sequence number and appear unpredictable. This will require 3 accesses to the DB (insertion, mysql_insert_id, and update). I have a number of options to try and think about. Thanks again. Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 22/03/2007 7:44 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IP to City detection
It is very hard to get to the level of city. It is the way the networks are built. I live in a minor town. My provider has a node in this city, but it gathers all the traffic of the whole area (my town and neighboring towns) and sends it through an internal link to their major regional center. Depending on availability, my traffic might get to the Internet (uppercase Internet, the big, public, global one which links us all together) right through that regional node or, depending on traffic, it might get beamed over somewhere else and get into the Internet at another less busy node. Big providers are constantly shufling traffic around depending on the availabilty of their own internal network and that of their wholesale provider. The IP you see exposed to the Internet is that of the node where your provider internal network connects to the public network, the uppercase Internet. Due to national regulations, it is usually hard for one national provider to use IP addresses belonging to another country so, IP to country tables are quite reliable. IP to city is not reliable at all, there is not external rules imposing arbitrary borders on traffic so a provider is free to send packets wherever it becomes more efficient. Moreover, if a client has the same provider as your service, the IP address you receive might be an internal IP address and not an actual Interner address. Internal IP addresses have little restrictions, they can be almost anything. If that were the case, all bets are off. These days with the CeBit show running at Frankfurt, Deutsch Telekom (sorry about the spelling) might be struggling with their bandwith around that area. Data packets might be popping about everywhere in Germany and, if they have agreements with neighboring countries, some might be showing up at Denmark, Austria or Poland, who knows! My town is close to Barcelona, Spain. When they had the 3G mobile phone conference there last month, my packets might be going to Tarragona, Valencia or even all the way to Madrid. Comercial IP to location databases, at least, keep in close contact with the major providers so they have a close idea of how are they routing their packets. Non-comercial databases don't have the resoorces to keep updated. The only reason they are more or less reliable at the IP to country level is that governments have different regulations in each country and they know there is value in the information flowing through the optical fibers so, while they figure out how to tax those bits and bytes, they make it just a little more hard for them to flow from one country to the next, but within a single country, there are no limits. Satyam - Original Message - From: William Lovaton [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, March 21, 2007 1:24 PM Subject: [PHP] IP to City detection Hi people, Is there a way to detect the city of a person based on the IP address? I mean something like ip2nation http://www.ip2nation.com/ but for cities so I can use it in my PHP web application. Thanks for any help you can give me, -William -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.15/728 - Release Date: 20/03/2007 8:07 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Name Capitalization
- Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Leonard Burton [EMAIL PROTECTED] Cc: Chris W. Parker [EMAIL PROTECTED]; PHP php-general@lists.php.net Sent: Tuesday, March 20, 2007 11:09 AM Subject: Re: [PHP] Name Capitalization Leonard Burton wrote: HI Chris, Here is one option. Make a long list (array) of search/replace pairs and loop through your text replacing as necessary. 'mcdonald' = 'McDonald' 'mcdowell' = 'McDowell' 'o\'reilly' = 'O\'Reilly' 'de la rosa' = 'De La Rosa' etc ad nauseum... I think the better solution would be some pregs that would go through and look for mc then have it turn the name into Mc then Capitalize the next letter. [same thing for mac] Then Do the same thing with O'Henry it would look for o\' then it would turn it into O' and capitalize the H. Let us know when you're done! :) This project shouldn't be that hard as there are probably only 10 to 15 rules for names. give or take a few *thousand* variations alot of which will conflict, take for instance the surname prefix 'de' - in a spanish name (we'll assume Chris' example is correct) the 'd' of a 'de' prefix should be capitalized BUT in a dutch name the 'd' of a 'de' prefix should not capitalized: JOSE DE LA ROSA = Jose De La Rosa FRANK DE BOER = Frank de Boer this actual example may not be valid Indeed, it is not. The correct capitalization is José de la Rosa. At least in Spanish the rules are quite simple, unless someone is actually called 'De', neither 'de', ' la' ,'del', 'y', 'e' or 'i' would be capitalized, and there is no such a thing as a capital letter in the middle of a word or name, not in native Spanish names at least. Nevertheless, you would expect the first letter of a sentence to be capitalized so a news heading such as 'De la Rosa won a 3rd place for McLaren' is correct. Satyam but I guarantee that you'll come across this kind of conflicting rules that are language/region/culture based and that you will have pretty much no chance of determining which rule to apply given just the name input. Chris' suggestion of a 1 to 1 map using an assoc array is actually probably the cleanest and most successful strategy - but rather you than me when it comes to compiling that list ;-) though please do put it online when you have completed it :-P assuming the correction that is made to the name capitalization is presented to the user you could consider asking the user whether it is correct and/of offering a number of variations (including an 'other' field) from which they could choose - this is based on the idea that you'll probably guess the capitalization wrong quite a lot of the time but that regardless of that fact you may still be able to offer an interface that is helpful to the user - even if it's not saying much more than 'HEY CHIEF, ARE YOU SURE YOU WANT YOUR NAME TO LOOK LIKE THIS?' Take Care, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.14/727 - Release Date: 19/03/2007 11:49 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image digit to check password
- Original Message - From: Jay Blanchard [EMAIL PROTECTED] [snip] however, several website also propose an additional security to avoid hacking/brute force, they display a 4 digit image with a random string including number and letters... something like A3P23. if user do not respect case and string, password is not changed. I would like to know how such system works and if a tutorial exist about that ? [/snip] Google captcha Not that long ago, your reply would have been considered gibberish Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Getting last record ID created from DB
- Original Message - From: markw@mohawksoft.com I guess maybe most databases support the notion of auto number in some form. I haven't used MSSQL recently, but I think their solution is a GUID. You can set an auto-increment attribute on any integer data type. They also have GUIDs, which they recomend using if you plan on using replication, as any autonumeric sequence is local to each database and there will be repetitions over multiple servers, something GUIDs won't. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Getting last record ID created from DB
- Original Message - From: markw@mohawksoft.com There in lies the biggest problem with LAMP, and that's MySQL. The architecture of your methodology *only* works with MySQL, and not more capable databases like Oracle, DB2, or even PostgreSQL. If you rely on oddities of a particular system, then you are doomed to be stuck with it or pay the price of redesign when you need a more capable system. Not so much. Most databases offer some sort of autoincrementing integer and a means to get its value immediately after an insert. The syntax both for creating it and retrieving it might vary, but it exists in some form or other. This does not excuse the overuse of autonumerics as primary keys and most often, the only key in a whole table. Significant keys, that is, keys that are meaningful for the data being stored, are far more valuable if they exist. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirecting in a PHP script
- Original Message - From: tedd [EMAIL PROTECTED] At 11:28 PM -0500 3/14/07, Richard Lynch wrote: On Tue, March 13, 2007 11:54 pm, Chris Shiflett wrote: Tijnema wrote: Did you guys ever noted that little arrow down just right of the back button, where you can go back 2 steps at once, so you don't have to click very fast? I think we both remember browsing before that feature was invented. I remember the fire-storm when the IMG tag was introduced. Death of the Internet. Film at 11 Various news posts went like this: I mean, my God, man, you're going to include a FIFTEEN KILOBYTE file on your web page?!!! What, are you crazy???! That's going to melt-down the entire Internet! :-) :-) :-) Yeah, I remember similar comments about using a mouse -- hey, things change. tedd -- And this nonsense of a glass-tty! how are you supposed to really make sense of a program staring at that thing, seeing just 24 lines at a time? It can't compare with browsing through fanfold paper in the confort of your desk, or even at home! Whenever, wherever an idea hits you, paper and pencil is just so handy. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP URL issues
There are lies, damned lies and statistics. Had he known about benchmarks! I have already tried different ways of producing output and I completely disagree that concatenating the pieces and then echoing them is the best. In a first try, I found that echoing the separate parts as arguments to echo with commas in between was the fastest and variable interpolation within double quotes strings (or heredoc) was fastest than concatenation. Nevertheless, in a later trial, the numbers which were so clearly in favor of echo with multiple arguments, turned only slightly better, not enough to justify the loss of flexibility of building up a string first and having the option of manipulating it. This last sentence was confusing, lets see. When writing functions, you might either have them do the echo themselves or returning a string. The first is fastest, the second offers flexibility. If the first is really much faster, I'm willing to do away with the flexibility, which is no more than a potencial benefit, since 90% of the time I might have nothing at all to do with the return value of the funcion and, if really needed, I might use output buffering. Neverhteless, if the straight echoes are not that much faster, I'd rather keep an ace in my sleeve and go with returning strings. In my first trial, the result was conclusive, it was about 4 to 1, in the second, it was about 20% faster. The first was done on my own personal machine, a Windows machine doing nothing else, the second on my ISP shared hosting with an unknown load. I might say that my test on my own idle machine was the most representative, since it didn't have to deal with external issues such as competing for external resources, but then, that competition is really part of life. Though avoiding the memory shuffling of doing many string concatenations, doing echoes with multiple arguments might require the interpreter to negotiate access to IO buffers more often than building the whole page in memory and then getting it echoed just once. And I am sure that the way Windows and Linux handles IO with Apache is quite different, so, which benchmark is really representative? I am sure that some benchmarks are quite representative, independent of platforms. For example, it would make sense that doing an exact equality (triple =) should be faster than a plain equality. The first fails straight away if types are different and in no case is any conversion made. In the second, if the types don't match conversions need to be made first (after figuring out which one to make) so logic indicates it should take longer. Nevertheless, I don't feel like testing it out since the results, as my previous experience indicate, seem to be so uncertain. I'm not even arguing whether it makes sense or not in trying to shave off a few ticks of the clock. I am sure that a machine handling who knows how many users requests simultaneously will appreciate any little help, actually, I'm not sure I am actually looking for answers because, as far as I know, the answer is: it depends Satyam - Original Message - From: Richard Lynch [EMAIL PROTECTED] To: Steve [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Wednesday, March 14, 2007 10:07 AM Subject: Re: [PHP] PHP URL issues On Tue, March 13, 2007 9:31 am, Steve wrote: This may or may not help, but here's a few things to note: 1) I would avoid placing variable output in double quoted strings. While not important for smaller scripts, doing a large number of outputs like this causes a decent performance hit. In fact, I wouldn't use double quotes ever in php. Instead, strive for something like: echo 'ba href=test.php?term='.$letter_value.''.$letter_value.' nbsp;/a/b'; Have you benchmarked this, or can you provide a link to others' benchmarks demonstrating this perofmrnace hit?... -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.11/721 - Release Date: 13/03/2007 16:51 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fw: [PHP] PHP URL issues
One more example of a questionable benchmark, not wrong but I wonder (as I was doing in my previous) whether it is really representative. There are two main ways to handle strings, one is to malloc exactly the required memory for each string and keep moving characters around from one chunk of memory to another. If you append a single character to a string, you would measure both, add their lengths plus whatever overhead your data representation requires, malloc that much memory, move the characters from each source and then free the memory occupied by the first. The other way to do it is to malloc memory in more or less fixed sizes and include in the header of your variable a length field. With plenty of memory available nowadays, few still choose the first option. Appending a few characters does not require any new memory allocation nor freeing it up. The later method depends on how good where your statistics (more damned lies once again) about the average string length, but if you get it right, appending to a string ( .= operator) becomes as fast as appending to a StreamBuffer, as found in other languages with separate Strings and Streams classes. Some languages do not even require string space to be contiguous so that when one block is used up you don't have to get a bigger one and move everything to the new place, the blocks comprising the string are linked in a list. That's one reason why lots of languages now prefer 'immutable strings', it is no longer possible to treat the string as an array of characters since they cannot be accessed via a simple offset. This benchmark is probably exercising more the symbol table lookups and memory allocation functions than the actual concatenation, since it is allocating and freeing up lots of space for really tiny strings that don't take much of that space at all. Whatever difference there is in the actual string operation might be clouded under other factors. Regardless, I do prefer to use single quotes and, as I mentioned elsewhere, I just echo the bits and pieces as soon as I am able, reasoning that the output buffer is truly a stream buffer and since the echo is a language construct (no function call overhead), it should be faster than managing memory to hold strings. As I said, though, the performance of one option against others varies so much in different trials under different conditions that I feel foolish just to show them. Then, not even logic works fine if you mean to define what is faster and what is not. Sometimes the developers, using profilers and such tools, find a very slow spot and they get to optimize it to such an extent that it works faster than its un-optimized relative, which under equal circumstances would have actually been faster. Using single quotes for PHP strings frees me the double quotes for HTML attribute values without any need to escape them. I have defined CRLF and TAB as constants which I can redefine at any time to an empty string if I no longer care my HTML output to be readable. Since I prefer to keep all values in their native PHP format up to the last moment, and those values have to be passed either through htmlentities(), number_format(), money_format() or strftotime() on output, variable interpolation is out of the question anyway. Satyam - Original Message - From: Steve [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, March 14, 2007 3:25 PM Subject: Re: [PHP] PHP URL issues I personally have not unfortunately. A good friend of mine is also a developer who initially told me about it when I first began coding. Because I don't want to stick with the he-said, she-said approach, I did a quick google search and came up with this link: http://spindrop.us/2007/03/03/php-double-versus-single-quotes/ There's several other pages saying similar things if you do look around. Even the performance different isn't significant, it will add up. If something like this is known to help ever so slightly with execution time and it's something you can teach yourself to do subconsciously, then I feel it's definitely worthwhile to pursue. Richard Lynch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Tue, March 13, 2007 9:31 am, Steve wrote: This may or may not help, but here's a few things to note: 1) I would avoid placing variable output in double quoted strings. While not important for smaller scripts, doing a large number of outputs like this causes a decent performance hit. In fact, I wouldn't use double quotes ever in php. Instead, strive for something like: echo 'ba href=test.php?term='.$letter_value.''.$letter_value.' nbsp;/a/b'; Have you benchmarked this, or can you provide a link to others' benchmarks demonstrating this perofmrnace hit?... -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So
Re: Fw: [PHP] PHP URL issues
- Original Message - From: Robert Cummings [EMAIL PROTECTED] To: Satyam [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Wednesday, March 14, 2007 4:49 PM Subject: Re: Fw: [PHP] PHP URL issues On Wed, 2007-03-14 at 16:31 +0100, Satyam wrote: One more example of a questionable benchmark, not wrong but I wonder (as I was doing in my previous) whether it is really representative. There are two main ways to handle strings, one is to malloc exactly the required memory for each string and keep moving characters around from one chunk of memory to another. If you append a single character to a string, you would measure both, add their lengths plus whatever overhead your data representation requires, malloc that much memory, move the characters from each source and then free the memory occupied by the first. The other way to do it is to malloc memory in more or less fixed sizes and include in the header of your variable a length field. You forgot realloc(). Yes I did, but it doesn't matter that much. When asigning by blocks the best strategy is to keep all blocks the same size, or of a few assorted sizes, and link them in lists because blocks of different sizes end up fragmenting the memory too much and giving the garbage collector lots of trouble, if all blocks are of the same size, they are immediately reusable. Basically, if you are dealing with the memory yourself, assigning it, freeing it, collecting garbage afterwards and defragmenting, you won't resort that much to individual calls to the memory library functions, you just grab a big chunk and manage it on your own. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP URL issues
You should use urlencode() on variables that will go into URL arguments. You might have a whitespace in any of those variables and the URL stops at the first whitespace. If those spaces are at the ends and are not significant, you might want to use trim(). - Original Message - From: Don Don [EMAIL PROTECTED] To: PHP List php-general@lists.php.net Sent: Tuesday, March 13, 2007 11:37 AM Subject: Re: [PHP] PHP URL issues I've just noticed that if am passing only one value it works fine, but when am passing in more than one none works. Why is that or what could be wrong ? e.g. this works echo ba href='test.php?term=$letter_value'$letter_value nbsp;/a/b; on test.php i can display the value of term but with this echo ba href='test.php?term=$letter_valuetype=$type_value'$letter_value nbsp;/a/b; on test.php the values are empty. Nikola Stjelja [EMAIL PROTECTED] wrote: If you are going to insert variables like $var_name in a string you need to enclose that string with double qoutations marks, not single. PHP will replace var names with values only inside double qoutations. Hope that helps On 3/12/07, Don Don [EMAIL PROTECTED] wrote: I've got the following url rewriting problem. on page 1 i've got this p a href='page1.php?messageId=$tmpForumuserId=$user_id' See /a/p and on page 2 i've got this $messageID = $_REQUEST[messageId]; $userID = $_REQUEST[userId]; when i check to see the values of these variables its says its empty, but when i place my cursor on the link in page 1 i can see both variables being show with their values in the browser. But on page 2 i cant get the values Something seems wrong perharps ? Cheers - Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. -- Please visit this site and play my RPG! http://www.1km1kt.net/rpg/Marinci.php - Don't get soaked. Take a quick peek at the forecast with theYahoo! Search weather shortcut. No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 12/03/2007 19:19 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP URL issues
I wouldn't do the htmlentities() on the whole argument list. Depending on the Doctype version you have declared and depending how well implemented it is in each browser, it may render the argument list useless. Unless you declared the strictest and latest version of HTML, all browsers will take a plain in between arguments instead of an amp;. Haven't you seen the page source as received by the browser? All browsers give you that option somewhere in their menues. What does the URL look like in the Location box in the browser? Just to know whether the problem is in the assembly of the URL or in reading it back. If the URL shows correctly, try a var_dump($_GET). Show it within a pre section so even whitespace is clearly visible. Satyam - Original Message - From: Don Don To: Satyam ; PHP List Sent: Tuesday, March 13, 2007 4:01 PM Subject: Re: [PHP] PHP URL issues $query_string = 'testId='. urlencode(trim($tmpTestId)) . 'userId=' . urlencode(trim($tmpUserId)); print 'pa href=viewpage.php?'. htmlentities($query_string) .' View Values /a/p'; on view page i am trying to display the values using $_GET[value] and it sill returns Satyam [EMAIL PROTECTED] wrote: You should use urlencode() on variables that will go into URL arguments. You might have a whitespace in any of those variables and the URL stops at the first whitespace. If those spaces are at the ends and are not significant, you might want to use trim(). - Original Message - From: Don Don To: PHP List Sent: Tuesday, March 13, 2007 11:37 AM Subject: Re: [PHP] PHP URL issues I've just noticed that if am passing only one value it works fine, but when am passing in more than one none works. Why is that or what could be wrong ? e.g. this works echo $letter_value ; on test.php i can display the value of term but with this echo href='test.php?term=$letter_valuetype=$type_value'$letter_value ; on test.php the values are empty. Nikola Stjelja wrote: If you are going to insert variables like $var_name in a string you need to enclose that string with double qoutations marks, not single. PHP will replace var names with values only inside double qoutations. Hope that helps On 3/12/07, Don Don wrote: I've got the following url rewriting problem. on page 1 i've got this See and on page 2 i've got this $messageID = $_REQUEST[messageId]; $userID = $_REQUEST[userId]; when i check to see the values of these variables its says its empty, but when i place my cursor on the link in page 1 i can see both variables being show with their values in the browser. But on page 2 i cant get the values Something seems wrong perharps ? Cheers - Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. -- Please visit this site and play my RPG! http://www.1km1kt.net/rpg/Marinci.php - Don't get soaked. Take a quick peek at the forecast with theYahoo! Search weather shortcut. No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 12/03/2007 19:19 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- We won't tell. Get more on shows you hate to love (and love to hate): Yahoo! TV's Guilty Pleasures list. -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.10/720 - Release Date: 12/03/2007 19:19
Re: [PHP] Data Types Problem
Since in PHP you don't declare variable types, PHP does its best to guess what you mean with your values and integers have preference to strings, so your '01' gets converted to a plain integer 1 for the comparison. Use === (triple) equal in the comparison and it will check for both value AND type and it won't do any type conversion. Satyam - Original Message - From: Arno Coetzee [EMAIL PROTECTED] To: php-general php-general@lists.php.net Sent: Monday, March 12, 2007 8:26 AM Subject: [PHP] Data Types Problem Hi Guys I seem to have a problem with data types in php when executing the following script , i do not get the desired output. i a pass url parameter (message) to the script. if i pass a numeric value (1) , the script accepts it as '01' and vice versa. the same with 0 and '00' here is the script: ?php $theMessage = $_REQUEST['message']; echo theMessage : ' . $theMessage . '\n; if ($theMessage == 01) { echo message : '01'; }else if ($theMessage == 00) { echo message : '00'; }else if (is_numeric($theMessage)) { echo Numeric Input : . $theMessage; }else { echo Invalid Input; } ? i presume that i am not interpreting the data types it should be interpreted. can anyone please help -- Arno Coetzee Flash Media Group Developer Mobile : 27 82 693 6180 Office : 27 12 430 7597 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.8/718 - Release Date: 11/03/2007 9:27 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Posting variable outside of the post form
- Original Message - From: David Giragosian [EMAIL PROTECTED] To: Otto Wyss [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Monday, March 12, 2007 8:18 PM Subject: Re: [PHP] Posting variable outside of the post form On 3/12/07, Otto Wyss [EMAIL PROTECTED] wrote: I submit a form back to itself with action=?PHP echo $_SERVER['PHP_SELF']; ? methode=get yet I've a large PHP variable which I'd like to access afterwards as well. Is this possible somehow? O. Wyss Cookie, session variable, session cookie, database layer... David Or a hidden field input type=hidden but, since you mentioned the value might be large, it might either be advisable to take any of David's sugestions or change to a method=post. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array mysteries
- Original Message - From: Otto Wyss [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, March 11, 2007 11:14 AM Subject: Re: [PHP] Array mysteries Steve Edberg wrote: At 9:51 AM +0100 3/11/07, Otto Wyss wrote: function convert_from_weekday ($weekday) { return $wdays[$weekday]; } If the above is your exact code, then the problem is one of scope; move the $wdays declaration inside your convert_from_weekday() function. I'm more used to C++ than PHP, with global $wdays; it works. Unless you are using the array elsewhere, it might be a good idea to put it inside the function so as to not polute the global namespace with variable names that have no need to be there. In large applications, there is a non-trivial chance that someone else might use a variable by the same name and ruin your translation table. It will be slightly slower, though. As for the localization functions, you might see their effect in: http://www.satyam.com.ar/int/setlocale/index.php?locale=de_DEsubmit=Aceptar the input box allows you to enter different locales, the previous URL already has German selected. Satyam However, you may want to investigate the formatting functions of date(): http://php.he.net/manual/en/function.date.php Date should return names using the native locale; if you want to return date strings for other locales/languages, use setlocale() - http://php.he.net/manual/en/function.setlocale.php Thanks, I'll keep this in mind. O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.8/717 - Release Date: 10/03/2007 14:25 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array mysteries
- Original Message - From: Edward Vermillion [EMAIL PROTECTED] To: tedd [EMAIL PROTECTED] Cc: Tijnema ! [EMAIL PROTECTED]; php-general@lists.php.net Sent: Sunday, March 11, 2007 8:57 PM Subject: Re: [PHP] Array mysteries On Mar 11, 2007, at 1:59 PM, tedd wrote: At 12:02 PM -0500 3/11/07, Edward Vermillion wrote: On Mar 11, 2007, at 10:02 AM, tedd wrote: At 3:05 PM +0100 3/11/07, Tijnema ! wrote: On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote: At 10:05 AM +0100 3/11/07, Tijnema ! wrote: - You could define $wdays inside the function function convert_from_weekday ($weekday) { $wdays = array (0 = Sonntag ,1 = Montag ,2 = Dienstag ,3 = Mittwoch ,4 = Donnerstag ,5 = Freitag ,6 = Samstag ); return $wdays[$weekday]; } $day = convert_from_weekday(0) // $day = Sonntag Tijnema: That's also a shorter version of a simple switch statement. I haven't thought of, or seen, that before -- thanks. tedd Yeah it is, but i just used moved his $wdays inside the function... but well, there are ofcourse a lot of other options, as date (l) would also return the day of the month :) Tijnema It's the technique and not the specific data thing I was addressing. When I'm confronted with a case condition, I typically use the switch statement. But, your solution provided me with another way to look at that. Cheers, tedd But what's the cost of this in a loop, rebuilding the array each time, as compared to a switch statement? Just another thought... Ed It's just another way to look at a possible solution. As for the cost, what are we talking about? I doubt that a typical application would show any discernable difference in execution times. One could test this easy enough by running both through 50k loops, but even then I doubt that the times would be that much different -- but I may be wrong, been there before. Cheers, tedd I don't know if there would be any difference either, which is why it was a question. Although Larry's suggestion of making the array static is something I hadn't thought of. Overall it is an interesting concept to use an array instead of a switch, and I do wonder at what point, if any, that the two would start to diverge resource-wise. Would the array lookup be faster for a lesser-used option/key in a situation where there were quite a few options? (you wouldn't have to go through the whole switch to get to the option at the end (?) or would you? I have no idea how that all works internally) Yes, you would. It goes sequentially through each case:. The array, on the other hand, uses a hashing algorithm so it should be about even no matter which option you pick. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Creating variable names from values
- Original Message - From: Otto Wyss [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Thursday, March 08, 2007 5:56 PM Subject: [PHP] Creating variable names from values From an arry I create a table like foreach ($persons as $key = $pers) { echo tdinput name=\K$key\ type=\checkbox\ .../td td.../td } so each checkbox field has its own name created from $key. Yet how can I access these fields (names) later on? foreach ($persons as $key = $pers) { $key = 'K' . $key; if ($$key) { notice double dollar sign, it means, not the value of $key but the value of the variable $key says. if ($K???) { $cnt += 1; ... } } Is there a better way to access multiple fields from a table? O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date: 07/03/2007 9:24 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What sripts,helpers to use for AJAX
'Better' is a little subjective and prone to generate a flame war, but I'll risk my opinion. You might want to check Yahoo User Interface (YUI). The Connection Manager at http://developer.yahoo.com/yui/connection/ provides reliable cross-browser JavaScript code for the client side. You might want to check the YUI for other goodies as well. It only deals with client-side Javascript which lets you handle the sever side pretty much whichever way you want it so you are not forced to buy into a whole framework, client and server side, when you don't really need that much. Unless you have good reasons to serve data in XML format, to keep life simple, I would also sugest you use JSON, which is easy to generate (recent PHP versions have json_encode() and json_decode()) and is native JavaScript. On the client (JavaScript) side, I would recomend this functions: http://blog.davglass.com/files/yui/docs/YAHOO.Tools.html instead of those at http://www.json.org/js.html, though the later site is good in terms of explaining and it has a comparison of different JSON functions for PHP, in case your version does not support it. Satyam - Original Message - From: Otto Wyss [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Thursday, March 08, 2007 6:11 PM Subject: [PHP] What sripts,helpers to use for AJAX I want to add some AJAX communication to my pages and would like to know, what scripts, helpers you would recommend. I don't want to use a full featured framework, just something to do the AJAX work. So far I've come across the following solutions http://prajax.sourceforge.net/ http://sanjer.berlios.de/ yet they both doesn't seem very much used. Does anybody know these or knows better alternatives? O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date: 07/03/2007 9:24 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Intro to PHP question
I am not a linux expert but it might be because instead of running it like php myprogram.php you are just typing myprogram.php in which case, the file needs to have a comment in the first line telling the shell which interpreter should handle it. Some #!php or something like that, not sure. Anyway, it is just the guess of a non-expert. Satyam - Original Message - From: Jonathan Kahan [EMAIL PROTECTED] To: php-general@lists.php.net Cc: Jonathan Kahan [EMAIL PROTECTED] Sent: Thursday, March 08, 2007 5:43 PM Subject: [PHP] Intro to PHP question Hi all, I am using a linux server. When the php file below (uri.php) is run from the command line I get the following error. Any ideas on what I could do differently? Thanks for any help, Jonathan ../uri.php: line 1: syntax error near unexpected token `newline' ../uri.php: line 1: `html' html body?php $d=date(D); if ($d==Fri) echo Have a nice weekend!; else echo Have a nice day!; ?/body /html Kind Regards Jonathan Kahan Systems Developer Estrin Technologies, inc. 1375 Broadway, 3rd Floor, New York, NY, 10018 Email: [EMAIL PROTECTED] Web: http://www.estrintech.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date: 07/03/2007 9:24 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Creating variable names from values
They are called 'variable variables': http://www.php.net/manual/en/language.variables.variable.php and it is under variables! Satyam PS: it sounds obvious once said, but it's usage might not be, so I meant the pun, but not to tease you. - Original Message - From: Otto Wyss [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Thursday, March 08, 2007 8:16 PM Subject: Re: [PHP] Creating variable names from values Satyam wrote: $key = 'K' . $key; if ($$key) { notice double dollar sign, it means, not the value of $key but the value of the variable $key says. Thanks, any idea where this is described in the PHP manual? Searching for $$ produces no results. O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date: 07/03/2007 9:24 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] db query not working
I saw two people pointing two errors on the SQL insert statement which you would have found yourself had you put the 'or die()' at the end of the query, as someone else suggested. Do never leave any query without the 'or die()' after it (or any other means to check if mysql_query returns anything not false). This would have saved lots of your time, our time, everybody's bandwidth and would avoid your asking everybody again for the next error you make. We all make errors, none of us is above that, that's why, at least in my case, I never fail to add the or die() at the end. That's why the developers of function libraries have put some means of reporting errors back. It takes time for providing good error reporting. You are wasting that effort as well. Do you deserve all this speech? No more than the dozens who write what I call 'ballistic' code: code you have no control over once it launches. Guided missiles are far better. Anyway, you got it because I had time to rant about this. Satyam - Original Message - From: Ed Curtis [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, March 07, 2007 3:28 PM Subject: [PHP] db query not working I have this code: mysql_connect ($local_host, $local_user, $local_pass); mysql_select_db ($local_db); mysql_query (DELETE FROM tmphitsmag); $result = mysql_query (SELECT DISTINCT company FROM view_log WHERE company != ''); if ($row = mysql_fetch_array($result)) { do { $magazine_path = $row['company']; $magazine_path = explode(/, $magazine_path); echo str_replace(_, , $magazine_path[2]) . br; mysql_query (INSERT INTO tmphitsmag (magazine) VALUES('$magazine_path[2]'); } while($row = mysql_fetch_array($result)); } mysql_close(); It dumps the table fine, works the explode, outputs the string in the echo command the way I expect, but doesn't place the value in tmphitsmag table. Anyone have a clue? Thanks, Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/712 - Release Date: 06/03/2007 15:42 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] db query not working
- Original Message - From: Jochem Maas [EMAIL PROTECTED] Satyam wrote: I saw two people pointing two errors on the SQL insert statement which you would have found yourself had you put the 'or die()' at the end of the query, as someone else suggested. Do never leave any query without the 'or die()' after it (or any other means to check if mysql_query returns anything not false). This would have saved lots of your time, our time, everybody's bandwidth and would avoid your asking everybody again for the next error you make. We all make errors, none of us is above that, that's why, at least in my case, I never fail to add the or die() at the end. That's why the developers of function libraries have put some means of reporting errors back. It takes time for providing good error reporting. You are wasting that effort as well. Do you deserve all this speech? yes. no error checking, no attempt at self improvement and above all no patience when it comes to waiting for an answer. ... I call 'ballistic' code: code you have no control over once it launches. Guided missiles are far better. might I suggest that the word 'better' shouldn't be used to describe any kind of missile other than a decommissioned one. 'better' ways of killing people are things generally only sought after by fundamentalists, arms-industry employees and megalomaniacs (it just springs to mind that a certain leader of the [not so] free world could happily sit in any of those categories) My apologies, it was not a happy comparison. gun analogies suck almost as much as guns, as opposed to good old rant, which, as long as they're not combined with guns are fairly harmless and quite often informative. Anyway, you got it because I had time to rant about this. we make time to rant ;-) It is an old guy thing, at least in my case (trivia: I was born the day after the ENIAC was turned off) -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/712 - Release Date: 06/03/2007 15:42 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] destructor sequence explained
- Original Message - From: Richard Lynch [EMAIL PROTECTED] To: james james [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Wednesday, February 28, 2007 1:33 AM Subject: Re: [PHP] destructor sequence explained On Tue, February 27, 2007 6:11 pm, james james wrote: Can someone please help explain how the order of object destructors called at shutdown is determined, especially with regards to objects composed of other objects? I think that changed from version to version, so unless you are on a dedicated server, you have to manage any order dependencies for yourself... I do not think there *IS* a documented ordering to this. Actually, I think it is documented that the order of the destructors cannot be predicted. This means that even if you find how it is done in this particular version, don't count on that to hold if in a newer version they change it. By stating that it cannot be predicted, the developers reserve the right to change it at any time. When an object is deleted, it is put in the list of things to be dispossed of, and the garbage collector will call the destructors prior to deallocating the memory. It can happen at any time when there is no higher priority stuff to be done. So, it all depends on the whim of the garbage collector, a background item that the developers might change at any time and whose behaviour depends on lots of unpredictable things such as server load. You get whatever order PHP feels like using. exactly Satyam -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.4/703 - Release Date: 26/02/2007 14:56 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Extract printable text from web page using preg_match
- Original Message - From: M5 [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, February 27, 2007 6:47 PM Subject: [PHP] Extract printable text from web page using preg_match I am trying to write a regex function to extract the readable (visible, screen-rendered) portion of any web page. Specifically, I only want the text between the body tags, excluding any script or style tags within the document, also excluding comments. Has anyone here seen such a regex? Is it possible to do in one expression? ...Rene Though it might be possible to do by handling the HTML document as a plain string, the fact is lots of HTML is nor well formatted. As sugested, using strpos for the start and end tags might be a faster and easier solution than a regex, but no browser will complain if it reaches the end of the document and found no closing body tag. An initial body tag might have lots of attributes, such as onLoad, class, style, target you name it, you'll eventually find it. Unless you know the 'quality' of the documents you plan to parse, I would sugest you use a DOM parser. PHP ships with two alternatives, depending on the version, which might or might not be installed in your setup, otherwise, you'll have to google for something you may use. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] gettext online editor?
- Original Message - From: Vincent DUPONT [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, February 27, 2007 10:33 PM Subject: [PHP] gettext online editor? hello, for translating our web applications, we use to create an XML file with the labels; one label for each entry; one file for each language. This let us: 1. create one file (in french) and let someone do the translations 2. provide the 'key users' (admins) of the application a php page that can be used to edit/change these translations 3. include the xml files into our cvs so that changes are managed 4. provide a new language to the application simply by adding the corresponding file if needed, we can split the file on a functional basis to reduce the amount of data to be loaded. Most of the time however, we simply have some form labels, feedback messages, menu items : less than 50 labels per page. So this works very well. Recently a collegue showed us gettext. As it seems very powerful, the main disadvantage I can see is that translations files are not directly editable. The admin users cannot edit the files and correct/change the translations. Moreover, we work mainly on windows and I'd rather minimize the number of softwares needed by the developers to do their work (php editor, oci, mysql, mssql clients, cvs, svn, firefox, moz, ie, uml editor, ... so many already!) So my question is: do you know if there is any way of editing the gettext translation files from a http page? I mean, without the need to execute a 'compile' (or whatever) action on the webserver. You might want to check PHP-gettext at http://savannah.nongnu.org/projects/php-gettext/. Since it reads external gettext files and stores them internally in PHP data structures (well, arrays) you might patch their data structures. Anyway, it might not be better than your current setup. do you have any comment on translating the applications? yes, but they are in Spanish, (http://www.satyam.com.ar/blog/2007/01/17/internacionalizacion-y-localizacion-indice/) sorry, Europeans often are multi-lingual, perhaps ... of course gettext seems powerful, with caching an so on. But I really believe the new SimpleXML can load a translation file very quickly, and php offers enough functionalities to do cache of the labels in the current language... thank you Vincent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.4/703 - Release Date: 26/02/2007 14:56 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Securing user table with sha function
- Original Message - From: Tim [EMAIL PROTECTED] -Message d'origine- De : Haydar Tuna [mailto:[EMAIL PROTECTED] Envoyé : mardi 20 février 2007 10:34 À : php-general@lists.php.net Objet : [PHP] Re: Securing user table with sha function Hello again, if you crypt your usernames, it happened many problems. As you know, if you crypt any string to SHA1, you don't decrypt again. You cannot use username in your application. in my many application, I have crpyted password , I haven't cryrpt usernames. Becuase I used username for session authentication. for example if I want to action on the usernames or list of usernames , what can I do this? All of usernames are crypted. OK then what if i consider using PHP's Mcrypt extension with a key to crypt/decrypt data, this would give me the possiblity to use a username crypted hash in the session variable and decrypt it at any moment with the proper key? One aproach I have often seen to security is making things complicated, assuming that it will deter intrussion. Complicating things, though, rarely achieves anything useful. Being paranoid about some data you might be complicating your own work and that of those who will have to mantain and upgrade the application afterwards for very little gain. There are good and proven ways to secure an application. If you rarely see anyone going beyond those basic rules it is because the pay off is marginal in terms of security but too complicated in terms of mantainability. Take the user name you are so concerned about. Are you subscribed to eBay and get their newsletter? They send you their mailings with your username in clear to let you know it is indeed from them. eBay runs one of the most secure open sites in the world, and they don't mind sending your login name in the clear, and nor do I so, why should you? Just complicating things don't make a site more secure, it just complicates it. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Language construct
echo, include and a few others are language constructs because they are part of the language itself rather than being functions in the same category as regular functions are. This means that they are integral part of the language, just like 'if', or any operator +, *, etc, though they look pretty much like functions. It means that though syntactically they look as functions and in the manual they are listed under functions, this is only to make them easy to use, understand and locate in the documentation. That is why certain rules for functions can be relaxed, such as requiring parenthesis around its arguments, which are not actually needed but are there so that they have the same look as regular functions. Satyam - Original Message - From: Balasubramanyam A [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, February 20, 2007 3:32 PM Subject: [PHP] Language construct Hello all, I'm new to this group and I'm learning PHP. I want to know what is the exact definition for Language Construct. Could someone please explain about this? No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.441 / Virus Database: 268.18.3/693 - Release Date: 19/02/2007 17:01 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] print() or echo
echo is slightly faster than print and it takes multiple arguments so instead of: echo 'p' . $test . '/p'; you can do echo 'p' , $test , '/p'; which should be faster, and I say 'should' just because as print should be slower because it has to go into the trouble of setting up a return value, so avoiding doing a concatenation first and then output the whole thing by just streaming each of the pieces to the output straight away should be faster, though string operations are so optimized as to be neglig well, you can't tell the difference. Satyam - Original Message - From: Danial Rahmanzadeh [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, February 13, 2007 4:49 PM Subject: [PHP] print() or echo is it true that echo is a bit faster than print()? in general, when we don't need a return value, which one is better to choose? Cheers, Danial Rahmanzadeh No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 12/02/2007 13:23 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] round to nearest 500?
- Original Message - From: Jon Anderson [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hah yeah, always worth a little skepticism, but it seemed to make some kind of sense. If you always round up or always round down, that's obviously not right and you end up losing potentially a lot of money or over-estimating the money involved. Founding up for 5 through 9 and down for 0 through 4 seems like it makes some kind of sense, but apparently it doesn't work out that way. I'm sure someone out there knows what I'm talking about (it might be the first time, but I know I'm not making this up hah), but rounding 0.75 up to 0.8 and 0.65 down to 0.6 (or vice versa) is supposed to be more accurate or at least leads to fewer anomalies. Someone feel like writing a quick script that generates random numbers and does the rounding based on these two ideas (doing it the 'hard way') and see how much variation there is after like 10,000 iterations? If I have time later, I'll do it. Now I'm even more curious. I wasn't aware of the accounting trick before today, but I believe I can explain it: If your numbers are statistically random, then the above solution will lead to an even distribution of rounding up and rounding down. The reason is simple: 0: No rounding. It's already there. (8.0 doesn't need to be rounded to 8 - it already *is* 8.) 1-4: You round down - 4 of 9 times you round down. 5-9: You round up - 5 of 9 times you round up. That is not quite correct, there is no such 4 ninths agains 5 ninths. You round down in the interval from 0 to0.4 and you round up from 0.5 to 0.999. If you substract the .5 from 0.9, you get 0.499 so it is about the same interval for both. If there is any difference, and actually there is, is because any number is, in reality, truncated, and not rounded, at some point. Depending on the number of bits of the mantissa, it might be a long way off, but eventually, it will happen, and that one is truncation, nor rounding, and if you repeat any calculation involving fractional numbers, it will eventually add up to something noticeable. Actually, there is the further problem that computers actually use binary, not decimal, so they cannot represent decimal numbers exactly. To offer an example of what I'm talking about, 1/3, which results in a never ending 0.33 is exactly 0.1 in base 3 arithmetic! Conversely, many 'round' numbers in our decimal notation are not 'round' in binary and viceversa. So it is all the piling of lots of rounding errors in real-life number representations that produce the error, not the mathematics of rounding, which actually work in an abstract world of infinitely precise number representations (in other words, infinite bits to represent any numbers). Satyam So you round up 11.1% more often than you round down. As a result, if you round up when it's odd, and down when it's even, you eliminate the 11.1% difference in when you'd round up then round down. That said, if someone were aware of the above rounding trick, it wouldn't take someone very much effort to come up with things like fee structures or pricing structures that could take advantage of that scheme to force rounding errors to remain permanently in the person's favor. I certainly hope that PHP continues to use the standard technique, and not the accounting trick above. :-) jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 12/02/2007 13:23 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fw: [PHP] Re: Pasar varialbe sin GET
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html - Original Message - From: Anuack Luna [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Monday, February 12, 2007 2:52 AM Subject: [PHP] Re: Pasar varialbe sin GET Disculpa. Por casualidad no tienes una Web donde explique como hacerlo fácilmente He visto varias, pero no entiendo nada Le agradezco Saludos desde Colombia Anuack Luna [EMAIL PROTECTED] escribió en el mensaje news:[EMAIL PROTECTED] Hola a todos. PHP Bueno, mi consulta es complicada Normalmente se pasa una variable así: nombredelarchivo.php?valor=variable nombredelarchivo.php?id=x La pagina nombredelarchivo.php recibe la variable de la otra Web page Hasta hay nop broblem He visto en los portales como por ejemplo crean un solo archivo para imprimir un valor como si fuera una carpeta. Ejemplo: pagina/usuari_1 pagina/usuari_2 pagina/anuack pagina/lolita. Para mi seria lógico que en donde dice anuack es una carpeta... NO??? He visto nombre de archivos {name}.php pero no encuentro como lleva un valor y convierte a {name}.php en anuack, lolita, usuario... etc. Como envía un valor o variable a {name}.php y como la recibe {name}.php si por método GET no funciona También he probado en variable de formulario, cookie, variable de sección Algo ilógico pero lo probé, variable de servidor y valor introducido y nada de nada Claro, puedo hacer que me imprima por ejemplo 18.php, pero no encuentra el archivo. Alguna información clara en español. Espero haberme explicado -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to parse PHP tags in a string?
- Original Message - From: Zak Mc Kracken [EMAIL PROTECTED] Hi all, Is there a PHP function that parses a string as it was the content of a PHP file? I have a CMS application and editors write the news items text into a text area. Since they have some knowledge of PHP, I'd like to allow them to insert ? ... ? or ?= ... ? and have the content blocks parsed and executed. OK, this could be easily done parsing the string and passing the block contents to eval(). However I wonder wether there is some function already doing that (maybe in a more efficient way). I would not recommend you do such a thing, you are opening up all the PHP environment to the editors, including reading variables and calling functions they whould see nor run. Instead, I would sugest you allow them to embed within the text a series of functions or variables which you would define, enclosed in whatever symbols you find suitable (easy to search and unambiguous) which would allow your program to replace by whatever data you may provide for them to use but in no case I would open up the whole of the PHP environment to them. You would pick those functions with a regular expression and do a switch on the keyword found and process it. Thus each keyword would have a case to process it and might call a PHP function or read a variable, but no 'default:', if it is not within the allowed functions, forget it. And never make eval() accessible to users. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fw: [PHP] Regular Expression
- Original Message - From: H.T [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Monday, February 05, 2007 10:12 PM Subject: [PHP] Regular Expression Do you know good regular expression editor or something simialar? This goes into the 'something similar' category: From the documentation: The Regex Coach together with this documentation can be downloaded from http://weitz.de/files/regex-coach.exe (Windows installer) or http://weitz.de/files/regex-coach.tgz (Linux tar archive). It's great to try and test the expressions -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read file on file system
Have you doubled the backslash to escape it? Or put it in between single quotes? Either: c:\\test.csv or 'c:\test.csv' or even 'c:/test.csv' Otherwise, a \t in between double quotes will be interpreted as a tab Satyam - Original Message - From: Bagus Nugroho [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, February 04, 2007 2:47 PM Subject: [PHP] Read file on file system Hi All, If I have file on[windows] c:\test.csv. How I can read the entire contents of this file? I have try file_get_contents, fgetcsv and etc but didn't work. May I'm mis-understanding about using those function. Thanks in advance Regards, bn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read file on file system
file_get_contents takes a file name as an argument, not an opened file handle. - Original Message - From: Bagus Nugroho [EMAIL PROTECTED] To: Stut [EMAIL PROTECTED]; php-general@lists.php.net Sent: Sunday, February 04, 2007 3:45 PM Subject: RE: [PHP] Read file on file system in simple like this $filename = d:\\test.csv; $openfile = fopen($filename,'r'); $readfile = fread($openfile,filesize($filename); echo $readfile or like this . echo file_get_contents($openfile); . echo fgetcsv($openfile); Thxs and rgds bn -Original Message- From: Stut [mailto:[EMAIL PROTECTED] Sent: Sun 04-Feb-2007 21:14 To: Bagus Nugroho Cc: php-general@lists.php.net Subject: Re: [PHP] Read file on file system Bagus Nugroho wrote: If I have file on[windows] c:\test.csv. How I can read the entire contents of this file? I have try file_get_contents, fgetcsv and etc but didn't work. May I'm mis-understanding about using those function. Well, from examining the code you included in your post, and reading the output you're seeing, I have determined that... ahh, hang on a second, I've started seeing code where no code exists. Is that a bad thing? Should I see someone? -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Login script login
- Original Message - From: Dave Carrera [EMAIL PROTECTED] Hi All, Having a grey brain moment here and need some advise on the logic of this, should be simple, login script. I am checking validity of customer number customer email customer password (md5 in mysql) So i have my form with relevant fields Now i am getting problems with either sql or how i am handling , and showing, and errors. I think what i am asking is this If someone just hits the login button show error All fields must be entered If customer number dose not excist show relevant error If customer number ok but email not show error If customer number ok but email ok but password is not show error In login scripts you usually don't tell which part of the login is wrong, otherwise, you are hinting at what is right. Once the customer is logged in, you are right to be as helpful as possible, but until the customer proves who he/she is, you don't give away anything. Satyam If all is ok set sessions, got this ok, and proceed. Any help with with this is very much appreciated. Kind Regards Dave C -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help wtih a query?
- Original Message - From: Jon Anderson [EMAIL PROTECTED] To: Skip Evans [EMAIL PROTECTED] Cc: PHP-General php-general@lists.php.net Sent: Tuesday, January 30, 2007 11:46 PM Subject: Re: [PHP] Help wtih a query? Wrong list. Putting $sql=... in there doesn't make it a PHP question. ;-) Skip Evans wrote: Is that what the left/right joins do??? Yea. LEFT JOIN will give you NULL entries in the left joined table, so you'd just have to say WHERE ISNULL(left joined table.some field in that table). Of course, you'll need to do the right JOINs in there for that to work. Personally, I think that implicit joins are sloppy, so I would suggest using JOIN with ON or USING...but I suppose that's a preference thing, and some (all?) might disagree with me. SQL engines have many techniques to improve the performance of the queries, with dozens of scholarly papers backing each slight improvement. The more the SQL engine knows about your intentions, the better chances it has to apply the best techniques to improve the performance of your query. For a particular engine, only a subset of all these tricks might be implemented so little might be gained from writing queries this way instead of that way and this might change with each version but it still holds that the chances for better performance improve if you make it clear what you want, eventually. Satyam jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL Readability.. (was Re: most powerful php editor)
- Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Larry Garfield [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Sunday, January 28, 2007 12:55 PM Subject: Re: [PHP] SQL Readability.. (was Re: most powerful php editor) Larry Garfield wrote: On Saturday 27 January 2007 1:14 pm, Jochem Maas wrote: query builders are alot more fiddly to get 'right' than one might imagine, dealing with NULLs, booleans and dates for example (as Satyam pointed out) can be a right PITA. I actually almost never use native date types in the SQL database. I just store unix timestamps and do the math in PHP. Dates are completely unportable anyway. I also tend to use ints for booleans, too, although beefing up the switch statements in the code to handle native booleans should be trivial. mysql doesn't have booleans does it? at least not versions I have to use. with regard to date stuff, many people take the opposite approach and do most of the date math inside SQL - most DBs have kickass date calculation functions btw. and for the times when you need/want unix timestamps, mysql atleast, gives you UNIX_TIMSTAMP(). At least as of MySQL 4.1 (haven't played with MySQL 5 much yet), yes, MySQL has no native boolean data type that I know of. The standard alternative is TINYINT(1), which technically gives you values 0-9. And yes, I agree that MySQL has fairly decent date manipulation routines. But at work we do try for database independence when possible, so except on specific projects we try to avoid it. again we differ :-) I have never bought the 'data independence' story - in practice it's of little value imho most of the time (granted certain products do benefit - but what I build doesn't fall into that category) and I find it crazy to end up with a situation where the most advanced peice of data manipulation software in a given stack is dumbed down to the lowest common denominator [of DB engines]. On more complex project I try to cram as much of the data intregity and business logic in to the database itself (for which I use firebird mostly) because it means being able to create different clients to the data without replicating [as much] business logic (e.g. website and desktop app). besides which the required stored procedures and triggers are usually hundreds of lines less than their php equivalent AND more importantly they are intrinsically atomic (in the sense that database transaction 'should' be). rgds :-) Hear!, hear! (or something to that effect) Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL Readability.. (was Re: most powerful php editor)
- Original Message - From: Larry Garfield [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Saturday, January 27, 2007 12:18 AM Subject: Re: [PHP] SQL Readability.. (was Re: most powerful php editor) I have long since given up on raw insert/update/delete statements as the syntax is all kinds nasty. These days I just do this, which is even easier and more powerful: http://www.garfieldtech.com/blog/simplifying-sql I tried the following: insert('sometable',array('when' = mktime(0,0,0,2,1,2007),'if' = true)); which produced the following SQL statement: INSERT INTO sometable (when) VALUES (1170284400,1170284400) The problem is that PHP types do not correspond to SQL types. Though a boolean does identify itself as such, a date never does. Your switch() on the gettype() of the value misses the type 'boolean' so it falls through the default: case which then appends whatever was left from the previous pass. However, even adding a case for type boolean there is no way to recognize dates since they are no more than integers for all PHP cares. Finally, what happens with an expression that produces a sort-of boolean, like anything non-zero for true? Those are the reasons I used type modifiers in my BuildSql function (http://www.satyam.com.ar/int/BuildSql.php), I couldn't rely on PHP figuring them out correctly. This also allowed me to expand those modifiers to optional positional modifiers and null handling ones. I even tried to query the SQL engine to report them back, but that was also unreliable, MySql for one, reports the type of what it used to store it, not what you declared them to be. Thus, for a boolean field it will report integer, but if you try to store a number other than 0 or 1 it then complains. So, unable to get reliable information from either end, I decided on stating the type explicitly on the query string. Satyam On Friday 26 January 2007 10:03 am, [EMAIL PROTECTED] wrote: My contribution to the insanity.. INSERT statements made easy: $genericQY = INSERT INTO MOD_LMGR_Leads (; $genericQYvalues = VALUES (; $genericQY .= FirstName,; $genericQYvalues .= 'John',; $genericQY .= LastName; $genericQYvalues .= 'Smith'; $genericQY .= ); $genericQYvalues .= );; $genericQY .= $genericQYvalues; $genericRS = mysql_query($genericQY); I use this structure so if I decide that I don't need certain data I can comment out a single line to remove the column name and corresponding value. Also helpful for making updates to column/value pairs and not worry about the dreaded error involve # of columns not matching. Only things you have to watch for: 1. Make sure you don't have a comma on the last item 2. Make sure you have spaces where appropriate so when it concatenates the strings, you don't get stuff crammed together (not really an issue with the INSERT statement, but I try to keep a consistant practice with all my queries so I don't slip up.. SELECT columnsFROM tableWHERE something = something is where it really gets ya if you forget spaces.. just as an example) 3. Make sure to remember to concatenate the query and values parts I like to think this is a little outside the box thinking since common practice is one command, one line or total chaos hah. Any comments on improving this or other unique stylistic ways people like to design their code? -TG = = = Original message = = = On Wed, January 24, 2007 8:07 pm, Robert Cummings wrote: On Wed, 2007-01-24 at 18:23 -0600, Richard Lynch wrote: On Wed, January 24, 2007 7:41 am, Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-24 13:57:03 +0200: and also in these days I'm looking for 19 inch (or more) wide LCD sceerns to able to fit longer lines in my screen... Number of reading errors people make grows with line length, this has been known for as long as I remember. You're increasing the probability of bugs in the code, and get tired sooner because following long lines requires more energy. I believe those results are specific to what is being read. Surely it's easier to read: SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah if it's all on one line, no matter how many fields there are, while trying to read the code as a whole. Sure, it can be hard to find/read the individual field names, on the rare occasion that you need to do that... Dear Mr Lynch, normally I highly respect your commentary on the list, but today I think you've been-a-smoking the crackpipe a tad too much. There is no way in hell one long line of SQL is easier to read than formatted SQL that clearly delineates the clause structure. SELECT A.field1 AS afield1, A.field2 AS afield2, B.field1 AS bfield1, B.field2 AS bfield2, C.field1 AS cfield1, C.field2 AS cfield2, D.field1 AS dfield1, D.field2 AS dfield2 FROM tableA as A LEFT JOIN tableB AS B ON B.fee = A.foo LEFT JOIN tableC AS C ON C.fii = B.fee LEFT JOIN tableD
Re: [PHP] bit wise math? Is there a function to easily return the bits?
pre?php $n = 7; for ($i = 1; $i $n;$i =1) if ($i $n) $a[] = $i; // put it in an array or do whatever, $i contains the parts. var_dump($a); ? /pre - Original Message - From: Richard Lynch [EMAIL PROTECTED] To: Jon Anderson [EMAIL PROTECTED] Cc: blackwater dev [EMAIL PROTECTED]; php-general@lists.php.net Sent: Friday, January 26, 2007 12:29 AM Subject: Re: [PHP] bit wise math? Is there a function to easily return the bits? On Thu, January 25, 2007 1:34 pm, Jon Anderson wrote: function bits($num) { $bit_array = str_split(strrev(decbin(intval($num; $val_array = array(); foreach ($bit_array as $pow = $bit) { if ($val = $bit * pow(2,$pow)) $val_array[] = $val; } return($val_array); } (I wanted to see if I could write it in few LOC.) I wonder if there's a faster way... //these might be marginally faster... function bits($num){ $bits = array(); $bin = decbin(intval($num)); $v = 1; for ($b = strlen($bin) - 1; $b = 0; $b--){ if ($bin[$b] === '1') $bits[] = $v; $v = $v * 2; } return $bits; } function bits($num){ $num = (int) $num; $v = 1; $bits = array(); while ($v = $num){ if ($v $num) $bits[] = $v; $v = $v * 2; } return $bits; } I suspect there is a much faster way, somewhere, somehow... jon blackwater dev wrote: Is there a php function I can call to pass in a number and get the values returned? For example, pass in 7 and get 1,2,4 ? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] bit wise math? Is there a function to easily return the bits?
- Original Message - From: Satyam [EMAIL PROTECTED] pre?php $n = 7; for ($i = 1; $i $n;$i =1) if ($i $n) $a[] = $i; // put it in an array or do whatever, $i contains the parts. Sorry, the above fails for numbers which are powers of two, it should have been: for ($i = 1; $i = $n;$i =1) if ($i $n) echo $ibr /; (Notice less than or equal in the while part) Satyam var_dump($a); ? /pre - Original Message - From: Richard Lynch [EMAIL PROTECTED] To: Jon Anderson [EMAIL PROTECTED] Cc: blackwater dev [EMAIL PROTECTED]; php-general@lists.php.net Sent: Friday, January 26, 2007 12:29 AM Subject: Re: [PHP] bit wise math? Is there a function to easily return the bits? On Thu, January 25, 2007 1:34 pm, Jon Anderson wrote: function bits($num) { $bit_array = str_split(strrev(decbin(intval($num; $val_array = array(); foreach ($bit_array as $pow = $bit) { if ($val = $bit * pow(2,$pow)) $val_array[] = $val; } return($val_array); } (I wanted to see if I could write it in few LOC.) I wonder if there's a faster way... //these might be marginally faster... function bits($num){ $bits = array(); $bin = decbin(intval($num)); $v = 1; for ($b = strlen($bin) - 1; $b = 0; $b--){ if ($bin[$b] === '1') $bits[] = $v; $v = $v * 2; } return $bits; } function bits($num){ $num = (int) $num; $v = 1; $bits = array(); while ($v = $num){ if ($v $num) $bits[] = $v; $v = $v * 2; } return $bits; } I suspect there is a much faster way, somewhere, somehow... jon blackwater dev wrote: Is there a php function I can call to pass in a number and get the values returned? For example, pass in 7 and get 1,2,4 ? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL Readability.. (was Re: most powerful php editor)
- Original Message - From: Stut [EMAIL PROTECTED] You call that readable?? $vals = array(); $vals['FirstName'] = 'John'; $vals['LastName'] = 'Smith'; $query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals)); function BuildInsert($table, $values) { foreach (array_keys($values) as $key) $values[$key] = mysql_real_escape_string($values[$key]); $sql = 'insert into `'.$table.'` (`'; $sql.= implode('`,`', array_keys($values)); $sql.= '`) values ('; $sql.= implode(',', array_values($values)); $sql.= ')'; return $sql; } I use to build SQL statements with a BuildSql function, which you can see at: http://www.satyam.com.ar/int/BuildSql.php It is commented in PhpDoc format. For example: echo BuildSql('Insert into ?ptable (?s,?ns,?mi,?d,?ni,?i,?t)','Something','',5,time(),0,null,mktime(3,4,5)- mktime(0,0,0)); Will return: Insert into wp_table ('Something',null,5,'2007-01-21 15:54:27',null,0,'0 04:04:05') It is not only meant to build inserts but it is more like a sort of SQL-oriented sprintf(), like it does proper handling of null values, such as avoiding puting the text 'null' (notice the quotes) instead of the value null. It also has a ?p 'prefix' modifier to use a fixed prefix on all table names. As for formatting, I usually put the SQL statement in one line and the arguments in the next one with spaces to align them vertically, which I won't show here since the formatting of the message will ruin it anyway. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi lingual pages
I wrote something about this, but it is in Spanish: http://www.satyam.com.ar/blog/2007/01/17/internacionalizacion-y-localizacion-indice/ Satyam - Original Message - From: Otto Wyss [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, January 24, 2007 10:44 PM Subject: [PHP] Multi lingual pages I'd like to make my pages multi lingual, showing everything in the language the user chooses. My pages show mostly static text. So what's the usual implementation for this case. O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] most powerful php editor
Since a couple of IDEs have also been mentioned, I would like to add to the list of sugestions phpEdit (http://waterproof.fr/) for Windows only. It does all that Eclipse with all the plugins for PHP does, plus some, but it is much slimmer and faster. I admit that since what I have already installed satisfies me, I never went beyond the free trial version, but it was really good and woked as advertised, and this was more than a year ago and they keep sending e.mails with the updates, and they keep adding and adding. As I said, I already have all I need, in bits and pieces assembled together over time, but if you start from scratch, this product is great. Satyam - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, January 21, 2007 3:58 PM Subject: Re: [PHP] most powerful php editor God I love this list.. great answers everyone! (serious and non-serious :) In addition to the editors listed, here's a few more to consider: Crimson Editor - my personal favorite when I don't need code completion. Code highlights for many different types of code (including my beloved LUA files used in World of Warcraft scripting hah). I use the macro record/playback a lot. http://www.crimsoneditor.com/ Emerald Editor - crimson editor has been abandoned for years (and still kicks ass), these guys hope to revive it as a new project called Emerald. It's not done yet. http://www.emeraldeditor.com/ Notepad++ - looks spiffy, but wasn't enough of of a change to get me to switch from Crimson editor (although it came damn close) http://notepad-plus.sourceforge.net/uk/site.htm Zend Studio - Still my 'professional' choice, but since it's a java app, it's kind of heavy on the system. And it's made by the people who created the core PHP engine, so they know a few things. http://www.zend.com/products/zend_studio Komodo - Similar to Zend Studio.. but much like Notepad++ and Crimson Editor.. not enough of an 'upgrade' to get me to switch, but a former coworker swore by it. http://www.activestate.com/Products/Komodo/ Should be enough to get you started investigating. -TG = = = Original message = = = At 08:21 AM 1/21/2007, Robert Cummings wrote: On Sat, 2007-01-20 at 22:54 -0200, Vinicius C Silva wrote: hi everyone! i'd like to ask something maybe commonly asked here. what is the most powerful php editor? ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Forms and destroying values
This issue comes over and over again. The trick, as I learned from this list, is to send a redirect to the browser to a confirmation page, so the browser remembers the page redirected to and completely ignores the page that made the redirection so that neither a refresh nor going back to it can repeat the operation. So, if the database update has been succesful, use the header() function to send a 'location' header along with enough arguments in the URL to display a significant confirmation message but make sure that it is different from the URL that makes the database update. It will be this address, not the post that made the database update, that the browser will remember. Satyam - Original Message - From: Beauford [EMAIL PROTECTED] To: PHP php-general@lists.php.net Sent: Friday, January 12, 2007 9:27 AM Subject: [PHP] Forms and destroying values Hi, How do I stop contents of a form from being readded to the database if the user hits the refresh button on their browser. I have tried to unset/destroy the variables in several different ways, but it still does it. After the info is written I unset the variables by using unset($var1, $var2, $etc). I have also tried unset($_POST['var1'], $_POST['var2'], $_POST['etc']). I even got deperate and tried $var = ; or $_POST['var'] = ; What do I need to do to get rid of these values??? Obviously I am missing something. Any help is appreciated. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Forms and destroying values
As many have already replied to your question, what happens is that upon a refresh the browser is resending the original post variables again. The unset() does work, from the point of the unset() to the end of the script (when all variables except for session variables are unset), PHP will have completely forgotten about those values. But that does not affect the browser at all. On a refresh the browser will send the information again, unless it is tricked via a redirection command to believe the URL used for the post is obsolete. Then, what the browser will do is to remember the URL it was redirected to and drop the 'obsolete' URL so, when the user does a refresh, the browser will be smart enough to go to the 'updated' (the redirected-to) URL instead of the original 'obsolete' one and thus will get the confirmation page again, but without passing through the database transaction. Satyam - Original Message - From: Beauford [EMAIL PROTECTED] To: 'PHP' php-general@lists.php.net Sent: Friday, January 12, 2007 5:23 PM Subject: RE: [PHP] Forms and destroying values So the answer is, there is no way to destroy the values. Question then, what is unset() used for as it doesn't seem to do anything? With a language as good as PHP I though there would be some way to do this. I have got a workaround, but that's exactly what it is - a work around. I am also still confused as to why giving them a null value doesn't work. Thanks to all. -Original Message- From: Satyam [mailto:[EMAIL PROTECTED] Sent: January 12, 2007 8:21 AM To: Beauford; PHP Subject: Re: [PHP] Forms and destroying values This issue comes over and over again. The trick, as I learned from this list, is to send a redirect to the browser to a confirmation page, so the browser remembers the page redirected to and completely ignores the page that made the redirection so that neither a refresh nor going back to it can repeat the operation. So, if the database update has been succesful, use the header() function to send a 'location' header along with enough arguments in the URL to display a significant confirmation message but make sure that it is different from the URL that makes the database update. It will be this address, not the post that made the database update, that the browser will remember. Satyam - Original Message - From: Beauford [EMAIL PROTECTED] To: PHP php-general@lists.php.net Sent: Friday, January 12, 2007 9:27 AM Subject: [PHP] Forms and destroying values Hi, How do I stop contents of a form from being readded to the database if the user hits the refresh button on their browser. I have tried to unset/destroy the variables in several different ways, but it still does it. After the info is written I unset the variables by using unset($var1, $var2, $etc). I have also tried unset($_POST['var1'], $_POST['var2'], $_POST['etc']). I even got deperate and tried $var = ; or $_POST['var'] = ; What do I need to do to get rid of these values??? Obviously I am missing something. Any help is appreciated. Thanks -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Using gettext
I decided to internationalize a program that I already had and part of that process was to put the existing texts under gettext(). So far, when I meant an application to be localized, I made the original in English, but this one was already in Spanish. So, now, I have the source strings in Spanish with many letters with diacritical marks, accents, tildes, umlauts. Though the .po file says they are in ISO-8859-1 and, indeed, they are coded in that way, gettext finds the translations for the string which happen to contain no diacritical marks but fails on any string that does have any. Nevertheless, it does understand and render correctly those same 'special' characters as translations, as long as they are translations for strings that don't have any such. This would indicate it is understanding the character encoding correctly. The GNU manual doesn't say there is any limitation as to the character set of the input file, after all, that's why it can be specified in thhe header. So (characters with diacritical marks might not display correctly in your mail client): # this translates fine: msgid Pedro msgstr Peter # this translation is not found: msgid José msgstr Joseph # this works fina as well. msgid no diacritial marks in this string msgstr plenty of them: áéíóúüñ I'm using Windows XP and used poEdit from the GUI interface and I also run the msgfmt utility from the poEdit package and the one from the GNUWIN32 project and the result is the same. I also copied the .mo file to the *nix server of my ISP and the result is exactly the same. The setlocale() function succeeds (though with different values in each system) since, after all, it does translate some of the strings. I also tried the gettext implementation from WordPress, wich comes from the PHP-gettext project (http://savannah.nongnu.org/projects/php-gettext/) which does not use the standard PHP library functions but solves it all in PHP (without functions) so it works whether the locale is installed or not, whether the PHP has gettext support compiled and so on. Using this, it works fine with all string, so the .mo file seems to be fine. Actually, it works just nicely without using setlocale, bindtextdomain, textdomain or any of all those complications, whether your ISP has gettext compiled into their PHP, you just tell it where the .mo file is and it reads it into an array. I wonder why I care about the 'official' gettext at all, but I'm curious to learn, so I ask. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security with dbHost, dbUser, dbPassword
- Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Satyam [EMAIL PROTECTED] Cc: php-general@lists.php.net; Otto Wyss [EMAIL PROTECTED] Sent: Thursday, January 11, 2007 12:16 AM Subject: Re: [PHP] Security with dbHost, dbUser, dbPassword Satyam wrote: - Original Message - From: Otto Wyss [EMAIL PROTECTED] What is the usual save way to store/use DB access info in a script. I currently just use some PHP variables in a file which I include in all other scripts. config.php ?PHP if (!defined (config_include)) die (Error...); $dbhost = localhost; $dbuser = name; $dbpass = password; $dbname = database; $dbcoll = utf8_unicode_ci; ? Is this save enough or are there better ways? Where should I store this file so it isn't accessible via the net but inside scripts? O. Wyss Besides what Jochem has already sugested, I would add that I usually have in the include file, in an unaccessible path as he said, a function that returns a connection. The function has all the connection information local, so that they are neither global variables nor constants, just local literal values within the function. I'm sure most people end up with some kind of abstraction in the form of a class or function to do all the 'heavy lifting' regarding connecting to the DB, etc - but when projects get rather large and/or your faced with a situation where you want/need to run your project on different systems (e.g. local-dev, test/staging, live) it often most handy to place all installation specific configuration values in a single file that is specific to the given installation and therefore usually not included as part of the version control (e.g. CVS or SVN) module that stores the projects files. No problem there, the include in my DB abstraction layer includes and calls the separate file with the function to make the connection to the database. Though the main application source doesn't know about the include file with the connection data in it, the DB layer include does. In this way, I have the db include file under CVS and can refresh it at the production server without a problem, while the include file with the connection is separate, so that I have one for the test machine (this one) where the server is 'localhost' which I never copy to the production server. Nevertheless, I admit that the important issue here is to have the connection data out of the public folders, mine is just a useless paranoid complication. Does anyone have an expression evaluator in an application open to the public? Does anyone make a var_dump of $_GLOBALS on error (and then forgets to strip it out on production code)? I sure hope not. In the same function I put the call to mysql_select_db. Though I check the return values for errors, I usually ignore them since unless you have either more than one database engine or more than one database, the default link resource does not need to me explicitly passed to other functions. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Handling SimpleXMLElements
I have a problem trying to handle SimpleXml objects. Though I can manage some workaround the problem, I would like to understand it better. This is a section of the XML file I'm trying to read (it is not complete, just a section) tr tdBERMUDA/td tdBermudian Dollar (customarily known as Bermuda Dollar) /td tdBMD/td td060/td /tr tr tdBHUTAN/td td pIndian Rupee/p pNgultrum/p /td td pINR/p pBTN/p /td td p356/p p064/p /td /tr It is part of a table with currency codes. Each row has 4 cells containing the country name, the currency description, the currency code and the numeric code, as seen in the first row. Nevertheless, with countries that have more than one currency, it still has a single row with the first cell containing the country name (see BHUTAN) but then in the following cells it has several lines, one for each currency, as simple paragraphs. When I get to the row for BHUTAN, I do a foreach to see what's in each cell. Function dump() just does a var_dump() of whatever is given in the first argument within a pre tag and uses the second argument as a heading, surrounded by dashes. In this case I copied the expression of what I am dumping as the title (within single quotes so it does not expand). foreach($row as $cell) { dump($cell,'$cell); dump($cell-p,'$cell-p'); dump((array)$cell-p,'(array)$cell-p'); dump($cell-p[1],'$cell-p[1]'); } The section in question is shown below. Though $cell is shown as a SimpleXMLElement containing one 'p' property which contains an array of two elements: $cell- object(SimpleXMLElement)#8 (1) { [p]= array(2) { [0]= string(12) Indian Rupee [1]= string(8) Ngultrum } } If I dump that 'p' element, I don't get an array but an object with just one element, the first value in the array $cell-p- object(SimpleXMLElement)#7 (1) { [0]= string(12) Indian Rupee } If I typecast it to an array, I still get a single element (array)$cell-p- array(1) { [0]= string(12) Indian Rupee } Nevertheless, if I explicitly index into the 'p' element, without even typecasting it into an array, the second element is there. $cell-p[1]- object(SimpleXMLElement)#10 (1) { [0]= string(8) Ngultrum } So, now you see it, now you don't, or do you? What's happening? Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anybody have any experience with outsite-in? [Quite a bit 0T]
It is not a new concept, even Wikipedia has a long list of them: http://en.wikipedia.org/wiki/List_of_LiveDistros Most of those distros have individual articles ... not the one mentioned below, though. Satyam - Original Message - From: Skip Evans [EMAIL PROTECTED] To: Ryan A [EMAIL PROTECTED] Cc: php php php-general@lists.php.net Sent: Thursday, January 11, 2007 10:35 PM Subject: Re: [PHP] Anybody have any experience with outsite-in? [Quite a bit 0T] Hey all, When you say it lets you run it off a CD does that mean the CD is totally self contained, as in you can pop it into any machine, sans web server DB, etc, and it runs just peachy? Skip Ryan A wrote: Hey all! This is a bit OT as its not really php programming, but it does involve PHP and MySql etc so The company I work for has decided to use the software from outsite-in.com, for those of you who dont know (and i'm guessing a lot of you dont, as I kinda just found out about it myself) their software allows you to run php+mysql etc on a CD/DVD. Just curious to know if anybody has had any experience with their software? I have tried their free demo's and it looks pretty good. Note: Others on this list have in the past advised me on how to do this using different methods, but my company wants to go with this... needless to say I am in NO way connected to outsite-in.com and i have *nothing* to gain if you visit their site, buy anything from them, shoot them, kiss them or whatever. :) Thanks! Ryan -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) - Everyone is raving about the all-new Yahoo! Mail beta. -- Skip Evans Big Sky Penguin, LLC 61 W Broadway Butte, Montana 59701 406-782-2240 =-=-=-=-=-=-=-=-=-= Check out PHPenguin, a lightweight and versatile PHP/MySQL development framework. http://phpenguin.bigskypenguin.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Handling SimpleXMLElements
- Original Message - From: Jochem Maas [EMAIL PROTECTED] I'm guessing you have php5.0.x running - you really want a php5.1.x PhpInfo reports it's 5.2.0 so I'm covered there. version if your going to use XML - it will avoid *alot* headaches with regarding to using var_dump() (or print_r() or even echo) to figure out what the simpleXML objects are/contain. Satyam wrote: I have a problem trying to handle SimpleXml objects. Though I can manage some workaround the problem, I would like to understand it better. cell. Function dump() just does a var_dump() of whatever is given in the first argument within a pre tag and uses the second argument as a heading, surrounded by dashes. In this case I copied the expression of what I am dumping as the title (within single quotes so it does not expand). foreach($row as $cell) { dump($cell,'$cell); dump($cell-p,'$cell-p'); dump((array)$cell-p,'(array)$cell-p'); dump($cell-p[1],'$cell-p[1]'); } The section in question is shown below. Though $cell is shown as a SimpleXMLElement containing one 'p' property which contains an array of two elements: $cell- object(SimpleXMLElement)#8 (1) { [p]= array(2) { [0]= string(12) Indian Rupee [1]= string(8) Ngultrum } } If I dump that 'p' element, I don't get an array but an object with just one element, the first value in the array $cell-p- object(SimpleXMLElement)#7 (1) { [0]= string(12) Indian Rupee } If I typecast it to an array, I still get a single element (array)$cell-p- array(1) { [0]= string(12) Indian Rupee } Nevertheless, if I explicitly index into the 'p' element, without even typecasting it into an array, the second element is there. $cell-p[1]- object(SimpleXMLElement)#10 (1) { [0]= string(8) Ngultrum } So, now you see it, now you don't, or do you? What's happening? Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems with mysql_connect()
There is a closing parenthesis missing, see below: - Original Message - From: Delta Storm [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, January 10, 2007 11:45 AM Subject: [PHP] Problems with mysql_connect() Hi, I'm having problems with this code (a simple exercise where i wanto to connect to sql server and get data from it and write that data in html) : !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 / titleExercise 23 - Using PHP with MySQL/title /head body ?php //Povezuje se s MySQL serverom $connection = mysql_connect('localhost','user','pass') or die (Unable to connect to MySQL server); //Odabira bazu podataka mysql_select_db(php1) or die (Unable to select database); //Pravi i zadaje upit $query = SELECT * FROM items; $result = mysql_query($query) or die (Error in query: $query . . mysql_error()); //Provjerava jeli li zapisi vraceni if (mysql_num_rows($result) 0) { //Pravi html tablicu echo table width=100% cellpadding=10 cellspacing=0 border=1; echo tr td bID/b /td td bName/b /td td bPrice/b /td /tr; //Prolazi kroz skup zapisa //ispisuje svako polje while ($row = mysql_fetch_row($result)) == this one is missing * { echo tr; echo td . $row [0] ./td; echo td . $row [1] ./td; echo td . $row [2] ./td; echo /tr; } echo /table; } else { //Ispisuje poruku o gresci echo No rows found!; } //Kad je obrada gotova oslobada skup rezultata mysql_free_result($result); //Prekida vezu s MySQL serverom mysql_close($connection); ? /body /html the error is : Parse error: parse error, unexpected '{' in C:\Program Files\XAMPP\xampp\htdocs\test_folder\exercise23.php on line 41 I really dont know why is this error showing i looked for syntax errors but i think that there aren't any Thanks in advance! :) (P.S dont read the commnents they are croatian) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security with dbHost, dbUser, dbPassword
- Original Message - From: Otto Wyss [EMAIL PROTECTED] What is the usual save way to store/use DB access info in a script. I currently just use some PHP variables in a file which I include in all other scripts. config.php ?PHP if (!defined (config_include)) die (Error...); $dbhost = localhost; $dbuser = name; $dbpass = password; $dbname = database; $dbcoll = utf8_unicode_ci; ? Is this save enough or are there better ways? Where should I store this file so it isn't accessible via the net but inside scripts? O. Wyss Besides what Jochem has already sugested, I would add that I usually have in the include file, in an unaccessible path as he said, a function that returns a connection. The function has all the connection information local, so that they are neither global variables nor constants, just local literal values within the function. In the same function I put the call to mysql_select_db. Though I check the return values for errors, I usually ignore them since unless you have either more than one database engine or more than one database, the default link resource does not need to me explicitly passed to other functions. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php