-
Posts
15,288 -
Joined
-
Last visited
-
Days Won
436
Everything posted by requinix
-
I can't even figure out the problem description, and the machine translation wasn't very helpful. I mean, Input data 3 1 2 1 4 11 3 16 The result of 43 employees, 1 something, 2,1,4 hours for the three employees to each solve a problem, 11,3,16 something else, and then somehow the result is 4?
-
What does the "tablet" version of that look like?
-
It's a copy of a GitHub repo that doesn't have any code in it.
-
Are you sure XAMPP isn't running? That error sounds like it's coming from your browser, not XAMPP. One of http://localhost or http://localhost:8080 should work - or at least give you a 404. Otherwise you need to know which port XAMPP is using (assuming it is running at all) and plug that into the latter URL in place of the 8080.
-
If you mean using it for closing connections and stuff that the class needs, yes. You can't tell PHP to destroy an object - just unset variables/let them drop out of scope and rely on PHP to clean up as it goes.
-
You can call $this->close() or whatever to "close a connection". You cannot unset $this. I can't think of any reason why you should need to. If the calling code wants to destroy the object then it needs to do that (and by "destroy" I mean remove any reference it has and forget about the whole ordeal (however the object may be referenced somewhere else)).
-
Your form has method="get" but you are using $_POST. method=get goes with $_GET, method=post goes with $_POST.
-
Implementing lenght prefix with stream
requinix replied to NotionCommotion's topic in PHP Coding Help
//How can I validate that the received message length prefix matchs the length of the message so it doesn't get out of sync?...you can't. Because you're using that length to decide how long the message is. If the other end sends the wrong length then it's their fault, and you'll probably discover it when the json_decode() fails. It's pretty simple so yeah. -
Implementing lenght prefix with stream
requinix replied to NotionCommotion's topic in PHP Coding Help
I would expect parseBuffer to look more like do { if have message length { if buffer is >=length long { get message as substr(buffer, 0, length) deal with message adjust buffer to substr(buffer, length) reset length } else { quit loop // wait for rest of message } } else { if buffer is >=4 long { get length as substr(buffer, 0, 4) and unpack adjust buffer to substr(buffer, 4) } else { quit loop // wait for rest of length } } } indefinitely // will keep going until buffer runs out -
Showing calories in the first part and weight in the second doesn't make sense. Should be the same units for both: calories burned and remaining, or weight lost and remaining. Regardless, you need a percentage, and that requires having (if not showing) both numbers in the same units. Do you have the code at a point where you have two variables, one for the amount of s done so far and another for the amount of s remaining to be done?
-
The progress bar would be the number of calories burned so far compared against the total number of calories you estimate they need to burn, right? That's easy enough to do on a page so long as you can come up with those two numbers - really, a percentage. The only question for this part is what you want the progress bar to look like. Calculating the calories to burn is harder. You need to do some research about this because there is no simple conversion rate between calories and weight lost.
-
Oh, well then, use the title. The URL would look like my.php?channel=TV%20Channel%201 or ?channel=TV+Channel+1 (whichever you would rather have) by using http_build_query; use the PHP_QUERY_RFC3986 enc_type if you want %20s instead of the default plusses.
-
But you don't have an ID to work with - just "TV Channel N", and whatever the URL is but you said that changes. If there aren't too many channels in that list then you could do something like hash the name: echo "myphp?channel=" . sprintf("%u", crc32("TV Channel 1")); // myphp?channel=3485320925then search the XML for the channel with a matching (by doing the same sprintf+crc32 on each one and comparing the numbers).
-
>attached >no attachment
-
I imagine that the job is being killed off when the shell exits. Don't do this anyways. Use cron to set up a regular job, even if that job runs every minute and doesn't do anything. Store the information needed (like the permalink) somewhere and have the cronjob scan for jobs and process them.
-
PHP Data Grab Project - Need help with security
requinix replied to ClipboardCode's topic in PHP Coding Help
Aside from the few remaining functions in PHP which issue warnings in cases that don't need them, @ is fine if you are already accounting for potential problems being covered up; note that custom error handlers will still receive the warning, but with $errno=0. @$_POST["letmein"] != $foo !isset($_POST["letmein"]) || $_POST["letmein"] != $fooaccomplishes the same thing either way, but using @ lets you avoid the tedious isset() check. With PHP 7 you could swap the @ for a ?? ($_POST["letmein"] ?? "") != $foo -
You can't. Not with the model you're using. You're talking about something that happens at runtime - unless you want to make a class for every single possible combination of features (spoiler: you don't) then that sort of behavior needs to be managed dynamically. As a first draft, interface ObjectFeature { public function __construct($object); } interface ObjectHasFeatures { public function addFeature($feature); public function getFeature($class); public function hasFeature($class); } trait HasFeatures { private $_hasfeatures_features = []; public function addFeature($class) { $this->_hasfeatures_features[$class] = new $class($this); } public function getFeature($class) { return $this->_hasfeatures_features[$class]; } public function hasFeature($class) { return isset($this->_hasfeatures_features[$class]); } } class Car implements ObjectHasFeatures { use HasFeatures; private $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } class FlyingFeature implements ObjectFeature { private $car; public function __construct($object) { assert($object instanceof Car); $this->car = $object; } public function fly() { echo "*{$this->car->getName()} starts flying*\n"; } } $car = new Car("Notion's Car"); $car->addFeature(FlyingFeature::class); $car->getFeature(FlyingFeature::class)->fly(); https://3v4l.org/Qmm0D
-
For a simple solution, keep your virtualhost conf files on the host machine (eg, vagrant/www/*.conf) and do something like Include /path/to/wherever/*.confin the Apache configuration. Then you can configure each virtualhost however you want, with whatever root you want.
-
Yeah, I was getting confused there for a bit. Anyway, I think kicken is talking about the $data->id. The clients (being the ones generating those IDs) would use a sequential number, and the easiest way to go about that would be with a static variable somewhere: static $id = 0; $message = [ "id" => ++$id, ... ];Really, though, the client can do whatever it wants as long as the ID is scalar (for use as array keys) and "guaranteed" to be unique during the lifetime of that particular message's request/response cycle.
-
Um, so, question, How are you coordinating these IDs across clients? Given that the server needs to know which ID corresponds to which client.
-
And these are the people companies will hire to replace us