Jump to content

requinix

Administrators
  • Posts

    15,227
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. What have you tried so far? You're probably very close already. And I don't know about the links, and I haven't seen any settings for it. You can add a space or something to break them.
  2. Calm down, it's only been 30 minutes on an early Monday morning. Yes it's possible. In a .htaccess: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/(get_categories|...)\? RewriteRule ^ index.php?%1= [L,QSA] For every API call to do URL rewriting on, add it to that third Cond separated by |s. Like ^/(foo|bar|baz|whatever)\? (If anyone's wondering, I used a third RewriteCond for readability's sake.)
  3. $("input#show_invitations_button, th#show_invitations")
  4. I just love copy/pasting the same answer across forums.
  5. A shell script (or a single command, even) would be easier. If you can't do that then is your PHP script running as root?
  6. It should be possible. MySQL can calculate the average and then round it up and down for the two vote numbers. You'd have to construct a loop but with a counter @variable you can do it. If the average is 3.x then it's possible to come up with a set of 3 and 4 votes that satisfies the two conditions. That's because any 1, 2, or 5 votes can be "transformed" into 3s and 4s without affecting the grand total or the number of votes. Because there's an average of 3.x, every low/high vote must have a "balancing" set of high/low votes that maintains the average. The math turns those balanced votes into 3s and 4s regardless of what the actual numbers where. The low and high values are just the two numbers on either side of the average. Say the average is 4.x. Start off with some vote close to that average, like 4. You can pick lots of 4s but the average of them will be too low. You need some higher votes, like 5, to raise it. In this case we picked the two numbers on either side of 4.x - you could pick anything really, it's just that it's easier to pick 4 and 5. Not mentioned is how this all only works if there is a possible set of votes to sum to the total and also maintain the average, but this is the case because these numbers aren't just randomly generated: there was a series of real, legal votes that resulted in them. If it weren't then all the math is out the window because it's simply not possible.
  7. As I answered elsewhere,
  8. It uses a regular expression: "/^(?!(??:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(??:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(??:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(??:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(??:(?!.*[^.]{64,})(??:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(??:[a-z][a-z0-9]*)|(??:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\\[(??:IPv6:(??:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(??!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?:?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(??:IPv6:(??:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}|(??!(?:.*[a-f0-9]{5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?:?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}?)))?(??:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(??:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD" and has a copyright. Copyright © Michael Rushton 2009-10 http://squiloople.com/ Feel free to use and redistribute this code. But please keep this copyright notice.
  9. Regular expressions are basically the way to go, but unless you want a (theoretically) perfect expression you'll have to settle for some false positives and/or false negatives. Google can help you get one of those. Next is checking the domain name. getmxrr can look up the mail server for a domain, but if there isn't one you should assume that the hostname also acts as a mail server (IIRC that's part of the standard). You could go another step and try a connection to the server if you wanted. After that you might be able to verify a "username" but it depends on whether the mail server is nice enough to help with that. Generally you don't have to go this far: services that use an address in, for example, a registration process send an email to confirm it. This is what you should do.
  10. Define "exists". And any particular reason it has to be used via the command line (as opposed to a normal script you'd use in a webpage)?
  11. $error->ErrorHandle($setError); You haven't defined $error inside that function. The one on the outside doesn't matter. Inside the catch block, instantiate a new errorCatch and call its ErrorHandle.
  12. That "image/jpeg" comes from the browser, not from PHP. Besides the fact that it's totally untrustworthy, not all browsers will call an image by the same name. Use a function like getimagesize to independently check (a) that it's an image and (b) what type of image it is.
  13. This topic got lost and ended up having to ask for directions to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=357624.0
  14. First, if 1*votes = voteTotal then all the votes are 1. If 5*votes = voteTotal then all the votes are 5. Otherwise get the average, which must be between two numbers in the 1-5 range. Call those two numbers "low" and "high". Take the fractional part of the average and * votes (and round). This is the number of "high" votes. The remainder is of "low" votes. voteTotal = 1394 votes = 431 1*431 = 431 so not ones 5*431 = 2155 so not fives 1394 / 431 ~ 3.23433 so low=3 and high=4 0.23433 * 431 = 101 so that many votes of 4 The remainder is 431-101 = 330 votes of 3 I can explain the proof if anyone wants.
  15. That duplicated row probably has two matching rows in the other table (it's hard to tell which table is which in what you've posted). Example: table1 table2 id | one id | two ---+---- ---+---- 1 | abc 1 | JKL 1 | XYZ SELECT table1.* FROM table1 JOIN table2 ON table1.id = table2.id (table1) (table2 which you can't see) id | one | id | two ---+---- +----+---- 1 | abc | 1 | JKL 1 | abc | 1 | XYZ
  16. This topic is now in MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=357554.0
  17. 99% of the time that error message means your query failed. There's a problem with it and MySQL couldn't execute it. The actual problem here is moot because your query needs to change. It won't do what you're trying to do. So give it another shot. Try the most obvious solution first, and once that's working you can think about whether there's a better way of doing it.
  18. A little short on details, and I think you mean spring->summer->autumn, but If the seasons were numbered like Spring=1, Summer=2, Autumn=3, Winter=4 (which is #1 doesn't matter as long as they're all in sequential order) then you could use a little bit of math and a UNION. # the non-special events first SELECT ... ORDER BY MOD(season + 4 - N, 4) UNION ALL # special events SELECT ... If N is the number for the "first" season (ie, the current season) then the MOD() will turn the first season number into 0, the next one into 1, then 2, and 3 for the last season. Thus sorting. An alternative would be a big CASE and could be more efficient.
  19. str_pad() works, but personally I prefer sprintf. $current = "0052"; // absolutely must be a string! $next = sprintf("%04u", $current + 1);
  20. There could be a couple options available. What's the site?
  21. You need to add C:\Windows\Temp to the open_basedir list.
  22. IMO it's not that cut and dry. There is only one major distinction: whether you're a blue pill programmer (learn-by-what) or a red pill programmer (learn-by-why), but even there will be some mixed behaviors. The rest is down to just how long you've spent programming and how much progress you've made since you started. By the way, I'm trying to not rant. I think I did well. Blue pill programmers learn by covering various topics. They copy/paste "codes" they find on the Internet, fiddle with them until they work (or give up or ask someone for help), congratulate themselves, and move on. They look at a subject long enough to remember what it's called. When things don't work it's probably some "bug" in PHP or some really weird behavior (unique to them, of course) and the workaround involves changing their code into something different... but whatever, it works now. They hear about some cool concept, find a tutorial somewhere, copy/paste the code (or download "scripts") and figure out how to make their own code work with it. But they don't actually learn. Sure they've dealt with lots of subjects but they don't actually learn what's going on. SQL injection is because someone didn't addslashes() on some input and/or haven't turned on magic_quotes. $_FILES["name"]["type"] is automagically some value that says what the type of file is. Classes are things that have variables and functions. If they get hired at a company it's because the company (a) needs someone for cheap or (b) doesn't understand how to evaluate the skill of a programmer. The programmer will introduce many problems in the code but it takes a long time for them to be noticed because (a) the other programmers are also at that skill level or (b) the site doesn't draw enough users/traffic/attention for anything big to get exploited or broken. Red pill programmers learn by finding out how things work. They see a website and want to make their own, then start learning how websites work. They might find the various options like PHP and .NET and Python and (for this discussion) choose PHP. They use WAMP because it provides the things they need and requires minimal configuration. When scripts work it's because they put what they've learned together into one cohesive unit; when things don't work they try to figure out why and then fix it. New subject matter requires some research: maybe a manual or documentation, maybe a forum or community, or maybe just playing around with it. Maybe they find working examples and take them apart to see how it is they work. And they do learn - maybe not everything, maybe not in depth, but they understand how things work conceptually rather than in terms of what lines of code are needed. Once introduced to the concept that users are malicious they will distrust stuff not because it's in $_GET or $_POST but because it comes from the user. Might wonder where the information in $_FILES comes from, and when they realize it's not from PHP they start wondering "then where?" From the user? So does that mean a malicious user can manipulate the file type? Oh they can? Oh, well then some code needs to change. Hears about SQL injection and how bad it is, and wonders if what they're doing is enough. How about some more direct comparisons? - Classes BPP: collections of variables and functions, classes can get other variables and functions from other classes if you "extend" them RPP: things or entities; OOP is very complicated, there's things like polymorphism and design patterns, and PHP supports a lot of it - MySQL (and databases in general) BPP: tables have columns and rows, use queries to do things; SQL injection is because a programmer didn't escape the quotes RPP: more things and entities, they're probably related to each other somehow, there are different types of queries for different things; SQL injection is because someone, somehow manipulated the query string - File uploading BPP: PHP gets uploaded files, type and name tell the file type and original name, you have to copy the files somewhere RPP: PHP gets uploaded files, you have to make sure the files are safe and then you can copy them somewhere - Validation/sanitization/other basic security principles BPP: regular expressions can check anything, JavaScript is good for doing it, I don't need to worry about security because $reason RPP: regular expressions are complicated, JavaScript is nice but I can't rely on it, I should worry about security regardless of whether I trust my users or not
  23. No. But it could have something to do with that being a syntax error. Which bothers me because you said that code worked in 5.3.1. Which it couldn't possibly.
  24. You can rename the file on the server to whatever you want. I even recommend it. Whatever name, whatever directory. What the user will see is what you show them. As long as you store the original information (eg, filename) somewhere then you can show it to them later. For example, download scripts. The URL can be anything because the (suggested) name of the downloaded file is given by your script in the Content-Disposition header.
  25. What does "doesn't work" mean? Blank page? You get the failure message? Okay so it doesn't do what you want, but what does it do? Also, you're overwriting the $uniekpatient with the uploaded file. First you put the $inhoud stuff in there but then you move the uploaded file there as well. (Unless you actually have to,) you don't need to put $inhoud in a file. All that information is being stored in the database so you can look it up anytime you want. Another possible problem could be with permissions. You're putting the files in the same directory as this .php script (which is a bad idea - put them in a dedicated directory like uploads/ or something). On Linux-/Unix-based systems you need to have write permission on that directory. Try chmodding it to 0777.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.