Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. 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'  
  2. 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'  
  3. 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.
  4. 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.
  5. 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.
  6. kicken's post in PHP curl GET request with Parameters was marked as the answer   
    Yes.  CURLOPT_POSTFIELDS is only for doing POST requests.  For GET you just include the parameters in the URL's query string.  You do that by adding a ? followed by the parameters in name=value&name=value2 format with proper url encoding applied.
    PHP has a function to build the appropriate string from an array of parameters: http_build_query.  Use that and concatenate the result to the URL.
  7. kicken's post in Filling Undefined values in an array with a null value was marked as the answer   
    You can simply use the null coalescing operator when reading the values from your array to remove the warning.
    $num = $leaddata[$status][$title] ?? null; $contacts = $leaddatastatus[$status][$title][$sub_status] ?? null;  
  8. kicken's post in Method call working in one place but not the other was marked as the answer   
    Yes.  You're loading your existing comments in the constructor of the Comments class, so all your data gets loaded here:
    $comment = new Comment(Input::get("post_id")); The data you load at that point is what you'll end up displaying later on when you call display() and count().  Whether or not $message is true isn't really relevant to how this functions.
    That's wrong from a syntax perspective.  If that's what you have, you should be getting a syntax error I would think.  You don't use <?php ?> tags to embed variables into strings.  You use concatenation and/or interpolation.
    Redirect::to("single_post.php?post_id=$post_id&related=$related"); With the syntax fixed, replace your $message = true; line with the redirect.  You'll need to use an alternate means of determining whether or not to show your message, such as by adding a message=true parameter to the URL or storing something in the session.
    This is possibly related to the bad syntax of the redirect.  Notice in the stack trace it shows the php tags as part of the parameters:
    Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /opt/lampp/htdocs/qcic/assets/class/DB.php:35 Stack trace: #0 /opt/lampp/htdocs/qcic/assets/class/DB.php(35): PDOStatement->execute() #1 /opt/lampp/htdocs/qcic/assets/class/DB.php(121): DB->query('UPDATE posts SE...', Array) #2 /opt/lampp/htdocs/qcic/assets/class/Post.php(227): DB->update('posts', '<?php echo 86; ...', Array) ------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^ #3 /opt/lampp/htdocs/qcic/newsnet/single_post.php(16): Post->viewCount('<?php echo 86; ...') ---------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^ #4 {main} thrown in /opt/lampp/htdocs/qcic/assets/class/DB.php on line 35  
  9. kicken's post in COALESCE not working in CodeIgniter was marked as the answer   
    You need your join on the second table to be a LEFT JOIN, but right now you're just making it a regular (INNER) JOIN.  An inner join excludes the row from the result if no match is found in the second table.  A left join will include the row, but with all the fields from the second table set to NULL.
    I don't know code igniter, but a simple search for code igniter left join suggests you want to write your join as:
    $this->db->join('crm_clients_users c','t.agent_id = c.id', 'left');  
  10. kicken's post in Add event to an element created with javascript was marked as the answer   
    You need to use a delegated event which involves
    Adding the event to some parent element that will always exist and Adding a selector argument when calling the .on method. $('#tableDiv').on('click', '#edit', function(){ alert('Hi!'); });  
  11. kicken's post in include the script only once was marked as the answer   
    Make it a named function, then pass the name to your event handlers.
    function loadData() { $.ajax({ type: 'POST', url: 'returnPDO.php', dataType: "json", data: { id: "1", rows: "7" }, success: function (data) { ...CODE.... } }); } $("#searchTbl").keypress(loadData); $('#go').on('click', loadData);  
  12. kicken's post in fill array with " " to avoid "undefined index" errors? was marked as the answer   
    Ah, but have you tried array_fill_keys?  See also, this post: Notice: Undefined index: driving me insane.
  13. kicken's post in Block direct access to files but use them was marked as the answer   
    Some places will try and do that by checking the referrer and denying access if it doesn't exist or match the right domain.  It's not going to stop anyone with even the slightest determination from downloading your file though.   IMO, it's not worth the effort to even try and do something like that.  
    Basic rule of the web is if the browser needs access to the file, then by necessity the user can also download a copy of that file.
  14. kicken's post in echo an array inside form confirmation email was marked as the answer   
    Use a foreach loop above the $body and create a new variable containing the order details as a string, then use that variable in $body.
    $orderDetails = ''; foreach ($orders as $order){ $orderDetails .= $order . '\n'; } It seems your orders are JSON encoded, so you'll probably want to json_decode them and format them nicely within that foreach loop.
  15. kicken's post in Javascript postMessage(msg) with Instance Of Class w/Methods was marked as the answer   
    postMessage serializes the data that you want to send.  That means that for the most part, only simple data is able to be sent, not complex stuff like functions or objects with methods.
    What you need to do is define MyClass on both pages and give it a way to be serialized to a string or simple object on the sending page and then unserialized back into the full object of the receiving page.
  16. kicken's post in results are sorted by directory name and not date was marked as the answer   
    Use usort rather than sort, then you can provide a comparison function and implement whatever logic you need to get the correct sorting.  The comparison function will be given two items from the array ($a and $b) and must return a number that indicates if $a is less than $b (-1), they are equal (0), or $a is greater than $b (1).
    If your files all began with the date in Y-m-d format you'd be able to simply compare them.  In m-d-Y format though you need to parse the date out of the name and then compare the date.
    usort($files, function($a, $b){ $a = basename($a); $b = basename($b); $aDate = DateTime::createFromFormat('!m-d-Y+', $a); $bDate = DateTime::createFromFormat('!m-d-Y+', $b); if ($aDate && $bDate){ $comparison = $aDate <=> $bDate; if ($comparison === 0){ return $a <=> $b; } else { return $comparison; } } else { return $a <=> $b; } }); Here, the function reduces each path given to it's basename, then attempts to parse a date in m-d-Y format from the beginning of the filename.  If it's able to successfully parse a date from both filenames then it compares the dates to get that -1, 0, or 1 value indicating their order.  If the result is 0, meaning the dates are equal, it compares the entire string and returns that order.  If it's unable to parse a date from either of the filenames then it just returns an order based on a string comparison.
  17. kicken's post in CORS and Sandboxing User Javascript, and Cookies was marked as the answer   
    I downloaded your code and added that attribute and it seemed to be working fine after that.
    You need to add it to both the CSP and the iframe's sandbox attribute.
  18. kicken's post in Errors that make no sense to me. What am I doing wrong? was marked as the answer   
    A query can have more than one parameter (eg, multiple WHERE conditions), as such PDO::execute() needs to be able to accept more than one value to bind to those parameters.  The way it does that is by taking in an array of values (even if it only needs one).  Pass an array to execute with $site as an element of that array to fix that problem.
    $stmt->execute([$site]); Your foreach error is due to the variable you provide ($table) not being an array (or other Traversable object).  You don't actually define $table anywhere in your code, it just magically appears.  If you want to loop over the results of your query, then you have a couple options.
    PDO Statements can be used directly in foreach, so just loop over $stmt.  If you do this, you do not call $stmt->fetchAll() first. Grab the results using $stmt->fetchAll() and loop over that variable ($fcid in your code).  
  19. kicken's post in Does a class's constructor run when I call a static method from outside the class? was marked as the answer   
    No.  Constructors only run when you're creating an instance of an object using new.
    Static methods are not associated with an instance so there's no need to run a constructor.  You also cannot use $this or any non-static class properties or methods
  20. kicken's post in Various Issues with backslashes and replacing strings was marked as the answer   
    This is just a matter of two separate levels of escape sequence processing that you need to wrap your mind around, which can be difficult at times.
    When you're setting a string in PHP first you have PHP's escape sequence processing.  PCRE then has it's own level of processing that is done on the value that was passed to the function.  For example, if you wanted to use \0 in a replacement literally rather than have it interpreted as a back reference you have to pass the string '\\0' as your replacement.    If you're defining value in your PHP source as a string then you need to escape those slashes again for PHP's sake so you have $replacement = "\\\\0"
    If you get the value from a file or database you don't have to worry about the PHP level of escaping, but do still need to account for the PCRE level so you need your file to contain \\0 not just \0.
    It's not clear to me exactly what output you're expecting in your code sample.  The addslashes call effectively mitigates PHP's escaping meaning $replacement is set to the literal value "<pre>\\\\</pre>".  preg_replace will then see that and process it's own escaping which means the value it's working with is effectively "<pre>\\</pre>".  That means your final replaced output would be "<div><pre>\\</pre></div>"
    If you have "<pre>\\\\</pre>" stored in your database and are pulling that value from there then you should get the same result, just don't run it through addslashes() as you don't have to deal with the PHP level of escaping things.
  21. kicken's post in syntax error detection was marked as the answer   
    Your host probably re-configured things when it upgrade PHP. In the past many shared hosting providers I used would have things configured with display_errors=On but that's not an ideal configuration for a production server as it exposes too much. Your host was probably setup like that previously and when they upgraded finally changed it to the better display_errors=Off with logging setup instead.
    The old configuration would let you see the parse errors because of the PHP configuration, not your script specific settings. The new configuration doesn't show the errors, and your script can't override that if it can't be parsed.
    So your options now are
    Re-configure PHP to show errors again or Start checking the error log file when you get a blank screen or Re-work your application to use a main front-end file that sets your error reporting then require's the rest of your code.
  22. kicken's post in Can you see anything dodgy in this code? was marked as the answer   
    It sounds like you have your referrer id value coming in from potentially different sources. What you need to do is decide on the priority of those sources and then check for a value in that order.

    $referrerId = $default_referrer; if (isset($_GET['id'])){ $referrerId = $_GET['id']; } else if (isset($_COOKIE['referrer'])){ $referrerId = $_COOKIE['referrer']; } That will assign $referrerId the value from $_GET['id'] if it exists, otherwise $_COOKIE['referrer'] if it exists, and if neither of those exist fall back to $default_referrer. 
    After that, you know your referrer so you just do whatever you need to do with it.

    //Set the cookie for future page loads. $duration = 60 * 60 * 24 * 365; setcookie('referrer', $referrerId, time() + $duration); //Grab the user's details $userInfo = get_userdata($referrerId); //Do whatever with $userInfo
  23. kicken's post in is this the best way to access a multi array was marked as the answer   
    I'd guess something like this would work for you.

    foreach ($image as $img){ $imageID = wp_get_attachment_image($img['image'], 'full'); echo $imageID; } In your original code you would run wp_get_attachment_image twice, once for the [image] key and once for the [image_fallback] key which is probably not what you intended to do. If you only want the [image] key then just access it directly.
  24. kicken's post in Unexpectet String causes me cancer was marked as the answer   
    You need commas separating your fields in your app definition.

    var app = { shipping : 5.00, products : [ { "name" : "2.4GHz GPS WIFI Drone", "price" : "164.99", "img" : "IMG/COV/SHOP/IMG/REG/2017.10.2815.17.5925474Drone_SML.PNG", "desc" : "Flugzeit: 12 - 15 Minuten Ladezeit: 3- 4h", "pid" : "38", "qua" : "1" } //... However, the better way to do something like that is to use json_encode
    <?php $cart = []; if (isset($_SESSION['cart'])) { foreach ($_SESSION['cart'] as $row) { if ($row > 0){ $cur_pro_on_car = $Shop->product_get($row); $quantity = 1; if (in_array($cur_pro_on_car['PID'], array_keys($_SESSION['quant']))) { $quantity = $crud->word($_SESSION['quant'][$cur_pro_on_car['PID']], 'UTF-8'); } $cart[] = [ 'name' => $crud->word($cur_pro_on_car['prdname'], 'UTF-8') , 'price' => $crud->word($cur_pro_on_car['price'] / 100, 'UTF-8') , 'img' => $crud->word($cur_pro_on_car['prdpicsml'], 'UTF-8') , 'desc' => $crud->word($cur_pro_on_car['detailsstr'], 'UTF-8') , 'pid' => $crud->word($cur_pro_on_car['PID'], 'UTF-8') , 'qua' => $quantity ]; } } } ?> var app = { shipping : 5.00, products : <?php echo htmlspecialchars(json_encode($cart)); ?>, //... };
  25. kicken's post in decbin() - Is there an upper limit? was marked as the answer   
    decbin's range depends on whether you are on a 32-bit php version or a 64-bit php version. Your input is fine for both, but converting that binary value back to decimal is the problem.
    decbin(3584) = "111000000000"
    (int)"111000000000" = 111,000,000,000
    On a 32-bit system that decimal value is too high so you end up with 2,147,483,647 (the maximum value for an integer) when doing % 10.
    Dividing by 100 gets you low enough to fit within the 32-bit range so you stop having issues at that point.
    What sort of problem are you actually trying to solve? It looks like you want to test if certain bits are set in a number. If that is the case, then you want to be using the bitwise operators, not decbin.

    function teams($number){ if($number & 0x01) {echo " <font color=green>ARENA</font> ";} //1 if($number & 0x02) {echo " <font color=maroon>FLEET</font> ";} //2 if($number & 0x04) {echo " <font color=yellow>FLEET RESERVE</font>";} //4 if($number & 0x08) {echo " <font color=gold>FLEET COMMANDER</font>";} //8 if($number & 0x10) {echo " <font color=fuchsia>RANCOR</font> ";} //16 if($number & 0x20) {echo " <font color=darkblue>AAT</font> ";} //32 if($number & 0x40) {echo " <font color=tomato>SITH</font> ";} //64 if($number & 0x80) {echo " <font color=blue>LSTB(1)</font> ";} //128 if($number & 0x0100) {echo " <font color=blue>LSTB(2)</font> ";} //256 if($number & 0x0200) {echo " <font color=blue>LSTB(3)</font> ";} //512 if($number & 0x0400) {echo " <font color=blue>LSTB(4)</font> ";} //1024 if($number & 0x0800) {echo " <font color=blue>LSTB(5)</font> ";} //2048 if($number & 0x1000) {echo " <font color=blue>LSTB(6)</font> ";} //4096 }
  • 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.