Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Community Answers

  1. kicken's post in Update the code to PHP 8.2: conditionally displaying a notice about free shipping in Woocommerce was marked as the answer   
    No, you do not merge the else into the previous set of if statements.  You replace the second set of if statements with only what was in the else branch.  Like this.
    function next_day_delivery() { if( WC()->cart->is_empty() ) return; // Exit $cart_subtotal = WC()->cart->subtotal; $limit_free = 150; // Starting freee shipping amount $free_shipping = ''; // Initialising if ( $cart_subtotal < $limit_free ) { $free_shipping = sprintf( __('%s Add %s worth of goods to your order to get %s', 'woocommerce' ), '', // ' <img src="' . get_stylesheet_directory_uri() . '/images/shipping-icon.png"> ', strip_tags( wc_price( round( $limit_free - $cart_subtotal, 2 ) ) ), '<strong>' . __( 'FREE SHIPPING!', 'woocommerce' ) . '</strong>' ); } elseif ( $cart_subtotal >= $limit_free ) { $free_shipping = '<strong>' . __( ' You get FREE SHIPPING!', 'woocommerce' ) . '</strong>'; } $message = __( '', 'woocommerce' ) . $free_shipping; wc_print_notice( $message, 'success' ); }  
  2. kicken's post in Credentials Security was marked as the answer   
    Try browsing directly to your .env file on your website, for example http://example.com/.env and see if the file contents comes up.  If it does, then that's your problem.
    Ideally you'd store your .env file outside of your webroot so it's inaccessible via any URL.  If you're hosting provider does not allow for that, then you need to configure the webserver to not allow access to your .env file via .htaccess or some similar mechanism.  If you can't do that, then the next best option is to store the credentials as PHP code in a .php file so even if someone does try and load the URL they won't see the PHP code.
     
  3. kicken's post in Can Anyone Solve This? was marked as the answer   
    Look at the documentation for mysqli_stmt_prepare.  Notice it says the function only accepts one parameter which is the connection.
    Now look at your code and notice that you are passing two parameters, the connection and the SQL string.  You need to remove the extra parameter.
     
  4. kicken's post in How do you hide multiple DIVs when hovering over one? was marked as the answer   
    Yes, really.
  5. kicken's post in Why do display:inline for radio and checkbox label only when already each label is set to inline-block? was marked as the answer   
    As you noted,
    Adding display: inline prevents the width: 25% from having an effect on those elements.
  6. kicken's post in how to update a users collumn based on the time returned by a countdown. was marked as the answer   
    You shouldn't be trying to save a "time remaining" value at all.  That's a value you'd want to calculate on the fly when you need it based on the current time.
    Either save the sub_date and the amount of time they are allowed, or save an expiration date for the subscription and calculate the difference between now and that expiration date to determine the time remaining.
     
  7. kicken's post in how do I set curl POST method with PHP? was marked as the answer   
    Probably you should talk to the company hosting the API as it seems your request is going through fine so if there's a problem it's likely with the data you are sending not being what they expect.  They are the only ones that can really tell you for sure if there is a problem with the data.
     
    If I had to take a guess, it would be that you seem to be trying to post multiple records when they probably only expect one.  If you decide you're query string, you'll see you are posting data like this:
    0[id]=6653&0[participacion]=6936&0[beneficio]=cine&0[fecha]=2018-04-16+14:41:59&0[promo]=33&1[id]=6654&1[participacion]=3318&1[beneficio]=payp That seems unusual to me.  What would seem more likely is that you'd send one at a time with data such as this:
    id=6653&participacion=6936&beneficio=cine&fecha=2018-04-16+14:41:59&promo=33  
  8. kicken's post in SUM not working in Codeigniter was marked as the answer   
    Because you're asking for the number of rows, not the actual data.
     
     
    You want to fetch the row data and use that.  Some searching suggests that you'd do that using this code:
    return $query->row()->total_paid_amount Also, if you're trying to get a sum of all payments, you probably don't want to be using GROUP BY, and should remove p_id from your select list.
     
  9. kicken's post in Making Composer provide untagged git file was marked as the answer   
    You can tell composer to pull a specific commit by adding #hash after version.
    "api-platform/core": "3.0.x-dev#14c7cba" Normally just doing 3.0.x-dev would pull the latest version, but I think because both the main branch and 3.0 branch use this alias it causes an issue and for some reason composer prefers the main branch.
  10. kicken's post in Avoid multi directory structure for userbase was marked as the answer   
    It sounds like what you're describing / debating is a how to create a multi-tenant application, is that right?  Essentially you have an application that is dynamically configured and has separate data for each user instance (ie, several different wordpress blogs sharing the same code base).  I'm not sure I see the need for such complexity based on what is mentioned.
    That just sounds like basic user management / access to me.  You have your users table and a files table and associate the files with their users.  How you physically store the files on disk isn't really that relevant. Just ensure you code your editor so it can only load files the user has access to.
    Is there some public aspect to this where you need to isolate the user's files based on just the URL and not the user being logged in?  Last time I did something like this, it was based on the host name, but a URL directory would work as well.  Using the host name could have allowed the end-users to apply their own domain name to application instead of having to use mine (though that was never actually done).
     
    Based on the info provided so far, I'd probably just be doing essentially what I think you're already considering, just without the creation of separate folders for users bit.  I'd just store all the files for all users in one directory structure somewhere with random names.  The database would contain the original file name/mime type and user association information.  I'd use either mod_rewrite or FallbackResource in apache to handle public access to the files and normal login procedure for the editing/uploading bits.
  11. kicken's post in Why didn't position:sticky work? was marked as the answer   
    Seems like it's working fine for me.  However, you should not be using tables for layout.
  12. kicken's post in Did PHPFreaks get hacked? was marked as the answer   
    There was an incident a few years back.  You can read about it here.
  13. kicken's post in What is wrong in my code - wrong strokeStyle applied? was marked as the answer   
    You need to use beginPath() before you start to draw something.  Add a call to beginPath after you save the context.
  14. kicken's post in Best way to get an array slice starting from 'current' was marked as the answer   
    Just looking for a name element and then taking the next N elements is not really a good solution.  Unless you've previously sorted the array into a specific order, you can't guarantee the next N elements are actually the ones you want.
    If your structure is name0 matches with date0 then the thing to do would be build a new array that maps the name entries to the date entries and then you will have a simple array of date entries that you can slice off what you want.
    Even better if you can would be to rename your form elements so that PHP will essentially do that mapping for you.  Give your form elements names like name[0] and date[0][A], then you could just match the indexes between the name and date arrays.
     
  15. kicken's post in How can I pass class object to onclick function ? was marked as the answer   
    Don't use setAttribute to attach your onclick handler.  Use addEventListener.  Combine that with a closure that calls your select function and you can just pass the current object as a parameter the same as you would anything else.  Looking at your select function, I don't think it's necessary though.
     
    this.cbox.addEventListener('click', () => { this.setSelect(this.cbox.checked); });  
  16. kicken's post in How to enchance the table by displaying an alternate background color of “pink” and “white” for each table cell? was marked as the answer   
    Your code is incorrect.  You're not echoing your table cells, you storing them in a variable that is never used.  Your opening <td> tag is missing it's >.
    You cannot do an expression inside a string.  Either do it outside the string and save the result to a variable then embed the variable, or use concatenation.
    Lastly, you can do alternating colors with simple CSS and just create your table normally.
    td { background-color: white; } td:nth-child(2n){ background-color: pink; }  
  17. kicken's post in simple PDO insert sql insert form was marked as the answer   
    The parameter names in the query and the keys in your array need to match.  You've defined your parameters for the name as first_name and last_name, but in your array you used fname and lname.  Also post_code vs postcode, birthdate vs birthday.
     
  18. kicken's post in store jpg in mssql was marked as the answer   
    You need to use bindParam().  Set the type as PDO::PARAM_LOB so you can bind a file resource and stream the data (rather than as a big string), and use the $driverOptions parameter to set the data type to binary.
     
    $dbStatement = $db->prepare('INSERT INTO uploads (file_application_id, file_type, file_name, file_data) VALUES (?, ?, ?, ?);'); $dbStatement->bindValue(1, $appid['appid']); $dbStatement->bindValue(2, $attachment['type']); $dbStatement->bindValue(3, $fname); $fp = fopen('c:\\uploads\\'.$attachment['name'], 'r'); $dbStatement->bindParam(4, $fp, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); $dbStatement->execute();  
  19. kicken's post in Reverse proxy pass websocket request with PHP in apache was marked as the answer   
    As an alternative to making your own proxy server (or finding one) you might be able to simply configure Nginx to authenticate the request for you by making a sub-request to your PHP script.  I don't use Nginx so not sure if that would work but it sounds promising.
     
  20. kicken's post in Displaying only limited amount of pages in php pagination? was marked as the answer   
    You are currently looping from 1 to $number_of_pages when displaying your page numbers.
    What you want to do is loop from $page - 2 to $page + 2, taking care not to go below 0 or above $number_of_pages in the process.  Get your range of pages to loop over with some simple math and the help of the min/max functions then loop over that range. 
    $start = max(1, $page - 2); $end = min($number_of_pages, $page + 2); for ($p=$start; $p<=$end; $p++){ //... }  
  21. kicken's post in I'm getting a Forbidden error on my local server was marked as the answer   
    From PHP's include_path configuration.
    The error message you show doesn't match the code you posted.  The error shows '../php' but the code shows '../../php'.
    You need to get your path fixed, whatever you have is incorrect.  When it comes to requiring files, it's usually best to use __DIR__ and build a path from there.  For example, if your code file is /var/www/foxclone/public_html/index.php and you want to include the file /var/www/foxclone/php/PDO_Connection_Select.php, you'd do this:
    require __DIR__.'/../php/PDO_Connection_Select.php'  
  22. kicken's post in I'm getting a Forbidden error on my local server was marked as the answer   
    From PHP's include_path configuration.
    The error message you show doesn't match the code you posted.  The error shows '../php' but the code shows '../../php'.
    You need to get your path fixed, whatever you have is incorrect.  When it comes to requiring files, it's usually best to use __DIR__ and build a path from there.  For example, if your code file is /var/www/foxclone/public_html/index.php and you want to include the file /var/www/foxclone/php/PDO_Connection_Select.php, you'd do this:
    require __DIR__.'/../php/PDO_Connection_Select.php'  
  23. kicken's post in jquery-UI and NPM question was marked as the answer   
    The npm package doesn't provide a compiled single-file to use.  If you want to use it, you'd probably need to use something like webpack to compile everything into a single file for use on your site.
    Alternatively, there is a jquery-ui-dist package that contains the compiled output and you can just include it like you normally would.
  24. kicken's post in How to perform an action after some minutes was marked as the answer   
    Create a script that you can run every minute and it will check if there are any expired requests.  If there are it will do the "move on to the  next rider" stuff.
    Once that is working, create a cron job/scheduled task to execute that script every minute.
  25. kicken's post in Javascript Draw SVG with Filters to Canvas? was marked as the answer   
    Wrapping the call to drawImage in a setTimeout fixed the problem in my tests.  I'd guess you need the delay to give the browser a chance to render the image before you can draw it.
×
×
  • 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.