-
Posts
15,290 -
Joined
-
Last visited
-
Days Won
436
Everything posted by requinix
-
"Verify" customers? The API endpoint is "createCustomer"... Here's the deal with Javascript: it's public. Everything is visible for someone to read. Anyone can pull up your HTML and Javascript, see the API call, and start to abuse that. I don't see a hidden input in the form for some sort of API key, but that means (a) there's supposed to be one and you haven't included it yet, or (b) the endpoint is not authenticated. Either way, it really doesn't sound to me like this is the sort of thing that should be run entirely from Javascript.
-
10 years of code doesn't stop working overnight. Something changed. Find out what and you might get your answer. Maybe it's a PHP version? Did someone apply software updates? Changed server hardware?
-
Er, I missed this before. Whose API are you trying to use?
-
When you put those Proxy commands kicken's gave you into your .htaccess, you said you got an internal server error. What do the server logs have to say about why there was an internal server error? kicken gave you the "simplest thing" that could work. Evidently their API is not a simple thing. Says who? The internet isn't some plug-and-play thing. You can't wave a magic wand and suddenly have your site start talking to another site, just like how I can't travel to Finland and suddenly be able to speak Finnish. It will take some degree of work to make this happen.
-
That's not weird. It's only the larger companies that tend to provide SDKs for developers. Most of the time all you have to work with is documentation. Sounds like you don't have mod_proxy installed. If you control the server then you'll have to install that module first. If you don't, and if your hosting provider doesn't give you a way to enable features like mod_proxy, then you might have to go with a pure PHP solution.
-
You didn't include the answer in your follow-up, so I assume it was one or both of: (a) there was something wrong with $item->ID, like maybe it should been ->id or maybe $item is an array instead of an object, or (b) the ID was being passed correctly and viewuser.php needed to use $_GET or some other input abstraction layer to get the value.
-
CORS is implemented at the place receiving the AJAX call, not the one making it. 3rdpartywebsite.com/api would have to add those headers. Proxy the request: set up an API endpoint on your site that works the same way (at least as far as you care for it to work) which sends the request to that site and returns back its response.
-
Warning: DOMXPath::evaluate(): Invalid expression
requinix replied to oach's topic in PHP Coding Help
Depends on your setup. With normal PHP yes, silencing the error keeps it suppressed. If you have a logging system set up to intercept and log errors then it depends. PHP will invoke the system's custom error logger even with @s, but in such a way that smart code will be able to recognize that happened and not log it. A naive logger will see "omg error, gotta log it". For the record. You're right in that you shouldn't do it: hiding errors doesn't make them go away, just like how stopping Covid-19 testing doesn't mean there are no more cases. -
You mean some thing you can download and install that will do everything for you? No. I suggest you start by Googling "php mqtt".
-
What's the question? Are you saying that SHOW COLUMNS is deprecated?
-
I would think the option that is easiest on the microprocessor itself would be best. That probably means MQTT. Plus apparently that gets you real-time data.
-
You can use array_rand() to pick one of them randomly.
-
That was not easy to understand. 01-10 - Incoming: 10 - Outgoing: 5; 5 taken from today's inventory (10-5=5) - Ending inventory: 01-10 (5) 02-10 - Incoming: 10 - Outgoing: 7; 5 taken from 01-10's inventory (5-5=0), 2 taken from today's inventory (10-2=8) - Ending inventory: 02-10 (8) 03-10 - Incoming: 8 - Outgoing: 21; 8 taken from 02-10's inventory (8-8=0), 8 taken from today's inventory (8-8=0), remainder 5 - Ending inventory: deficit of 5 04-10 - Incoming: 15 - Outgoing: 3; deficit 5 taken from today's inventory (15-5=10), 3 taken from today's inventory (10-3=7) - Ending inventory: 04-10 (7) 05-10 - Incoming: 10 - Outgoing: 6; 6 taken from 04-10's inventory (7-6=1) - Ending inventory: 04-10 (1), 05-10 (10) 06-10 - Incoming: 5 - Outgoing: 7; 1 taken from 04-10's inventory (1-1=0), 6 taken from 05-10's inventory (10-6=4) - Ending inventory: 05-10 (4), 06-10 (5) Now that you've posted a whole bunch of code, half of which is commented out and I assume the other half of which does not do what you want it to do, let's disregard it and try starting over from the beginning. How is all of this data being stored? What do the database tables look like? What does the data in the database tables look like?
-
Executing time consuming functions in an EventLoop
requinix replied to NotionCommotion's topic in PHP Coding Help
Yes, because the expectation was that you have "a lot" of emails to send, and instead of doing one email, yielding, then another, and yielding, and another, it runs multiple emails in series. There may not actually be a problem with doing that. Probably the only thing that would really be relevant is how frequently you have more emails to send - theoretically, the thing sending emails could be doing one at a time and something could be generating emails to send faster than the sender can keep up. Anyway, read what kicken said. -
Executing time consuming functions in an EventLoop
requinix replied to NotionCommotion's topic in PHP Coding Help
It is quite a bit simpler than having to deal with Redis queues, yeah. And unless the work needs to come from an external source, the approach I showed also allows you to add tasks over time. So you could have one "process" (whatever ReactPHP calls it) that has the emailer and doWork, and another process could just as easily add emails to it. And you can go even further than that... -
Executing time consuming functions in an EventLoop
requinix replied to NotionCommotion's topic in PHP Coding Help
In this case it's about using the generator as a coroutine. Generators can suspend execution and return to some caller, then that caller can have the generator resume. The use case here is that your doWork becomes a generator, and it yields (suspends) every email or so. When it suspends ReactPHP would have a chance to execute as it needs (ie, run through the event loop), and when it's ready it has doWork continue. Rinse and repeat until hair is sufficiently washed. https://3v4l.org/qlXCj As long as doWork is running, ReactPHP's loop will not execute. Because it's not truly asynchronous - it just looks that way. The basic problem you have is that doWork takes too long. The basic solution is to split the work according to whatever is not "too long". Since your metric is time, I suggested running work until some suitable amount of time has passed. Like one second. doWork is probably self-contained, right? It determines what work needs to be done and does it. You'd refactor that so that determining the work to be done happens before doWork, then doWork goes through that set until either too much time passes or it runs out of stuff. class DoesWork { private $work = []; public function __construct() { $this->work = ???; } public function addWork($item) { $this->work[] = $item; } public function doWork() { // exact code varies, but basically... $now = microtime(true); $end = $now + 1; while ($this->work && $now < $end) { $item = array_shift($this->work); // whatever $now = microtime(true); } } public function hasWork() { return !empty($this->work); } } // setup $worker = new DoesWork(); // inside the event loop, if ($worker->hasWork()) { $worker->doWork(); } If you look closely, you'll notice the code structure looks similar to what was in that 3v4l link... -
Executing time consuming functions in an EventLoop
requinix replied to NotionCommotion's topic in PHP Coding Help
Doesn't look like ReactPHP has something to make use of generators... Those would have been pretty much the ideal answer to this. Can't you split doWork's work up? If it needs to send a group of emails, don't try to do them all at once: have it do whatever emails it can fit within one second or something, then stop and let the event loop take over. That's the basic approach to how some sorts of cronjob-type tasks run. It's not about getting everything done at once but about doing a chunk of them every time you get "processor" time. -
Start writing code and see how it goes. If you have specific questions like how to get the IP address, then feel free to ask, but for your code you can just put in something temporary so that you can keep going. $need = [3, 7, 4, 8, 2, 9]; // todo: get from the coordinates $ip = "75.36.25.58"; // todo: get real address (and note actual addresses are not padded) /* you'll need some code in here to break apart $ip... */ $digits = [ "A" => // first (0) "B" => // second (7) "C" => // third (5) // etc ]; // returns a single letter or null if nothing function choose_single_letter($needed, $digits) { // look for $needed in $digits if (/* $needed in $digits */) { return // the digit - if there's multiple matches then pick one (randomly?) } else { // nothing return null; } } // returns an array of [single letter, "+" or "-", single letter] or null if nothing function choose_paired_letters($needed, $digits) { // addition loop for ($i = 1; $i <= $needed - 1; $i++) { if (/* $i in $digits and ($needed - $i) in digits */) { return [/* the digit for $i */, "+", /* the digit for $needed - $i */]; } } // subtraction loop for ($i = 9; $i >= $needed + 1; $i--) { if (/* $i in $digits and ($needed + $i) in digits */) { return [/* the digit for $i */, "-", /* the digit for $needed + $i */]; } } // nothing return null; } // returns an array of [single letter or number, "+" or "-", number or single letter] function choose_any($needed, $digits) { // pick random digit in $digits if (/* $needed - digit >= 1 */) { return [/* digit */, "+", /* $needed - digit */]; } else { // needed + digit <= 9 return [/* $needed + digit */, "-", /* digit */]; } } $exprs = []; foreach ($need as $needed) { // call choose_single_letter, of that fails choose_paired_letters, or if that fails choose_any $exprs[] = // result } // now $exprs is an array where each entry is a thing that represents an expression: // (a) a single letter to draw // (b/c) an array in the form [operand, operator, operand] to draw To get the result into the picture, that totally varies based on how you want to do that, but the best approach will very likely be to get the whole coordinates+expressions thing into a single string, kinda like $string = "N 35° 54. (?) (?) (?) W 84° 01. (?) (?) (?)"; (substituting each question mark for the string representation of each expression that goes in there)
-
Php PDO query issue for navigation and content from MySQL db
requinix replied to Skorpio's topic in PHP Coding Help
I can't tell: are you still trying to solve the undefined index problem? When you use fetchAll, $row (that being the variable you chose to assign the results to) will be an array of arrays. You need to loop over that just like you did with ->query. If you write that code out you'll get foreach ($row as $row) { Now, doesn't that look a little weird? -
That was a bit hard to understand, so I'll rephrase it: The user is supposed to figure out N 35° 54.374' W 84° 01.829'. They are given most of it: N 35° 54.???' W 84° 01.???'. (Note that 1' is a little more than a mile, so you're giving them a lot of information here.) Each of the six question marks is a single digit, and uses a simple expression based on the 12 digits in their IP address, which we'll say is ABC.DEF.GHI.JKL. Each expression is (a) a single letter if possible (digits be reused?), otherwise (b) two letters added or subtracted if possible, otherwise (c) one letter added or subtracted with a number. If the user's IP address is 075.036.025.058 and the six missing digits are 3 7 4 8 2 9 then we can apply (a) to get 3=E, 7=B, 8=L, 2=H easily, but the 4 and 9 aren't available. Next is to combine two digits using (b): 4 can't be formed through addition but it can through subtraction with 6-2=F-H or 7-3=B-E. 9 can be formed with 7+2=B+H or 6+3=F+E (as well as 2+7 and 3+6). Don't need to invoke (c). Obviously, you need to start by grabbing the IP address and splitting it into the digits you can work with, as well as figuring out the six digits of the coordinates you need to fill in. Then you try to determine the formula for each of those six digits: Using the (a) process is easy: if there's a digit in the IP address then pick it. The (b) process is a couple loops: 1. Try addition. Loop from 1 to the digit-1 (or digit-1 to 1) - we can skip 0 because that would be digit+0 which (a) couldn't satisfy, and skip the digit itself for the same reason. If the number and (digit-number) is in the IP address then use them. 2. Try subtraction. Loop from 9 to the digit+1 (or digit+1 to 9). Again, if the number and (digit+number) exist in the IP address then use them. (There's actually a little more optimization you can do here.) The (c) process is easy: pick a digit from the IP address, decide on either addition or subtraction (keeping in mind that one of those might put you out of the 0-9 bounds), and get the other number.
-
Ajax message gets skipped to the url page not on required div element
requinix replied to jadprash's topic in Javascript Help
You already have a thread for this. -
ajax message gets skipped to the url page not on required div
requinix replied to jadprash's topic in Javascript Help
Not sure what that is supposed to mean, but if you're saying that it's still redirecting then either you didn't remove the redirect or there's another one somewhere in there that you'll need to remove as well. -
I want to disable a specific day on calendar HELP
requinix replied to ms115's topic in PHP Coding Help
I suspect date_added has a time component. -
Wordpress + Mysql Config + PHP file -> not working
requinix replied to Siegfried's topic in PHP Coding Help
Where's the code to enter the information into the database? -
I want to disable a specific day on calendar HELP
requinix replied to ms115's topic in PHP Coding Help
Posting a giant blob of code (and without formatting, which I've added for you this time) and a super vague statement about what you want is really not a good way to get help. What is the problem you are trying to solve? What is your difficulty in solving it? What have you tried so far? What specific part of the code is relevant?