Jump to content

requinix

Administrators
  • Posts

    15,066
  • Joined

  • Last visited

  • Days Won

    414

Posts posted by requinix

  1. There is a way to do it as you describe, so if you want that solution for academic reasons there's that. However it uses references (PHP does not have pointers but references are close) and I try to avoid references unless I know my audience (eg, coworkers) will be comfortable working with them.

     

    For normal code I would go with either

    a) The recursive version, as posted by Barand, or

    b) A loop-based version where you construct the array backwards, as in

    array()
    array('key3' => array())
    array('key2' => array('key3' => array()))
    array('key1' => array('key2' => array('key3' => array())))
  2. I did that and the days stay at 00.

    Okay, you got the "and a description of what's going wrong" part but you forgot about the "post the code you have".

     

    As you can see, my "$timeLeft" variable == hours only.

    No, that's milliseconds.

     

    I found another counter that includes the days.  It works perfectly, except it always adds extra "6 hours" on top of my time.  Which is weird. Can't figure out why.

    Probably to do with timezones.
  3. 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.
  4. 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 "@foo@xyz.com". 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.

    • Like 1
  5. 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.

    • Like 1
  6.  

    echo true ^ true;
    echo !(true);
    

     

    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 ||.
  7. I changed the nameservers from the default 123 reg ones to the prophet tech ones in the nameserver management section for the domain in the 123 reg control panel, and nothing else. Do I need to do anything else in the DNS?

    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.

  8. 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?

  9. 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 refused
    Compare 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?
    • Like 1
  10. 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);
    }
  11. Why are you marking as solved, without even addressing his concerns?

    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).

  12. Subtract 30 days from a date

    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?

     

    This is a simple website. It doesn't use objects.

    That is no excuse.

     

    I use time() and date()

    I'm a fan of those functions too, but there are some things DateTime can do better.

     

    Also I may need to add this value into MySQL and I wouldn't know how to add a date object into the query.

    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.
  13. 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.

  14. 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
  15. 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";
  16. 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.
    • Like 1
×
×
  • 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.