Jump to content

kicken

Gurus
  • Content Count

    3,893
  • Joined

  • Last visited

  • Days Won

    112

Everything posted by kicken

  1. Some sort of version control is worth the effort to learn. Git isn't too bad, and is where most things are going these days. There's others available though you could try. I still make heavy use of Subversion and it's fairly easy to use on windows with a tool like TortoiseSVN.
  2. In general and by default https is not required to use sessions. However, your host may have set session.cookie_secure to on in their PHP configuration which would make it so that https is required.
  3. Sounds like you are doing unserialize($data, false); But what you need to do is unserialize($data, ['allowed_classes' => false]);
  4. Nope, polling the process status is what I was speaking of. With proc_open such a thing is possible where as with exec you're just stuck until the process is done. Polling for the status isn't an ideal solution, but it's a solution if that timeout command isn't available (ie, on windows). function run_with_timeout($cmd, $timeout = 30){ $handle = proc_open($cmd, [['pipe', 'r'], STDOUT, STDERR], $pipes); if (!$handle){ throw new \RuntimeException('Unable to launch process'); } fclose($pipes[0]); $start = time(); try { do { usleep(500
  5. The timeout command would be the easiest way to handle this probably. I didn't know that was a thing, good to know. If for some reason that wasn't an option, you should be able to use proc_open and proc_terminate to accomplish the same task. I don't have time ATM to try it and provide an example. If I do later I may post an example.
  6. You can run procedures using either EXEC $sql = "exec exampleProcedure :data"; $stmt = $db->prepare($sql); $stmt->bindValue(':data', $data); $stmt->execute(); or ODBC style CALL $sql = "{call exampleProcedure(:data)}"; $stmt = $db->prepare($sql); $stmt->bindValue(':data', $data); $stmt->execute(); I've done them both ways without issue. The SQLSRV driver by default runs all queries as a prepared query (even when not using ->prepare) which has the effect of isolating state between queries. For example, you can't do something like: $db->query('C
  7. Not really. Think about how much time you're spending now into trying to figure out why your destructor is not being run vs just re-factoring the code to do: $storage->detach($client); $client->cleanup(); My view on the matter is one should for the most part limit destructors to things that are good to do, but don't necessarily need to be done with specific timing/ugency. I rarely ever use a destructor in most of my code. When I do, it's usually for just cleaning up resources (file handles, curl handles, image handles, etc).
  8. Yes, the variables map to the question-mark placeholders. You need one for each question-mark. So when you need to place the same value into a query in different places you need to use multiple ? and bind the variable multiple times accordingly. $stmt2 = $con->prepare("INSERT INTO wp_terms(name, slug) VALUES (concat(?,' ',?), lower(concat(?,'-',?)) ); ^ ^ ^ ^ | | | | +----------+ | |
  9. That's quite the rant there for something that wasn't really ever brought up. Nobody is saying that you need to make your site accept whatever someone whats to throw at it. You can absolutely have your laws/rules about what you will or won't accept. The point of the advice is that you shouldn't try and manipulate someone's input to conform to your rules. Either their input is valid, or it's not. Don't try and "fix it", doing so might just cause you a whole new class of problems. There are numerous cases of people figuring how to craft input such that it would be fine before the filter, b
  10. Your query syntax is wrong. The syntax of an INSERT query is INSERT INTO table (ColumnNameA, ColumnNameB[, ...]) VALUES (ValueOfColumnA, ValueOfColumnB[, ...]) In your prepared query the question-marks represent the values you want to insert into the table. For the column name you currently have some dynamic expression which isn't right. Instead you need the names of the columns into which you want to store the name and slug values.
  11. If you want to track where someone has been on your site and what path the took, the simplest thing to do is just have some code that runs on every request which captures the current page and stores it into the current session. For example $_SESSION['history'][] = $_SERVER['REQUEST_URI']; Make sure you've started the session, either here or elsewhere. Then when you want to that information, such as in your error handler, just read the current $_SESSION['history'] value and it should contain a list of all the URLs they visited in order from oldest to newest. You might want to
  12. There's really only two conditions you need to be concerned with, thus you only need two rewrites. Both of these rewrites should send the user directly to the preferred URL so there's only one redirect. Someone requests the page via http:// Whether they used www or not here isn't relevant, you just redirect them straight to https://www. Someone requests the page via https:// (no-www) Redirect them to https://www. If you're just googling for code to drop in, you might find implementations that chain instead, ie: http://$domain -> https://$domain -> https://www.$doma
  13. This concept has to do with Canonical URLs, you should choose which URL format you want and the redirect everything else to that one format through either your code or server configuration. In simple cases the search engines may figure it out, but it's best if you control the process yourself. There are a number of resources out on the web that can show you how to redirect your requests appropriately for whatever software you're using. For example: Apache force www.
  14. There is a pre-release (5.9.0) that claims support for the 8.0 release candidate, you could try that. Otherwise you'll just have to wait or try building it yourself. I personally don't really plan on doing any PHP 8 work for a while yet.
  15. PHP is single-threaded*, so yea each tick callback is run in series and must finish before the next tick callback can be run. Using event-based processing lets you make things that seem like they can multi-task but they don't really. A promise can be used to do work as well, it doesn't have to just wait for a result. Conceptually they are something that is used to just wait for something to finish, but that doesn't mean it has to be some external process. You could create a promise that just does work within PHP, such as that emailer queue in the previous thread. That could be impl
  16. If you only need HTML and CSS I like CSS Desk. Otherwise you can just turn off the console in jsfiddle to make your footer visible.
  17. Well, this would be one of those times. You can't do simple math like $now - $last with the value returned by microtime(). You need to use microtime(true) for that. For example: <?php $last = microtime(); sleep(5); $now = microtime(); $diff = $now - $last; printf("%0.4f seconds have passed", $diff); One might expect since the script sleeps for 5 seconds to get a result like 5.xxxx seconds have passed but what you actually get is: Notice: A non well formed numeric value encountered in W:\expired.php on line 7 Call Stack: 0.0002 391984 1. {main}() W:\expired.ph
  18. Since your dealing in seconds I would suggest using time() rather than microtime(). Microtime has an unusual return value by default.
  19. Your mail server is using a self-signed certificate rather than one from a trusted CA. This is why your verification is failing. Solving this requires using stream_socket_client rather than fsockopen so you can control the verification process via a stream context. There are a couple ways to address this using the context option, from best to worst: 1) Verify against a copy of your server certificate This involves saving a copy of your server's certificate along side your script in a file, then using the cafile option to tell PHP to verify the received certificate against this saved
  20. You do basically the same steps I outlined above for using a file, except you use redis instead. You designate a specific key to hold your API call results. Before doing your API call check if that key already has a value or not. Rather than DIY it, you could use a pre-made caching solution to make things simpler. $client = new Redis(); $client->connect('127.0.0.1', 6379); $cache = new RedisCachePool($client); $ttl = 300; $key = 'apiCache'; $results = $cache->get($key); if ($results === null){ $results = doYourApiCall(); $cache->set($key, $results, $ttl); } //Do w
  21. Your browser is viewing the certificates you're receiving as invalid. There could be various causes for this. The browser should give you the details as to why it's rejecting the certificate somewhere, maybe behind an button you have to click. Some things to check Make sure your browser and os are up to date Check your system clock and make sure it's set to the correct date and time Might just be that the certificate actually isn't valid, so check the actual certificate. You'll have to post more details like which sites and what the exact error text is for further
  22. I don't think fputcsv allows you to force quotes around values. Generally speaking quotes should not be necessary except under specific circumstances. Is there any particular reason you need to have every value quoted? If you do need every value quoted, you'll have to generate the output yourself.
  23. Redis requires an external server to be running that you communicate with. If you don't already have a redis server running, the easiest thing to do would probably be to just store the cached data in a file on the server or in your database if you have one. The basic premise is the same though, you store the time along with the data when you run your API call. Before subsequent calls you check if the time since the last call has exceeded some threshold. To do this with a file you might follow these steps: Designate a particular file as your cache, store it's name in a variable.
  24. Simple typo, should be: echo '<pre>' . print_r($data, 1) . '</pre>';
×
×
  • 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.