[PHP] Looking for complete entered URL
I've written a script that logs all visits to a web site, complete with referrer and IP address. It also logs all 4xx errors. What I'd like to add to this is, if someone adds extra code after the page_name.php, to be able to capture any extra code and log that. I've tried: $_SERVER['QUERY_STRING'] $_SERVER['REDIRECT_QUERY_STRING'] $_SERVER['REDIRECT_URL'] but nothing seems to get logged. Is there a way, when either a false url is entered and a 404 is generated, or just when someone tacks on extra code to the URL, that I can grab that extra info? I'm looking for the complete URL that was entered by the user, not anything returned by the server. I've created my own 4xx_error.php files which calls my tracking script, along with creating the proper ErrorDocument lines in the main .htaccess file. There are a lot of pages that have come up in my search, but nothing seems to pertain to what I'm trying to do. Thank you, Angela BTW, I know about Piwik and I use that, as well. This is something I'm doing on my own. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Detecting massive web hits
Does anyone know if there's a ready-made script that detects if someone hits multiple web pages within seconds of each other and then can temporarily ban them by IP from accessing our site? Looking through the logs, I see someone/something hit each and every page of a site I work on within only a few seconds of each other. I seriously doubt they are a customer. ;) I'd appreciate any insights. Thank you, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Mar 13, 2013, at 5:02 PM, David Harkness wrote: > isset() will return false for an array key 'foo' mapped to a null value > whereas array_key_exists() will return true. The latter asks "Is this key in > the array?" whereas isset() adds "and is its value not null?" While isset() > is every-so-slightly faster, this should not be a concern. Use whichever > makes sense for the context here. Hi David, Thank you for the explanation. It's nice to know the difference between them. Since they are equivalent for my use, I went with array_key_exists, simply because it makes more sense to me in English. ;) Thanks again to everyone. I got it to work _and_ there are no more errors!!! Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Mar 13, 2013, at 4:24 PM, Matijn Woudt wrote: > That wouldn't work, in_array checks the values, and your states are in the > keys. Use: > if(isset($states[$state])) Hi Matijn, Before I received your email, I ran across if(array_key_exists) and it seems to work. How does that differ from if(isset($states[$state]))? Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: > Why not just check if the $state exists as a key of the array $states before > doing this? Jim, Are you thinking about the in_array function? Angela
Re: [PHP] Mystery foreach error
On Mar 12, 2013, at 5:16 PM, David Robley wrote: > Presumably there is a fixed list of State - those are US states? - > so why not provide a drop down list of the possible choices? There is, but the problem must have been that if someone didn't select a State, $state was blank. I've since given the "Select a State..." choice a value of 'XX' and I'm now looking for that in the if statement I mentioned before. Angela
Re: [PHP] Mystery foreach error
I think I figured it out. array( '350','351','352','353', ), 'AK' => array( '995','996','997','998','999', ), 'AZ' => array( '850','851','852','853','854', ), 'WI' => array( '530','531','532', ), 'WY' => array( '820','821','822','823','824', ), ); $zip = 35261; $state = 'XX'; $zip_short = substr($zip, 0, 3); foreach ($states[$state] as $zip_prefix) { if ($zip_prefix == $zip_short) { echo "State = $state"; } else { echo 'no'; } } ?> Running this script, I got the same error as before. If $state is a known state abbreviation in the array, everything is fine, but if someone was to enter, say 'XX' like I did above or leave it blank, then the error is produced. I placed an if statement around the foreach loop to test for that and I'll keep an eye on it. Thank you for getting me to look at the array again, which led me to look at the State. Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Mar 12, 2013, at 2:26 PM, Marco Behnke wrote: > what is in $states? > Looks like $states[$state] is not an array. Here's a sample: array( '350','351','352','353', ), 'AK' => array( '995','996','997','998','999', ), 'AZ' => array( '850','851','852','853','854', ), ... 'WI' => array( '530','531','532', ), 'WY' => array( '820','821','822','823','824', ), ); ?> > side effects if you don't act carefully with it. I don't remember where that came from, but for the most part, this script works perfectly. However, I removed it and will test without it. Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mystery foreach error
I've been getting the following error for awhile now, but I can't figure out why it's happening: Invalid argument supplied for foreach() in ... sample.php on line 377 Here's that portion of code: include("states_zipcodes.php"); // Check if Zip Code matches from states_zipcodes $zip_short = substr($zip, 0, 3); foreach ($states[$state] as &$zip_prefix) { // <-- line 377 if ($zip_prefix == $zip_short) { break; } else { $match = 'no'; } } It doesn't happen all the time, so I'm thinking that some spambot is populating the HTML form with something the script doesn't like(?). However, I tested that myself by entering text, or by entering just 2 digits, but there was no error. FYI, I do have code in the script that catches faulty input and warns people in their browser to go back and re-enter the correct data, so I'm at a loss as to why this is happening. How can I see what's triggering this to happen? I have the following line in my php.ini: error_reporting = E_ALL & E_STRICT & E_NOTICE & E_DEPRECATED Thank you, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] UNLESS Statement Equivalent
On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote: > the variable $current_page does not exist. That was my problem. :( I've been staring at this for too long. Too bad there's not a 'use strict' pragma. > I would also suggest keeping with your original statement to return early and > return often. Its best to exit out of your functions sooner than later. > Specially if its a large function. O.K. I just thought there might be a more elegant way of doing it. I at least got rid of the else statement like you mentioned. Thanks for your help, Angela
Re: [PHP] UNLESS Statement Equivalent
On Mar 11, 2013, at 3:47 PM, Ashley Sheridan wrote: > if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and > ($current_dt < ($saved_dt + 3600)) ) ) Hello Ash, This makes sense to me, but I can't get it to work, so I'm either not understanding it or I'm asking the wrong question. Here's a complete scriptlet: Using the supplied data, the result should be "Don't save." Can you see what's wrong? Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] UNLESS Statement Equivalent
On Mar 11, 2013, at 2:38 PM, Jonathan Sundquist wrote: > Since you already have the return statement with the if statement the else > isn't required. If those three statements are true you would exit the call > any ways I don't follow. The else contains the meat of the statement. Angela
[PHP] UNLESS Statement Equivalent
I'm looking for an 'unless' statement, but as far as I can tell, PHP doesn't have one. Hopefully someone can help me rewrite my statement. In English, I want to say: "always do something UNLESS these 3 conditions are met". The best I've been able to come up with in PHP is this: if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and ($current_dt < ($saved_dt + 3600)) ) { return; } else { $query = "UPDATE `table` SET `hits` = '$count', `agent` = '$agent', `ts` = '$date_time' WHERE `page` = '$page'"; $result = mysql_query($query) or die ('Error! -- ' . mysql_error()); } However, I've read where this is not really acceptable. Can someone help me eliminate the 'else' portion of this if statement? Thank you, Angela P.S. I realize the above isn't complete code but it should still be clear. If not, let me know. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Not counting my own page visits
On Mar 4, 2013, at 3:49 PM, David Robley wrote: > Misunderstanding what $cookie contains? It is a boolean, i.e. it will be > true or false depending on whether the cookie was set or not. To echo the > contents of a cookie, you need to use the cookie name, viz > > "; ?> You're right - I didn't really understand cookies. However, with everyone's help here, and by searching the web, I got it to work. Thank you to Tommy, Ash, and David! Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Not counting my own page visits
On Mar 4, 2013, at 11:33 AM, Ashley Sheridan wrote: > You can manually write a cookie on your machine, or use a special script that > only you visit that contains a setcookie() call (it only need be set once). > From there on, you can check the $_COOKIES super global for the presence of > your cookie. I don't know why, but I can't get cookies to work. Here's a script I'm calling from my browser: Test Page "; ?> "; ?> The domain is being displayed but the cookie is not. There's no cookie in the browser prefs, either. What am I doing wrong? Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Not counting my own page visits
On Mar 4, 2013, at 9:56 AM, Ashley Sheridan wrote: > set a cookie with a long life and check for that, discounting visits when > either are true Hi Ash, I don't know anything about cookies. It sounds complicated to me. Is there a simple way to set one? Thanks, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Not counting my own page visits
On Mar 4, 2013, at 9:52 AM, Tommy Pham wrote: > What about ignoring $_SERVER['REMOTE_ADDR'] or $_SERVER['REMOTE_HOST'] > where that matches your public IP or FQDN? Hi Tommy, I am checking for $_SERVER['REMOTE_ADDR'] but how would I check that against mine? I don't have a static IP. Thanks, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Not counting my own page visits
Hello, I have a script that counts hits to all the pages in my site and emails me a report nightly. However, it also counts my visits to my site, and when I'm coding, I'm hitting a lot of my pages, repeatedly. I'd like to find a way to not count my page visits. At first, I thought about adding a parameter to each URL and parsing that in the script, but that would get old real fast, and also, I may forget to add it each time. Is there a way to tell the script to ignore my visits? Thank you, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Complex MySQL query for lowest price
Thank you for everyone's input. Someone suggested the MySQL list, so I posted my question there and got the answer I needed. Regards, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Complex MySQL query for lowest price
Hello, I have a formula that says, if 'specialprice' is not empty and it is lower than 'unitprice', use 'specialprice', otherwise use 'unitprice': Your Price: $%s', number_format(mysql_result($result,0,"used_price"),2)); ?> What I'd like is to add a starting and ending date and if today's date is between those dates, then do the above formula, otherwise if today's date is not between those dates, then just use 'unitprice'. This is starting to get too complex for me, so I need some help. ;) Hopefully this makes sense. If I need to be clearer, please let me know. Thanks! Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php