Jump to content

boen_robot

Members
  • Posts

    8,493
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by boen_robot

  1. Remove the slash before the predicate, and remove the ";", i.e. instead of td[2]/a/[@onclick="javascript:getURLWin('";] make that td[2]/a[@onclick="javascript:getURLWin('"] However, it's important to note that, as written, this would not match "javascript:void(0)". It would only match an "a" element that looks like <a onclick="javascript:getURLWin('"> and that's probably not what you want.I'm guessing you want the attribute that starts with that, which you can do like: td[2]/a[starts-with(@onclick, "javascript:getURLWin('")]/@onclick
  2. Replace func_require('/controller/'.$page.'/'.$option.'.php'); with require $_SERVER['DOCUMENT_ROOT'] . '/controller/'.$page.'/'.$option.'.php'; That is all.
  3. When we talk about scope, we're talking about the variables defined in'/controller/'.$page.'/'.$option.'.php' being available only within func_require(). And anyway, why do you need a function for that to begin with? What else is this function doing besides doing a "require" on the file?
  4. CIDR is an alternative notation for a subnet mask. It specifies....(take a deep breath, focus and read slowly... it's impossible to avoid heavy use of terminology...)The number of bits from the IP address (left to right...) that indicate the network for an address. If another IP address starts with those same bits, it is considered to be part of the same network (a.k.a. "subnet"). An IP that after those bits has only 0s is considered "the network address", and is intended to be stored by applications that need to do network computations, such as what you're trying to do.For example78.178.242.140can be represented as the binary number01001110101100101111001010001100(which in decimal is 1320350348)A CIDR "21" would indicate that the first 21 bits are the network, so the network prefix is010011101011001011110(the network address is therefore 01001110101100101111000000000000 - 78.178.240.0)An IP address is always 32 bits, so whatever 11 bits follow those 21, they are part of that network. The IP with all 1s is also reserved => There are 2046 addresses within this subnet, and any subnet with the CIDR "21". They range from01001110101100101111000000000001 (78.178.240.1)to01001110101100101111011111111110 (78.178.247.254)Using ip2long(), you get the number, which you can then work with using bitwise operators (the "&" above is a "bitwise and"). You can check if an IP is within a network by doing a "bitwise and" between them, and checking if the result is the same as the network address, i.e. if ((ip2long($_SERVER['REMOTE_ADDR']) & $networkAddress) == $networkAddress) {//Is in the network} else {//Is not in the network}
  5. Wait... so your end goal is to get the network addresses?You shoudn't rely on the final ".", since that is only true for "/24".How about: $networkAddresses = array();foreach (explode($_POST['country_ip_ranges'], ' ') as $range) { list ($ip, $mask) = explode($range, '/'); $networkAddresses[] = long2ip(sprintf('%u', ip2long($ip) & (pow(2, (int) $mask) - 1)));} If you're then trying to compute stuff with those network addresses later on, it might be better if you keep the integer representations (resulting from ip2long), since they allow you to make bitwise operations, such as the one above.
  6. What's the idea here? I mean... you said the expected output is 7,9,12... but what does that represent?
  7. Many sites do that, but they only use the main page as a "routing page", i.e. that page sends global site content and based on the URL, it includes another file to deal with the details of that particular section/page.The advantage is obviously ease of organization. The disadvantage is a slight performance penalty (due to the time it takes to analyze the URL, and include it), but if you do some sort of output caching, you'll negate all that.
  8. boen_robot

    XSitePro ?

    Blah...I can clearly see why davej didn't linked to that. This has a huge "scam" smell all over it.In fairness, it seems like a real desktop application... but the whole sales pitch is the very definition of "over promise", which naturally makes me think "... and under deliver".It's clearly targeted at people who not only can't make a web site by other means (which is kind'a understandable), but also haven't thought about what makes a web site appealing (let alone actually trying to create one).
  9. There is a poll feature on this forum you know (from the right...).I've added a poll for you.But anyway... this forum isn't much about stuff outside of web dev topics. We sometimes make exceptions about computer related topics, since they're in the same ball park, but this? Err... I'm on the fence about it.I guess it depends on why are you collecting votes about this?
  10. Done.I'll leave the topic open non the less, in case someone has objections or something.
  11. PHP isn't like other languages (e.g. JavaScript, C#, C++, etc.) where the scope is automatically expanded when something is missing from the current scope.If you have $photo->setDB($db); then $db will be referring to a variable declared within the current function/method, while $photo->setDB(static::$db); refers to a variable/property declared within the class, and NOT within the current function/method.If you're instead asking about the difference between self::$db and static::$db... birbal already clarified that one.BTW, for this code to work without any notices, you should be using protected static $db; instead.
  12. boen_robot

    session start

    The HTML and PHP layers have nothing to do with each other. The form's action is part of the HTML layer.If in the PHP layer, you're using the $_SESSION variable, you need to use session_start() somewhere before that, regardless of the HTML (so yes, even if there's an action attribute to a different page).
  13. Most applications use a configuration file for this and other environment-dependent settings.Depending on the level of complexity of your application, you could either just include a file with variables/constants, like you're already doing, or you may include a file that returns an array/object that is your configuration, or you might use some sort of configuration file parser for a non-PHP file type (e.g. an ini file, an XML file, etc.).There is no recommended way of doing this, nor is there a most popular convention. Whatever you think will strike the balance between being easier (and flexible enough) for you and others to work with vs. your application easily reading and acting differently based on the configuration.
  14. boen_robot

    About ISP

    I think that's due to most sites putting their JavaScript in the head without any async/defer stuff, making the execution of the page slow, even when the download is instant.
  15. Sounds more like something you'd do with URL rewriting.Google "mod_rewrite".
  16. boen_robot

    code

    This means the exact same thing as: So... the idea was that there is a point in checking if the field is submitted, especially if the form submits to itself (i.e. if the action is also the page with the form).But even disregarding that... That's just false.- A user may submit your form, and unless he's redirected away, he can copy the URL, and open up the page again, without resubmitting the form.- A hacker can use an HTTP debugger to send an HTTP request directly to the form's action, bypassing the form. At that point, he can submit arbitrary name/value pairs OR not submit any.
  17. boen_robot

    About ISP

    I work at a computer shop, repairing computers, and selling new ones.We're also a mini ISP, and by that I mean that we offer internet connection to the neighbourhood, but we lack the resources to go further than that, even though we have people outside who want to join our network.The offers that we give are about double your speed for almost the same price, but obviously, that's a "very low speed" compared to what people can otherwise get here, which is just another reason I say "mini".I think you can clearly see why I'm on the "high" end of the "home user" spectrum .
  18. boen_robot

    code

    If you use empty(), you don't need to use isset(). empty() would return false if the variable isn't set.If your definition of "empty" is different from what empty() checks for (e.g. if you accept the string "0" as not empty), then yes - you'd have to first check if the variable is set, and then check if it fits your custom definition of empty.
  19. boen_robot

    About ISP

    You have better upload than download ?!? Are you having a server at home or something?And is that the offered speed or the actual speed? I mean, if it's the actual, well... some cheaper offers at other Bulgarian ISPs have exactly that. If it's the offered... yeah, that's significantly worse indeed.
  20. boen_robot

    About ISP

    At home, I pay 30лв. (~$18.75) per month for a TV/Phone/Internet pack, with the internet being advertised as 100Mbit/s download and 50Mbit/s upload. I typically only reach that speed from torrent downloads, and very few ones at that. But that's to be expected, since this speeds are not explicitly labelled as "guaranteed", i.e. they're only a theoretical maximum that would only be reached if the ISP's network is under utilized.My average speed is more like 8-16 Mbit/s (1-2 MiB/s), but that's more than enough for everything I do (including watching HD videos online), it's the cheapest offer at my ISP (there are cheaper on other ISPs, but they don't have maximum speeds that high, and/or they don't include TV and phone in the pack), and it's without outages (in fairness, my previous ISP had only 1 outage per year, and I'm on this one for only a few months now), so I'm happy with it.This 100Mbit/s is pretty much the maximum in Bulgaria (at least the maximum I've seen), except that there are more expensive offers where- The speed is guaranteed, rather than maximum- The speed is symmetrical, i.e. the upload is also 100Mbit/s (guaranteed in the most expensive offers)- You get a static IP address- You get additional (static or perhaps dynamically assigned) IP addresses.Of course, those are directed at ISPs rather than home users, since we're talking about prices that are only just starting at 60лв. (~$37.50), which is relatively cheap if you take other countries with similar economies, except that electricity costs here are more expensive, so the net result is that offers like mine and lower are the ones the vast majority of home users use.
  21. Those were just pseudo names, used to illustrate the point. The real names need to correspond to whatever the nodes in your XML are. Your XSLT doesn't give me any hint as to how the XML looks, which is why I used those pseudo names instead.The general idea is that in the XML, you have nested elements, and you only want links on the inner most ones. This XSLT creates a "ul" for each level, and a "li" for each item at that level. When at the most inner level, a link is also created.How does your XML look like? What qualifies a node as "the inner most item" vs. "an item, but not the inner most one"?
  22. boen_robot

    code

    Who said that? I didn't...
  23. boen_robot

    code

    Your later snippet checks (!isset($key)) which is redundant - if you're within the foreach, you're looping over existing keys.That code is better as something like function hasEmptyValues(array $arr) { foreach ($arr as $value) { if (empty($value)) { return true; } } return false;} And as the name suggests, this only checks if there are empty fields in the submitted form (which is also what your snippet does).If a person (say, a hacker) tries to use an HTTP debugger, they can submit the form without setting all required fields (I mean, not even with empty values). Neither this function, or your snippet, check for that. You must explicitly specify somewhere the fields you want, and then use functions similar to the above to further verify their contents.Here's a function that allows you to give it an array to check, along with an array with the required fields: function hasAllRequiredFields(array $arr, array $requiredFields) { foreach ($requiredFields as $key) { if (!isset($arr[$key])) { return false; } } return true;} As you can see, it's an extension of your first one-liner.
  24. boen_robot

    code

    It checks if a user has filled in the "username" field on a form (which uses the "post" method...). It doesn't necessarily mean the password (or any other field) is filled as well.
  25. Instead of calling templates, try matching them.Something like (pseudo code): <xsl:template match="/|inner-list"><ul><xsl:apply-templates select="list-links" /></ul></xsl:template><xsl:template match="list-links[inner-list]"><li> <xsl:value-of select="link-label" /> <xsl:apply-templates select="inner-list" /></li></xsl:template><xsl:template match="list-links[not(inner-list)]"><li> <a href="{link}"><xsl:value-of select="link-label" /></a></li></xsl:template>
×
×
  • Create New...