Jump to content

requinix

Administrators
  • Posts

    15,266
  • Joined

  • Last visited

  • Days Won

    431

Everything posted by requinix

  1. "The file input"? rename (which does moves too) Figure out the path to the file in directory A, figure out the path you want it for in directory B, and pass both to rename().
  2. Okay, you got the "and a description of what's going wrong" part but you forgot about the "post the code you have". No, that's milliseconds. Probably to do with timezones.
  3. So if you go into a MySQL client program (like phpMyAdmin) and execute SELECT * FROM reactions WHERE topic_id = 1then you only get three rows? Dump out or log the value of $row2 somewhere. If it shows three rows then you're looking in the wrong place, and if it shows more than three rows then Doctrine is doing something spooky.
  4. Should be pretty straightforward: take the lines that deal with hours/minutes/seconds, create a duplicate fourth line for the hours, and make sure you get the math right. Example 1: <span class="hour">00</span> <span class="min">00</span> <span class="sec">00</span>becomes <span class="day">00</span> <span class="hour">00</span> <span class="min">00</span> <span class="sec">00</span>Example 2: var hoursContainer = $(container).find('.hour'); var minsContainer = $(container).find('.min'); var secsContainer = $(container).find('.sec');becomes var daysContainer = $(container).find('.day'); var hoursContainer = $(container).find('.hour'); var minsContainer = $(container).find('.min'); var secsContainer = $(container).find('.sec');Go ahead and give it a shot. If you have problem, post the code you have and a description of what's going wrong.
  5. Opinion? You should have upgraded YEARS ago. Because 5.2 stopped being supported YEARS ago. No updates since then. Not even security updates. Who knows how vulnerable the application is! It will take time and lots of testing but it needs to happen: upgrade to PHP 5.6. There are migration guides available to help with the process.
  6. You also need to be putting $new_recipient back into the array, not the original $recipient. Another thing. Keep in mind that strpos() can return 0 if the string starts with a @. And 0 == false. So you'd get something like "@[email protected]". The alternative is "@foo" (looks like an email so don't change it), which isn't good either but it would probably be better to keep that. So use === false for an exact comparison.
  7. So you've got $new_recipients. explode() that into a new variable. It'll be an array, so you can foreach over it to get the various bits inside. foreach ($exploded_new_recipients as $key => $recipient) {Each $recipient bit will be an email address or name. If you exploded on just a comma (which I suggest) then there could be some spaces too that need to be trimmed off. Once you have the "plain" value, you need to tell if it's a name or email. The easy way to check is to see if there's an @ sign, given that the user should really only be entering names or email addresses. (You could really scrutinize them if you wanted to, though.) For email addresses you'd just leave them alone. For names you'll want to modify them to be email addresses instead: update $recipient with the new value (replace spaces and add "@xyz.com), then update the original array too with $exploded_new_recipients[$key] = $recipient;(Because updating $recipient won't also automatically update $exploded_new_recipients.) After all that, the array should be just email addresses. implode() it back together (using comma+space this time, for a more nicely formatted list) and you're back to a single string of everything.
  8. 1. explode() on commas and foreach 2. Trim extra whitespace 3. If the thing isn't an email then replace space->period and add "@xyz.com" 4. implode() back together into a string
  9. You're suffering from PHP's loose typing. ^ is not a logical operator but a bitwise operator. It acts on numbers. true^true is interpreted as 1^1. The answer is, of course, 0.However ! is a logical operator. !true is false, but PHP decided that the string representation (ie, what you get when you try to echo it) is empty. Try echo "1 and 1 = "; echo (1 && 1 ? "1" : "0"); echo "<br>1 or 1 = "; echo (1 || 1 ? "1" : "0"); echo "<br> 1 xor 1 = "; echo (1 ^ 1 ? "1" : "0"); echo "<br>Not 1 = "; echo (!1 ? "1" : "0");or function showvalue($expr) { echo $expr ? "1" : "0"; } echo "1 and 1 = "; showvalue(1 && 1); echo "<br>1 or 1 = "; showvalue(1 || 1); echo "<br> 1 xor 1 = "; showvalue(1 ^ 1); echo "<br>Not 1 = "; showvalue(!1);You should also (re)acquaint yourself with PHP's various operators. I suggest you stick with the bitwise operators only, meaning use & and | instead of && and ||.
  10. Yeah, there's more to it than just the nameservers. Say you have a question about your website. You go to Google and search for "where can I find my website?" Google does not tell you what the answer is, but rather it tells you where to find the answers. You still have to look at the search results. You try the first one, and you get the answer you need. Great. But maybe it doesn't have it. If not then you go to the second result. And third. Until you find your answer or run out of results and give up. Google is the domain registration. You asked it about your website and it told you where to look next. Google's search results are the list of nameservers. You try each one until you get the answer you need. All you did was tell Google what search results to show for the question. You still have to make sure that each search result has the right information.
  11. You updated the domain registration to use the new nameserver, great. But did you update the nameservers themselves with the information for the domain? Do the nameservers have that configuration? Because it's not magic: you have to actually tell them the DNS records for the "thepizzacompany.co.uk" and "www.thepizzacompany.co.uk" and so on. Or alternatively, did you do a zone transfer from the old nameservers to the new ones?
  12. If I run nslookup on Windows I get ------------ Server: www.newcastlesedationclinic.co.uk Address: 88.208.228.254 ------------ SendRequest(), len 39 HEADER: opcode = QUERY, id = 2, rcode = NOERROR header flags: query, want recursion questions = 1, answers = 0, authority records = 0, additional = 0 QUESTIONS: thepizzacompany.co.uk, type = ANY, class = IN ------------ ------------ Got answer (39 bytes): HEADER: opcode = QUERY, id = 2, rcode = REFUSED header flags: response, want recursion questions = 1, answers = 0, authority records = 0, additional = 0 QUESTIONS: thepizzacompany.co.uk, type = ANY, class = IN ------------ *** www.newcastlesedationclinic.co.uk can't find thepizzacompany.co.uk.: Query refusedCompare that to the output for that working site. ------------ Server: azzuriuk.com Address: 88.208.228.254 ------------ SendRequest(), len 36 HEADER: opcode = QUERY, id = 2, rcode = NOERROR header flags: query, want recursion questions = 1, answers = 0, authority records = 0, additional = 0 QUESTIONS: justgeordies.co.uk, type = ANY, class = IN ------------ ------------ Got answer (242 bytes): HEADER: opcode = QUERY, id = 2, rcode = NOERROR header flags: response, auth. answer, want recursion questions = 1, answers = 6, authority records = 0, additional = 3 QUESTIONS: justgeordies.co.uk, type = ANY, class = IN ANSWERS: -> justgeordies.co.uk type = MX, class = IN, dlen = 9 MX preference = 10, mail exchanger = mail.justgeordies.co.uk ttl = 86400 (1 day) -> justgeordies.co.uk type = TXT, class = IN, dlen = 19 text = "v=spf1 +a +mx -all" ttl = 86400 (1 day) -> justgeordies.co.uk type = SOA, class = IN, dlen = 46 ttl = 86400 (1 day) primary name server = ns1.prophettech.co.uk responsible mail addr = admin.prophettech.co.uk serial = 1418996338 refresh = 10800 (3 hours) retry = 3600 (1 hour) expire = 604800 (7 days) default TTL = 10800 (3 hours) -> justgeordies.co.uk type = NS, class = IN, dlen = 2 nameserver = ns1.prophettech.co.uk ttl = 86400 (1 day) -> justgeordies.co.uk type = NS, class = IN, dlen = 6 nameserver = ns2.prophettech.co.uk ttl = 86400 (1 day) -> justgeordies.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.228.254 ttl = 86400 (1 day) ADDITIONAL RECORDS: -> mail.justgeordies.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.228.254 ttl = 86400 (1 day) -> ns1.prophettech.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.228.254 ttl = 86400 (1 day) -> ns2.prophettech.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.230.230 ttl = 86400 (1 day) ------------ justgeordies.co.uk type = MX, class = IN, dlen = 9 MX preference = 10, mail exchanger = mail.justgeordies.co.uk ttl = 86400 (1 day) justgeordies.co.uk type = TXT, class = IN, dlen = 19 text = "v=spf1 +a +mx -all" ttl = 86400 (1 day) justgeordies.co.uk type = SOA, class = IN, dlen = 46 ttl = 86400 (1 day) primary name server = ns1.prophettech.co.uk responsible mail addr = admin.prophettech.co.uk serial = 1418996338 refresh = 10800 (3 hours) retry = 3600 (1 hour) expire = 604800 (7 days) default TTL = 10800 (3 hours) justgeordies.co.uk type = NS, class = IN, dlen = 2 nameserver = ns1.prophettech.co.uk ttl = 86400 (1 day) justgeordies.co.uk type = NS, class = IN, dlen = 6 nameserver = ns2.prophettech.co.uk ttl = 86400 (1 day) justgeordies.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.228.254 ttl = 86400 (1 day) mail.justgeordies.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.228.254 ttl = 86400 (1 day) ns1.prophettech.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.228.254 ttl = 86400 (1 day) ns2.prophettech.co.uk type = A, class = IN, dlen = 4 internet address = 88.208.230.230 ttl = 86400 (1 day)So, are you sure the nameservers are configured to serve that domain?
  13. ns[12].prophettech.co.uk? They're refusing DNS queries...
  14. x+y is "#inputList2". A string. [x+y] is ["#inputList2"]. An array. I don't know where you're getting those []s from but get rid of them.
  15. Just use a normal, plain, simple function. Like in your first example. OOP is about object entities, not about using classes for everything. The reason it doesn't work is because the "Log" that you are use-ing in Main.php does not apply to functions.php too. It's a per-file thing. So //functions.php use Company\Project\Handlers\Log; function __log_notice(string $text) { Log::notice(0, $text, true); }or //functions.php function __log_notice(string $text) { Company\Project\Handlers\Log::notice(0, $text, true); }
  16. Are you the owner of the account? Do you know what I did with the account? I made a quick post to let other mods/admins know the OP's request had been addressed. It's not like I can contact the person or they can reply to threads... Not being able to delete one's own account is normal. I know of, like, two websites which let you do that. Or at least claim that you're doing that - I would be surprised how many of them actually remove account data from their systems. Because record-keeping is actually very important. Re: flippant. Yeah, I see that. I tend to react to rude comments and snideness similarly. I've also not been in a good mood lately because of, you know, this whole shitstorm. Re: you don't remember signing up. It's only been 2.5 years and you have more than a dozen posts across three threads spanning half a month. But whatever. Do you want your account suspended too? If you were using your real name or a personal email address then I would have offered to sanitize it along the way (no offense if that is, in fact, your first name, which would be kinda cool).
  17. 30 days of elapsed time or 30 days on the calendar? There is a difference. Are you using times with the dates too? And most importantly, what code do you have written so far and what kind of problems are you having with it? That is no excuse. I'm a fan of those functions too, but there are some things DateTime can do better. Depends how you store the date. The only two good options are as a DATE/TIME/DATETIME or as a Unix timestamp (which would use an INT or larger). For the former you just create a string in the "YYYY-MM-DD HH:MM:SS" format (eg, Y-m-d H:i:s), for the latter you keep the integer values that functions like time() and mktime() and strtotime() return.
  18. Really? You can't remember to type mywebsite.com so you're looking for a technological solution? How about a bookmark? Takes seconds to make one and you, who has a problem typing things, can instead click things instead. The hosts file is what you're thinking of, but it alone won't be enough. All it does is tell your browser which server a website lives at. It doesn't do redirects. Odds are you will have to configure the server that hosts mywebsite.com to be able to handle "my.ebay.com", and then have it issue the redirect. Because there is no way to have a client-side redirect before you've even gone anywhere - unless you make an add-on or extension for your browser.
  19. For all the files, you'll need another loop: use glob to get the list of files you want, foreach over it as $source, and then put that code you have to load a file into it. Dealing with un-namespaced XML elements (like ) is easy: do what you're doing now. Dealing with namespaced elements (like ) takes a bit more work. To do something like ->video:title, which you can't do for a couple different reasons, you need to use ::children. const XMLNS_VIDEO = "http://www.google.com/schemas/sitemap-video/1.0"; // <urlset xmlns:video="..."> echo $url->children(XMLNS_VIDEO)->video->title;Explanation? When you do ->video, SimpleXML will try to find a and won't find it. When you use children() first, SimpleXML will look for the namespace using that URI (an xmlns:video), figure out what XML namespace prefix to use ("video:"), and then begin looking for elements in that namespace. $url->video->title // <title> inside <video> inside $url $url->video->children(XMLNS_VIDEO)->title // <video:title> inside <video> inside $url $url->children(XMLNS_VIDEO)->video->title // <video:title> inside <video:video> inside $url
  20. Have you tried SimpleXML yet? Written any code so far?
  21. First, use an array for the decoded JSON. Having to use that {""} syntax is unfortunate and awkward. $zooelements = json_decode($elements, true); $name = $zooelements["0ad767cantbebotheredtocopypaste"][0]["value"];Second, are you actually using a @ when you call mysql_query? That will hide any errors that may happen. Hiding errors is very bad. Don't use @. Is your question about how to update $zooelements? Surely the answer is just $zooelements["0adblahblahblah"][0]["value"] = "NameEFGH";
  22. How can you make the checkbox be checked for the user? Put a "checked" in the HTML if you want it checked. There's something funky happening with your code in that form, so I'm going to go out on a limb and fix it. />The value doesn't really matter, and instead it uses the value in $result to show the "checked" or not.
  23. "Get function"? And for two, your form is using POST and not GET. Those textboxes and checkboxes have names, right? Like "water-purveyor" and "v1-na". So those will be in $_POST - though checkboxes only if the user checked them, so you need isset() for those. $water_purveyor = $_POST["water-purveyor"]; $v1_na = (isset($_POST["v1-na"]) ? $_POST["v1-na"] : /* default value? */ null);
  24. That code? You're throwing an exception only to catch it on the next line. That's pointless. You might as well just public function indexAction(Request $request) { if(!is_object($request)) { $this->logger = $this->get('logger'); $this->logger->info("You have the following error: { $error }", array("error" => "Param must be an object")); } }By the way, inconsistent indentation drives me crazy. I'm trying not to go into a treatise about how exceptions are supposed to work (too much to say that has been said elsewhere on the internet), with mixed success, but basically you use them if there is something unexpected that happens and your code is not able or supposed to handle it. Look around to see what people say about how to use exceptions - even if it applies to other languages (notably Java and C#). First of all, in your situation $request is going to be an object because you used the typehint. Not that it will prevent someone from calling the method with a non-Request or non-object, but if they did then there will be an error about it and your logger will see that (assuming your logger is set up for PHP errors, which it should be). If you still want exceptions here then I'd use something more like public function indexAction(Request $request) { if (!($request instanceof Request)) { throw new InvalidArgumentException('$request must be a Request object'); }The main point here is that indexAction cannot recover from this problem. There is nothing it can do. The Exception "forces" someone in the call stack to handle an InvalidArgumentException - or worst case nobody does and PHP fatals. Also note the InvalidArgumentException instead of just Exception. Pretty much every sort of exception you'd want to throw really, really needs to be a subclass. Throwing Exception everywhere severely limits what you can do when catching them: (a) You would have to resort to crazy hacks to figure out what kind of problem it represents, but more critically (b) You'll catch and handle types of circumstances your code isn't prepared for. If you set up a try/catch because you know that (eg) the function you're calling can error because a file doesn't exist, you'll get that, but you'll get every other exception too. And if you discard the exception because the missing file isn't a big problem, you're now discarding every exception. The InvalidArgumentException class specifically indicates that there was a problem with an argument to a function. I don't ever catch this class[1] because it represents a fundamental problem with the code itself - not merely some sort of unexpected situation or unusual circumstance. Continuing that train of thought, only catch the exceptions you want to handle. If something can throw an exception but your code doesn't know what to do in that case, don't catch it there. Instead, go backwards up the call stack until you find a place where it makes sense. Common example: set up a try/catch just before you try to "execute" the code for a particular page on your site, then in case of an exception you can (log it and) show an error message to the user. So public function indexAction(Request $request) { // do whatever public static function /* Controller:: */ invokeAction($controllerClass, $action) { $controller = new $controllerClass(); $method = $action . "Action"; $request = Request::current(); // no try/catch because there isn't any type of exception this method is prepared to handle $controller->$method($request); } try { Controller::invokeAction($controllerClass, $action); } // one type of exception that you want to use special handling for catch (SomeParticularTypeOfException1 $e1) { // ... } // another type of exception with special handling catch (SomeOtherTypeOfException2 $e2) { // ... } // catch every other exception so we can present an error message to the user catch (Exception $e) { ErrorController::showErrorPage(500, $e); // public static function showErrorPage($code, Exception $error = null) }[1] Unless I'm working with a system that must not fail[2], I do this. Which is to say I have a logger set up for uncaught Exceptions, log their presence, then let PHP die.[2] Well, that or there's a chokepoint in the code where I want to wrap any exceptions caught inside another exception. In which case I use the "$previous" parameter to Exception, like try { callSomeFunction(); } catch (Exception $e) { throw new BadMethodCallException("callSomeFunction failed: " . $e->getMessage(), 0, $e); }Side note: make sure your logger can handle nested exceptions.
  25. Variables defined outside of functions are not available inside of functions. Pass what you need as arguments, like function output($connection, $sql) {
×
×
  • 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.