Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by tibberous

  1. Hey everyone... I'm back.
  2. This is a simple task, but my brain apparently no longer works. I have a nested category structure - each record can have a parent, that is the id of another category. So: id name parent 1 Sporting Goods 0 2 Golf Clubs 1 3 Baseballs 1 4 Shirts 0 All I want to do is write a function that takes an id and gets all the children below it. It should be like 2 functions, with one being recursive... like 10 lines total... function has_subcategories($catid){ $result = $this->db->query("select * from `categories` where `Owner`=$catid and `active`=1 and `deleted`=0"); return $result->num_rows() ? true : false; } function get_subcategories($catid){ $result = $this->db->query("select * from `categories` where `Owner`='$catid' and `active`=1 and `deleted`=0"); $children = array(); foreach($result->result_array() as $subcat){ //echo $subcat['id'].'-'.$this->has_subcategories($subcat['id'])."<br>"; if($this->has_subcategories($subcat['id'])){ $children = array_merge($children, $this->get_subcategories($subcat['id'])); } else { $children[] = $subcat['id']; } } return $children; } Anyone see what I'm doing wrong? I've wrote this exact function before, not sure how I'm screwing it up.
  3. Godaddy sucks as both a web host and a registrar. MediaTemple also kind of sucks (godaddy bought them) Moniker is a good registrar.
  4. The advantage to using unescaped is that it at least shows you looked and made a consious decision to use unescaped data. Also, if you implement others code, you can replace their $_REQUEST's as needed.
  5. I normally hate best practices, but this one I came up, so it's less bad. Basically, you create a few functions like: function ireq($x){ return intval($_REQUEST[$x]); } function req($x){ return mysql_real_escape_string(trim($_REQUEST[$x])); } function unescaped($x){ return $_REQUEST[$x]; } Next, NEVER use $_REQUEST Now, to check your site for SQL injection holes, you can just search for $_REQUEST and "unescaped(". You can even use this method to slowly rewrite other peoples code, by replacing each $_REQUEST and making sure the proper characters are escaped. Has the added benifit of being MUCH fast to type - $i = req('i') vs $i = mysql_real_escape_string($_REQUEST['i']);
  6. Go post the url on 4chan. Don't say you want to test the security, just tell them it's your first PHP site and that your sure it's hacker-proof.
  7. <table><tr><td style='height:100px' valign='middle'>This is the middle.</td></tr></table> Theres some shitty hacks you can do to get it to work with divs, but since tables have had vertical align for the last 15+ years, I'd just use them.
  8. You acctually need some pretty advanced knowedge to do this. First, getting a PHP script to run at set intervals takes chron daemon (typically, I know there are other ways) You probably don't need curl. Unless your doing stuff like spoofing cookies and post variable requests, you can just do: $file = file_get_contents("page.php?p=1&section=whatever"); Biggest thing is probably going to be regex though. Btw, you might want to see if the news site has an rss feed that would be easier to parse.
  9. I have a MySQL set. I could query it as a string and do string compare, but I'd kind of rather get it as an i and do bit comparision. So... how do I do that? I know: select `permissions`+0 Will give me the decimal value of the set. How can I check to see if a bit is on or off though?
  10. A concept thats obvious to everyone but them. Windows 98 got destroyed for years because they tried to integrate ActiveX, IE and the operating system -- then they stuck in 1001 security prompts, like the problem was users running files and not the security holes that let websites run compiled code. Hopefully enough people will switch Microsoft will eventually quit developing it. They could preinstall Chrome on Windows 8, change the default search provider to Bing, and save a few million a year in development costs.
  11. I'd say thats true if you don't look at IE - I still get stupid things breaking in IE, like the third level of my dropdown menus and border styles on inputs and just general spacing. Maybe IE10 is better - don't feel like spending 20 minutes and a reset to upgrade though.
  12. Yeah - Firefox can't update without breaking plugins, I went like 4 months without Firebug. And no, theres no question, I though I was posting in Misc actually.
  13. You don't turn error reporting on in your editor, it's a feature in PHP that you turn on in the php.ini file. The path to you menu starts with this: inc/incfiles/ which means it needs to be in a folder called incfiles in a folder called inc.
  14. ROFL! Have you tried opening it in UEStudio or Word to make sure there aren't end of line characters in the file? You gotta fix it to really be able to work on it - even if it takes you 20 minutes to indent by hand, just do it or find some better code to start from.
  15. Sorry guys, I've kind of been under a rock, but what the hell?? http://en.wikipedia.org/wiki/Usage_share_of_web_browsers Only 25 of people are using Internet Explorer and thats rapidly falling?! I remember when it was %60! This is going to make a huge difference in how I program in browser support. I mean, getting stuff to kind-of work in IE was always an after-thought, but now it almost doesn't seem to matter. Crazy - I can remember when IE 6 had just been released and it was considered best practice to support IE 4. You were supported to do <font style="color: red" unless you also put in color="red". I still like my Firefox, but good on Google for getting the common folk to switch to a non-shitty browser.
  16. The one really interesting thing I found about your post is that, rather than use the association table for straight 1-1, you gave it a quanity field (I would have put quanity as a property of products without really thinking about it) It's funny because sometimes you make a thread to ask a question and kind of make your mind up while typing the thread - I think I'm going to reasses things now.
  17. I am making a multi-user system where there are multiple stores and multiple products. What makes this a little hard is that certain users will have several stores, and will be able to assign one product to many stores (thus the many to many) Generally you would make a binding table, but I'm wondering if it wouldn't be simpler to give products a varchar field called stores and just store the store ids like "-56-57-68-" A product can belong to multiple stores, but realistically it will never belong to 5-10. The only downside I can see is that, to select the products in a store, I'll need to use like '%-57-%' Even still, I wouldn't think it would matter much. Worse case, I could rewrite it as `Store1`, `Store2`, `Store3` or even take heavily trafficed stores and create them as seperate boolean columns. Just looking for general advice on how to handle this. Honestly, I might be over thinking it... I could probably do it however and it would work fine?
  18. Good point. I'd like to see more done in getting PHP to be a 'real' programming language. I use it for chron daemons, shell scripts... everything you can use Python for, but people always treat Python like it's a real language and PHP isn't.
  19. Seems pretty stupid? The problem is that Android is already free and damn near perfect. Maybe if they made it so that you could connect a moniter, keyboard and mouse and turn your phone into an actual computer it would be worth looking at.
  20. I don't think you understand what it does. It replaces a couple characters, namely ', with \' so you can insert them into the database. Lets say you were inserting "Jim's Car" - if you didn't escape it, the query would fail, because the sql would read: INSERT INTO `games`(`game`) VALUES ('Jim's Car') So, when you escape it, it replaces Jim's Car with Jim\'s Car, you still get Jim's Car in the database, the backslashes are typically never seen. So... yeah - thats escaping. It doesn't just randomly add slashes to strings, and you'll never see the slashes if you insert it into the database instead of print it to the screen.
  21. I'm guessing English isn't your native language? In PHP: <?php $s="Here is the first. Here is the second. Here is the third"; list($c) = explode('.', $s); $c .= '.'; echo $c; ?> That's probably the easiest way. Explode breaks the string into segments seperated by the period, and the list($c) = assigns the first array element to $c. The line $c .= '.'; just adds the period back onto the string.
  22. I have a multisite CMS. For security / performance I don't run the email off the main system, the mail records link to a dedicated email server that runs qmail / Plesk. It's pretty shitty. - The spam filter is simply bad (SpamAssassin). Using spamhaus doesn't stop much. Compared to gmail, it's junk. - If an account is comprimised, it seems to be very hard to figure out which account. The only way to even know at all is when the mail queue gets so hammered outgoing mail stops. There are mail limits, but there doesn't seem to be a way to pull up which email accounts are sending out the most messages. - Management isn't great. It isn't horrible, theres a web interface and a CLI, but there are just some stupid problems. If a client has 15 email addresses and wants the spam filter increased, you have to do it on all 15 emails individually, or write a script. Easy answer would be to use Google business mail, but the pricing on it can get out of control. For an organisation with 6 people and an info@, they'll be paying about as much to host email as the website itself. Does anyone know of a better solution?
  23. If somethings truely advanced, shouldn't it be easy to use? And if you make changes with msconfig, they don't revert. Crontab is a file, doesn't make sense it just disapears. I guess between Windows and Android I'm just use to OS'es not being a hodgepodge of esoterical crap. I *could* learn it, but I'd much rather see it replaced with something well designed and user friendly. Logmein shows just how well remote desktoping can work - what I'd really love to see if a server OS that you could manage though a client app. Guess as everything gets easier it just makes linux look worse. Open source sounds good in concept, but corperate software is really polished and user friendly lately... hell, anymore it's even becoming free.
  24. I hate Linux! Why does stuff reset on reboot? Every year I hope Google will come out with some super-advanced server OS but they never do. I'm gonna go find my stupid bashrc file, which would be /etc/startup if Linux made any sense. Thanks for the help.
  • 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.