php-general Digest 1 Jan 2012 16:26:54 -0000 Issue 7631
php-general Digest 1 Jan 2012 16:26:54 - Issue 7631 Topics (messages 316140 through 316143): Re: array 316140 by: Ashley Sheridan 316141 by: Govinda Re: Error in portuguese translation of substr_compare 316142 by: Daniel P. Brown count clicks to count most important news 316143 by: muad shibani Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- On Sat, 2011-12-31 at 14:53 +0100, saeed ahmed wrote: how can you explain someone in a simplest and everyday use example of ARRAY. The manual page explains it pretty succinctly. I don't think you'll get more simple than this, as there is obvious prerequisite knowledge assumed (i.e. that you know what a simple variable is, etc) -- Thanks, Ash http://www.ashleysheridan.co.uk ---End Message--- ---BeginMessage--- how can you explain someone in a simplest and everyday use example of ARRAY. The manual page explains it pretty succinctly. I don't think you'll get more simple than this, as there is obvious prerequisite knowledge assumed (i.e. that you know what a simple variable is, etc) Hi saeed, Ash means this: http://www.php.net/manual/en/language.types.array.php See the examples in grey-colored boxes. Arrays are just a collection of things. Similar to when you assign one variable one value.. well with an array you assign many variables one value each. But the reason you use an array is that instead of a bunch of separate variables, you want those variables to be part of a collection.. i.e. all those variables have something in common.. like for example you might use one array to describe the parts of a car, and another array to describe all the fruits in your kitchen. You could do this: (all separate independent variables) $part1 = 'spark plug'; $part2 = 'rear-view mirror'; $part3 = 'steering wheel'; etc. $fruit1 = 'apple'; $fruit2 = 'banana'; $fruit3 = 'orange'; etc. ...but (depending on your application, and the logic you use), it might make more sense to do something like this instead: (make arrays!) (these, below, are arrays where the key is just a number which is automatically assigned. You can also use another syntax (see the manual) to make arrays where you generate your own custom keys, and those keys can be strings instead of numbers.) $arrParts = array('spark plug', 'rear-view mirror', 'steering wheel'); $arrFruits = array('apple', 'banana', 'orange'); To use the arrays, there are tons of functions: http://www.php.net/manual/en/ref.array.php :-) -Govinda---End Message--- ---BeginMessage--- Forwarded to the proper address. Docs PT/PT-BR folks, please see the below email. Thanks, and happy new year! On Fri, Dec 30, 2011 at 14:35, QI.VOLMAR QI qi.vol...@gmail.com wrote: I was read substr_compare description in portuguese language, an I asked myself to test it, so after several test, I found that its wrong. The text is in Portuguese: Se length é igual ou maior que o comprimento de main_str e length é setado, substr_compare() imprime warning e retorna FALSE. That is translated: If length is equal or bigger than size of main_str and length is setted, substr_compare() prints a warning and return FALSE The original is: If offset is equal to or greater than the length of main_str or length is set and is less than 1, substr_compare() prints a warning and returns FALSE. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ ---End Message--- ---BeginMessage--- I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? ---End Message---
[PHP] count clicks to count most important news
I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor?
Re: [PHP] count clicks to count most important news
On Jan 1, 2012, at 11:26 AM, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? Not a fool-proof method, but use Javascript on the client-side to stop users' from continuous clicking. Then create a token and verify the click on the server-side before considering the click as being acceptable. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count clicks to count most important news
On Sun, 2012-01-01 at 11:49 -0500, Tedd Sperling wrote: On Jan 1, 2012, at 11:26 AM, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? Not a fool-proof method, but use Javascript on the client-side to stop users' from continuous clicking. Then create a token and verify the click on the server-side before considering the click as being acceptable. Cheers, tedd _ t...@sperling.com http://sperling.com There are still problems with this, GET data (which essentially only what a clicked link would produce if you leave Javascript out the equation - you can't rely on Javascript) shouldn't be used to trigger a change on the server (in your case a counter increment) I did something similar for a competition site a few years ago, and stupidly didn't think about this at the time. Someone ended up gaming the system by including an image with the clicked-through URL in the src attribute, and put that on their MySpace profile page, which had more than a few visitors. Each of those visitors browser attempted to grab that image which registered a click, and because of the number of unique visitors, the clicks were registered as genuine. I'd recommend using POST data for this reason, as it's a lot more difficult for people to game. -- Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] count clicks to count most important news
On 01-01-2012 20:08, Ashley Sheridan wrote: On Sun, 2012-01-01 at 11:49 -0500, Tedd Sperling wrote: On Jan 1, 2012, at 11:26 AM, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? Not a fool-proof method, but use Javascript on the client-side to stop users' from continuous clicking. Then create a token and verify the click on the server-side before considering the click as being acceptable. Cheers, tedd _ t...@sperling.com http://sperling.com There are still problems with this, GET data (which essentially only what a clicked link would produce if you leave Javascript out the equation - you can't rely on Javascript) shouldn't be used to trigger a change on the server (in your case a counter increment) I did something similar for a competition site a few years ago, and stupidly didn't think about this at the time. Someone ended up gaming the system by including an image with the clicked-through URL in the src attribute, and put that on their MySpace profile page, which had more than a few visitors. Each of those visitors browser attempted to grab that image which registered a click, and because of the number of unique visitors, the clicks were registered as genuine. I'd recommend using POST data for this reason, as it's a lot more difficult for people to game. I agree, POST data is indeed the way to go here. Personally, I would use a like image-like thing which is actually a button, using some clever javascript (personally I would use jquery for this) you can then POST data to the server based on the click. Then set a cookie which disables the button (and keeps it disabled on future visits). This should prevent average person from repeatedly clicking it. You could also log the person's IP adress and filter based on that aswell; combining various methods would be best in this case I think. To prevent the method which Ashley mentioned, using POST data isn't enough. You would want to guarantee that the link came from YOUR server instead of some different place. There are multiple ways to do this: - use a unique key as an argument in the POST which can only be clicked once. Register the key in a database before serving the page, and then unregister it once it has been served and clicked. Though if a person were to repeatedly open the page, your cache would be exhausted, and the method would become useless. - require a referrer address to come from your domain; also reasonably easily circumvented in this case - there are more, but it really depends on how much effort you want to put into preventing attacks and how much effort you expect others to put into attacking it. For example, large sites like youtube are sure to use extensive measures to prevent people from spam-clicking in any way. While sites that only cater to say 3 visitors a month don't require all that effort in the first place. Hope that helps, - Tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count clicks to count most important news
On 1 Jan 2012, at 16:26, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? I'm assuming this is not a voting system, and the news items you're counting are sourced from your own site and, with all due respect to Ash, unlikely to be a target for false clicks. All you're really wanting to do is prevent the site from registering multiple hits from the same user in a short period of time. I would probably use memcached on the server-side to store short-term information about clicks. When a news item is loaded... 1) Construct the memcache key: newsclick_article_id_ip_address. 2) Fetch the key from memcache. 3a) If it does not exist, log the hit. 3b) If it does exist, compare time() with the value and only log the hit if time() is greater. 4) Store the key with a value of time() + 300 and an expiry of the same value. This will prevent hits being logged for the same news item from the same IP address within 5 minutes of other hits. Other alternatives would be to use cookies (could get messy, and not very reliable since it requires the response from click 1 to be processed before click 2 gets started), Javascript (as suggested by tedd but without the token - it would work pretty well and would be a lot easier to implement than the above, but you sacrifice having full control over it). If I'm interpreting the requirement correctly my solution is almost certainly overkill, and a simple Javascript solution would be more than sufficient. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count clicks to count most important news
All the answers are great but Stuart Dallas' answer is what I was asking about .. thank u all I really appreciate it a lot On Sun, Jan 1, 2012 at 11:10 PM, Stuart Dallas stu...@3ft9.com wrote: On 1 Jan 2012, at 16:26, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? I'm assuming this is not a voting system, and the news items you're counting are sourced from your own site and, with all due respect to Ash, unlikely to be a target for false clicks. All you're really wanting to do is prevent the site from registering multiple hits from the same user in a short period of time. I would probably use memcached on the server-side to store short-term information about clicks. When a news item is loaded... 1) Construct the memcache key: newsclick_article_id_ip_address. 2) Fetch the key from memcache. 3a) If it does not exist, log the hit. 3b) If it does exist, compare time() with the value and only log the hit if time() is greater. 4) Store the key with a value of time() + 300 and an expiry of the same value. This will prevent hits being logged for the same news item from the same IP address within 5 minutes of other hits. Other alternatives would be to use cookies (could get messy, and not very reliable since it requires the response from click 1 to be processed before click 2 gets started), Javascript (as suggested by tedd but without the token - it would work pretty well and would be a lot easier to implement than the above, but you sacrifice having full control over it). If I'm interpreting the requirement correctly my solution is almost certainly overkill, and a simple Javascript solution would be more than sufficient. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- *___* * * السجل .. كل الأخبار من كل مكان www.alsjl.com صفحة السجل على فيسبوك http://www.facebook.com/alsjl *Muad Shibani* * * Aden Yemen Mobile: 00967 733045678 www.muadshibani.com
[PHP] PHP 5.3.2 max_execution_time
I've got a Dokuwiki installation that is producing Apache errors saying that the maximum execution time of 30 seconds has been exceeded. So, I went and changed max_execution_time in php.ini expecting that this would solve the problem (which is due to large files taking a while to upload over an ADSL connection). However, the error log still reports that the old 30 second value is in use, even though Apache has been restarted. phpinfo() for the same site reports max_execution_time as 120 seconds, so it seems as if the change to php.ini has been detected as expected. Is there another setting that I need to consider? max_input_time is already set to 60 seconds and there are no local 'php_value' Apache configuration items fighting the ones in php.ini. PHP version is 5.3.2 and is running under a CentOS 6.0 system. Chris Tapp opensou...@keylevel.com www.keylevel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about date calculations
On Fri, Dec 30, 2011 at 5:33 PM, Eric Lommatsch er...@pivotaldata.net wrote: When I try this method: $interval = $dteStartDate[$intCnt]-diff($dteEndDate[$intCnt]); I get the following error when I run the page: Fatal error : Call to undefined method DateTime::diff() in /var/www/evalHomeLime.php on line 254 Just for the record: As noted on the manpage [1], your PHP version needs to be = 5.3.0. Cheers, Matijn [1] http://www.php.net/manual/en/datetime.diff.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 5.3.2 max_execution_time
If you want to upload large file, maybe you should consider maximum uploaded size. You can change setting in php.ini on line that contain * upload_max_filesize*. On Mon, Jan 2, 2012 at 5:13 AM, Chris Tapp opensou...@keylevel.com wrote: I've got a Dokuwiki installation that is producing Apache errors saying that the maximum execution time of 30 seconds has been exceeded. So, I went and changed max_execution_time in php.ini expecting that this would solve the problem (which is due to large files taking a while to upload over an ADSL connection). However, the error log still reports that the old 30 second value is in use, even though Apache has been restarted. phpinfo() for the same site reports max_execution_time as 120 seconds, so it seems as if the change to php.ini has been detected as expected. Is there another setting that I need to consider? max_input_time is already set to 60 seconds and there are no local 'php_value' Apache configuration items fighting the ones in php.ini. PHP version is 5.3.2 and is running under a CentOS 6.0 system. Chris Tapp opensou...@keylevel.com www.keylevel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Duken Marga