|
Hm, most of the pages on my site are .html, but I don't want to change them all to .php (and go through and edit the htaccess to that too); is it kosher to do something like <img src="stats.php" class="nodisplay" /> so that I don't have to do a PHP include on each page/change the extensions/HTA? stats.php will obviously log browser data/counts.
|
# ? Sep 8, 2008 21:21 |
|
|
# ? May 16, 2024 18:53 |
|
That should work fine, just make your php script dump out a image or something (1x1 transparent gif would suffice) so you can avoid stuff like the red X on IE:php:<?php /* stats script doing stuff here ... */ header("Content-type: image/gif"); echo file_get_contents("/path/to/transparent.gif"); ?>
|
# ? Sep 8, 2008 21:57 |
|
Munkeymon posted:I guess you could do this: That's what I want. We are getting a bunch of SQL injection attacks on our web site, so I want to write a script that pulls the source IP address from the IIS log file as it happens and keep a tally of them per hour. This seemed the easiest way of doing it.
|
# ? Sep 9, 2008 00:04 |
|
cka posted:That should work fine, just make your php script dump out a image or something (1x1 transparent gif would suffice) so you can avoid stuff like the red X on IE: Ah, good idea, I hadn't thought about that (though I don't know if said red X will appear if the "image" is display:none'd).
|
# ? Sep 9, 2008 01:01 |
|
windwaker posted:Ah, good idea, I hadn't thought about that (though I don't know if said red X will appear if the "image" is display:none'd). It'll still show up in browser validation extensions and stuff, so you may as well do it.
|
# ? Sep 9, 2008 01:32 |
|
windwaker posted:Ah, good idea, I hadn't thought about that (though I don't know if said red X will appear if the "image" is display:none'd).
|
# ? Sep 9, 2008 14:11 |
|
Does anyone know how to check if a remote file exists? I can do it with file_exists() but only on local files ... I need my script to check if x.swf exists on a remote web address, but don't want it to load the full file, only, say 50 bytes or so so that the visitor won't notice any lag. would fread accomplish this? fopen in php.net doesn't seem to have good examples of this.
|
# ? Sep 9, 2008 16:34 |
|
eHacked posted:Does anyone know how to check if a remote file exists?
|
# ? Sep 9, 2008 16:40 |
|
Stephen posted:I've done this before using cURL by checking the response sent back from the server for errors. It worked, but there's probably a lot better ways to do it. Probably not. If HTTP is the only means of communicating with that server, then your way is ideal.
|
# ? Sep 9, 2008 19:34 |
|
I'm going out of my mind with this one. I have a csv that's generated from a website that I need to read in to a sql table. I cannot control the file coming to me as far as how it's encoded etc. Right now, when I use fopen, fgets and then a little csv parser I wrote, and then add the rows to my sql tables I'm having an issue. On both the echo statements I use for debugging in firefox and in the actual table itself there is a little black diamond with a question mark in it in between every single character. If I open said csv in notepad, resave it as ANSI encoding and run the exact same process, it works fine. I did enough research to know this has to do with character sets and how the file is encoded, but I was pulling my hair out trying to get this to work. I used utf8_encode and utf8_decode on the string coming in after fopen and before converting it into an array for processing. I tried iconv(), mb_convert_encoding(), htmlentities(), htmlspecialchars(), adding the charset to use in a header statement on my php page and just about any other fix I could find regarding unrecognized characters. None of them worked. Some got the first value in the array to be fixed and turned the rest into blank, some added more ?s, some did nothing, one even changed it all into japanese characters. Most of the solutions I found were regarding changing the ?s into what they were originally coming in as, like foreign language characters or something. I want them gone. When I view the csv in any text editor, I can see all the data just fine sans any unrecognized characters or whitespace. I know this might have to be with me not understanding encoding and decoding different filetypes and making my website UTF-8 compliant but I figured it was a good time to learn.
|
# ? Sep 10, 2008 20:25 |
|
Lank posted:Right now, when I use fopen, fgets and then a little csv parser I wrote, and then add the rows to my sql tables I'm having an issue. On both the echo statements I use for debugging in firefox and in the actual table itself there is a little black diamond with a question mark in it in between every single character. php:<? iconv("UCS-2","UTF-8", $string);?> quote:I have a csv that's generated from a website that I need to read in to a sql table. Standish fucked around with this message at 20:48 on Sep 10, 2008 |
# ? Sep 10, 2008 20:45 |
|
Standish posted:If every single character (even regular alphanumeric characters) has a black diamond before it then it sounds more like UCS-2 encoding than UTF-8. Try That might be one of the few combinations I didn't try. I tried using UTF-16LE to UTF-8 but that didn't do the trick. I'll attempt the UCS-2 conversion and come back here with header information if it doesn't work. The site the csv is coming from has a little "Generate report!" button and just spits out a download prompt when it creates the file so I'm not sure how much information I can get on whether the file is screwy or not. I tried using mb_detect_encoding or whatever that function is and it was saying the strings were ASCII...so that didn't help me very much, but I can dig some more. Am I corrent in thinking USC-2 is kind of archaic? Thanks for the suggestions, I'll give it a shot.
|
# ? Sep 10, 2008 20:54 |
|
Lank posted:The site the csv is coming from has a little "Generate report!" button and just spits out a download prompt when it creates the file so I'm not sure how much information I can get on whether the file is screwy or not. LiveHTTPHeaders for Firefox should let you see what it's being sent as if that is set correctly.
|
# ? Sep 10, 2008 21:02 |
|
Lank posted:I tried using mb_detect_encoding or whatever that function is and it was saying the strings were ASCII...so that didn't help me very much, but I can dig some more. If you haven't, I'd recommend trying the function on just one field of the csv import instead of the whole thing. Formally I know very little about character encoding, but I know an awful lot from banging my head against it incessantly. I believe that the file could be structured in that the csv file structure is in ascii, but each field of data is encoded in the weirdo encoding.
|
# ? Sep 10, 2008 21:42 |
|
Leavy posted:I believe that the file could be structured in that the csv file structure is in ascii, but each field of data is encoded in the weirdo encoding. Oh that's special. Haha. Well I've got lots of new things to try out. Thanks a ton. If none of that works then screw it, part of the SOP will be "Open in textpad, save as ANSI".
|
# ? Sep 10, 2008 21:48 |
|
Not sure if this is a PHP question or a mySQL question really.. Basically I'm trying to store a number in a decimal field in my mysql database. The number is greater than 0, and I need a fair few decimal places. The field size is 20,20. Now, I'm trying to store my number in there, but it seems to misinterpret it and I don't know why. The code is like this: code:
I've never coded PHP before, but I'm used to ASP and it's not a lot different, so this is a bit confusing to me. If I did essentially the same code in ASP I'm sure it would work properly. Any help is appreciated. edit: nevermind, fixed it. I changed the field to double and fixed the size limits... I think mysql dislikes the lengths being the sames sizes. Vince McMahon fucked around with this message at 21:30 on Sep 11, 2008 |
# ? Sep 11, 2008 20:40 |
|
Vince McMahon posted:edit: nevermind, fixed it. I changed the field to double and fixed the size limits... I think mysql dislikes the lengths being the sames sizes. MySQL reads the definition as SIZE, PRECISION, so 20,20 would be a column that holds 20 digits, with 20 digits of precision (all of the digits.) For example, a cost column would be decimal 5,2. It would hold up to 999.99. http://dev.mysql.com/doc/refman/5.0/en/precision-math-decimal-changes.html jasonbar fucked around with this message at 23:05 on Sep 11, 2008 |
# ? Sep 11, 2008 23:02 |
|
Yeah that was the problem. In my head I think I saw 20,20 as 20 digits infront of the decimal, 20 behind. Oops!
|
# ? Sep 12, 2008 09:12 |
|
What is the best way (if any) to carry sessions over domains? E.g. My users will login to admin.something.com. Options will be given to them based on what sites they have access to such as new1.something.com or new2.something.com Since they need to login to admin.something.com I don't want to make them re-login when they select a page they have access to.
|
# ? Sep 12, 2008 15:13 |
|
Stephen posted:What is the best way (if any) to carry sessions over domains? E.g. My users will login to admin.something.com. Options will be given to them based on what sites they have access to such as new1.something.com or new2.something.com Set a cookie with the domain ".something.com" http://us2.php.net/manual/en/function.setcookie.php
|
# ? Sep 12, 2008 15:41 |
|
SuckerPunched posted:Set a cookie with the domain ".something.com"
|
# ? Sep 12, 2008 16:14 |
|
Stephen posted:I guess if I stored the session ID and the IP address in the database and matched them each time the user browses to a page, it wouldn't be so bad. If you want to protect your users against cookie sniffing/session hijacking, use SSL (and set the "secure only" attribute on your cookies).
|
# ? Sep 12, 2008 16:40 |
|
Standish posted:You can't assume in general that a user will retain the same IP address for the length of their session, it breaks for a lot of ISPs that put their users behind transparent load-balancing proxies. (You can't even assume the top /16 or /24 bits of the IP will be the same, I've run into situations where consecutive requests from the same user came from totally unrelated IPs.)
|
# ? Sep 12, 2008 16:58 |
|
Stephen posted:That's a really good point. Thanks for the tip. This means I'll have to enabled SSL across all of the sites, yes? If you're trying to make it as secure as possible, yes.
|
# ? Sep 12, 2008 17:39 |
I'm trying to use this PHP Serial Extension following this reference for XAMPP but it's still saying the extension isn't loaded. What could be causing this? My phpInfo() is showing: Server API: CGI/FastCGI Loaded Configuration File: C:\xampplite\php\php.ini and that is the php.ini where I put: extension=php_ser.dll
|
|
# ? Sep 18, 2008 20:03 |
|
fletcher posted:I'm trying to use this PHP Serial Extension following this reference for XAMPP but it's still saying the extension isn't loaded. What could be causing this? Did you look in the error log? I am guessing that it is not finding the dll file.
|
# ? Sep 18, 2008 20:21 |
Begby posted:Did you look in the error log? I am guessing that it is not finding the dll file. [error] [client 127.0.0.1] PHP Warning: PHP Startup: win_serial_port: Unable to initialize module [error] [client 127.0.0.1] Module compiled with module API=20050922, debug=0, thread-safety=1 [error] [client 127.0.0.1] PHP compiled with module API=20060613, debug=0, thread-safety=1 [error] [client 127.0.0.1] These options need to match [error] [client 127.0.0.1] in Unknown on line 0 So I guess it was designed for an earlier version of PHP - any way around this? Is there just a command line program I can call to communicate with the COM port? This also looks promising. fletcher fucked around with this message at 06:22 on Sep 19, 2008 |
|
# ? Sep 19, 2008 06:11 |
|
code:
I need to pass any further variable on, say http://penis.url.com/testicles as rewriterule http://url.com/index.php?subdomain=%1&switch=%2 - can you fine gentlemen offer me any assistance?
|
# ? Sep 19, 2008 09:53 |
|
I have a question for you guys. I'm writing a small application for work that basically disseminates information to a few email distribution lists. I'm trying to keep the entire application object-oriented as I can see myself reusing a few of these classes in the future. My question is in regards to small classes / functions. Does it make sense to create a class that simply provides one function? Would it make more sense to try and fit that function into another class? For example, consider the following function: code:
Any insight would be appreciated.
|
# ? Sep 19, 2008 21:07 |
|
xluna posted:I don't really have a class that does anything specific with string formatting/manipulation, so should I create brand new one that only serves that purpose? I suppose my question is really more about best practices when using object oriented techniques. I'm relatively new to it honestly, and I'm trying to break my procedural habits. I usually create a static utility class to handle one off things like string manipulation and validation. All of the methods are declared as static, and they do exactly what you have there, accept something, transform / validate it, and return. That way you can keep all of your utility library functions in one place, if you are utilizing __autoload you can just call Utility::DoSomething($blah) and get the expected result from anywhere without worrying about including anything extra. jasonbar fucked around with this message at 21:39 on Sep 19, 2008 |
# ? Sep 19, 2008 21:36 |
|
jasonbar posted:I usually create a static utility class to handle one off things like string manipulation and validation. All of the methods are declared as static, and they do exactly what you have there, accept something, transform / validate it, and return. Awesome. Great idea. I didn't know how static methods worked, and this just made life a lot simpler. I knew there had to be a way to simply use class methods without instantiation as you do it all the time in C++, i just wasn't sure how because of my new-ness to it all.
|
# ? Sep 19, 2008 23:14 |
|
I'm a Java Servlet/J2EE guy, and I just read through the PHP documentation on their site. They don't seem to come out and say it directly, but it seems like a new PHP interpreter is created, runs and then dies within the scope of a single http request? (As opposed to Java where it runs continuously and handles incoming requests with threads). The reason I ask is because it would seem to make it tricky to do things like cache database queries in memory or maintain user session in memory. The options seem to be storing session in the browser cookie (bleh), or flat files (slow). Is there a way to make PHP run persistently, or do I just have to change the way I approach writing webapps?
|
# ? Sep 22, 2008 01:51 |
blargle posted:I'm a Java Servlet/J2EE guy, and I just read through the PHP documentation on their site. They don't seem to come out and say it directly, but it seems like a new PHP interpreter is created, runs and then dies within the scope of a single http request? (As opposed to Java where it runs continuously and handles incoming requests with threads). The reason I ask is because it would seem to make it tricky to do things like cache database queries in memory or maintain user session in memory. The options seem to be storing session in the browser cookie (bleh), or flat files (slow). Is there a way to make PHP run persistently, or do I just have to change the way I approach writing webapps? You can use PHP Sessions. Also check out memcache for caching stuff from a database.
|
|
# ? Sep 22, 2008 02:34 |
|
xluna posted:Awesome. Great idea. I didn't know how static methods worked, and this just made life a lot simpler. I knew there had to be a way to simply use class methods without instantiation as you do it all the time in C++, i just wasn't sure how because of my new-ness to it all. Static methods are handy, but don't overuse them. If you do you will make your classes harder to reuse since they are dependent on the implementation and naming of classes. Also, it makes it harder to do unit tests. I fell into this trap, and ignoring the advice I received on this forum and others dug some deep holes for myself that are still biting me in the rear end. For instance, you might be tempted to create a database class and call it like mydbclass::query($sql). Then mydbclass might have a singleton db connection or something. The problem arises when you try to reuse dependent classes in a different application, you have to have mydbclass wherever that class is uses. Or what if you want to query two databases with the same object that depends on mydbclass. You would be up a creek. So it can be handy, but don't overuse it. Often it is better to pass objects in constructors like this, and to make classes dependent on interfaces: code:
|
# ? Sep 22, 2008 13:32 |
|
Is there a good way to gracefully reject file uploads that are too large? Limits are usually controlled through php.ini or other files that compliment it such as .htaccess, which means PHP is the one throwing a fit when something is too big. I want to display a user-friendly error if somebody tries to upload gargantuan, unresized images from their 14 MP camera to a website. My guess is that there is some sort of error you could check for on postback, but Google comes back absolutely dry when I look up information on this. Any ideas? edit: I hate it when I find the answer 2 seconds after I give up. $_FILES["some_field"]["error"] == UPLOAD_ERR_INI_SIZE (or similar errors) does the trick. edit2: This only returns errors if individual files go over the collective limit, so it's no good for multiple file uploads. For now, I'm just using a function that adds up all the $_FILES["some_field"]["size"] fields and compares the result to max_upload_size (in integer form). If anybody knows a simpler way, tell me about it. Zorilla fucked around with this message at 21:22 on Sep 26, 2008 |
# ? Sep 26, 2008 01:18 |
|
I've got three sites all hosted on the same server in separate virtuals. One of the sites is an admin section that should be able to upload pictures etc. to the other sites. I tried writing files using the absolute path of the site on the server, but that failed. I could FTP each file to it's respective site once the user has uploaded it, but that just seems a bit messy. What are my options (if any) for writing files across sites? Edit: Solved it by posting the file to the other site, and then redirecting back again. Stephen fucked around with this message at 16:46 on Oct 1, 2008 |
# ? Sep 30, 2008 22:29 |
|
Is there any way to get a DIVs size using PHP? I really need to find this out soon, this image gallery is killing me.
|
# ? Oct 1, 2008 09:58 |
|
Aturaten posted:Is there any way to get a DIVs size using PHP? I really need to find this out soon, this image gallery is killing me. PHP outputs HTML on the server and sends it to your browser. Your browser then renders the div and creates the size, at that point PHP is done processing. You would need something client side to read the div. You could however send this back to PHP via javascript or something. That is unless I am missing your point, if so be more descriptive.
|
# ? Oct 1, 2008 13:11 |
|
Aturaten posted:Is there any way to get a DIVs size using PHP? I really need to find this out soon, this image gallery is killing me. Yeah, more info would be good. If you want to find the size of a div after the image loads or whatever, it might be a little bit tricky. Try making the divs a fixed size instead. If you really really really need to do that, however, the best way might be to AJAX it up. There are faster ways, but that would be the easiest. If you need a little more speed for a little more work, though, you can do everything serverside by using GD to find all of the image sizes and adding them up.
|
# ? Oct 2, 2008 04:51 |
|
|
# ? May 16, 2024 18:53 |
|
I have a huge table of articles I've posted on one of my personal sites and each entry has a tags field as such art_id, art_name, art_cont, art_tags 1, "title of article 1", "content of article 1", "hello, wooop, omnomnom" 2, "title of article 2, "content of article 2", "jello shots, canabis, gaysex" 3, "title of article 3, "content of article 3", "jello shots, canabis, robin hood" 4, "title of article 4, "content of article 4", "canabis, woop, something else, craigslist" How would I create an array of all the tags, ordered by any more commonly used ones first? Would I implode them all into a tags array, order by somthing then use an array function to remove dupes? or is there some mythical magical MySQL command that'll accomplish this for me?
|
# ? Oct 2, 2008 23:00 |