-
Posts
15,286 -
Joined
-
Last visited
-
Days Won
435
Community Answers
-
requinix's post in getting both ipv4 and ipv6 address of user was marked as the answer
The way they do it is they give the user something to connect to that supports only IPv4, and then another that supports only IPv6. Then they combine the information together to give you the full results.
Because all you can ever get from the user is how they connected to your site. If they used IPv4 then you can't know what their (public) IPv6 address is.
-
requinix's post in Help with API was marked as the answer
That describes the "ListDevicesDB" API you can call.
1. It uses the GET method.
2. You need to include a "token" header that includes some value. If the value is what you included in your post then that needs to change because this was (probably) supposed to be a secret value and you've now shared it with the whole internet.
3. The URL is as given there. It optionally supports a "deviceSerial" query string parameter, as the description indicates.
4. It doesn't describe what the return value is.
So you need to get a basic API calling thing in place. You can use libraries for it, or you can write the API calls yourself using cURL.
Your first step should be to understand more about making API calls through PHP. It's all the same everywhere - only differences being exactly what the API wants, and that's the information they gave you.
Once you understand a little more about API calls, then you can deal with the PHP code to try to make them. It's pretty simple but you do need to know more about what this is all about to be effective at it.
-
requinix's post in What's the problem that tunneling is trying to solve? was marked as the answer
RDP servers are notoriously risk-prone. It's almost always a bad idea to have them open to the internet for anyone to connect to.
By "tunneling" through the VPN, the RDP server remains disconnected from the internet, but you can still access it by connecting to the VPN (which is going to be much more secure).
Ditto for the remote server. In your case apparently you need two hops, presumably because it's not accessible over the VPN directly, but the point is the same.
It's very common to have a database server not connected to the internet, to minimize risk, so to allow access you can VPN or SSH into the network and then tunnel to get a direct database connection.
-
requinix's post in How do promises program flow work in javascript? was marked as the answer
Basically anything that has "await" and/or "async" keywords works the same way.
-
requinix's post in How to search for files whose suid bit is set? was marked as the answer
Try it and find out.
Seriously. That would have been the easiest option this whole time. All you had to do is manually find a setuid executable, such as sudo, and run different find commands to see what happens.
-
requinix's post in Is there a way to encrypt the directory names in a URL? was marked as the answer
You can't encrypt the location because the end result is that you're still giving someone a URL to the file. Having gibberish instead of the word "documents" doesn't change that.
The actual answer here is pretty simple: don't give direct links to your PDFs. Use a PHP script which authenticates the user and then outputs the file.
You can use URL rewriting to transform /documents/whatever.pdf to something like /document.php?filename=whatever.pdf (which means existing URLs still work), then do something like
<?php session_start(); if (!isset($_SESSION["userid"])) { // or whatever so you know if the user isn't logged in http_response_code(403); exit; } if (!isset($_GET["filename"])) { http_response_code(400); exit; } $filename = $_GET["filename"]; if (!preg_match('/^[a-z0-9_.-]+$/i', $filename)) { // potentially other characters in there http_response_code(404); exit; } $path = $_SERVER["DOCUMENT_ROOT"] . "/documents/" . $filename; // or whatever the path should be if (!is_file($path)) { http_response_code(404); exit; } $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $mime = [ // default $extension => "application/octet-stream", // list of file types you might have "pdf" => "application/pdf", // ... ][$extension]; header("Content-Type: $mime"); header("Content-Length: " . filesize($path)); header("Content-Disposition: inline;filename=$filename"); readfile($path);
-
requinix's post in mysqli_sql_exception: Incorrect string value was marked as the answer
"Incorrect string value" means you're trying to insert data that isn't valid for the column. In your case, the column is defined as utf8mb4 (aka UTF-8) but your string is not UTF-8.
If the value is binary data then do not use VARCHARs in the first place. Those are for character data. Use VARBINARY instead.
https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html
Either that, or you aren't supposed to be inserting raw binary data but either hex digits or a base-64 encoded version of the data...
-
requinix's post in How to change style when hover over div inside svg element? was marked as the answer
Works for me, provided that I'm not using Firefox and that I think the desired behavior is to change the background color of the SVG to red.
If you're trying to change the background color of the .inside-svg element then you've vastly over-thought this...
-
requinix's post in Match Two Types of Strings was marked as the answer
So you want to allow both (a) "TMP" plus 1-5 numbers, and (b) 1-5 numbers then "M"?
1. You need ^ and $ anchors, otherwise the regex will only check if the string contains something that matches it.
2. {5} means exactly 5, but you've been saying "up to".
3. What about zeroes? That's not in the regex now but I'd be surprised if you didn't want to allow them.
4. To allow both patterns, tell the regex that you want to allow both patterns using a |
/^(\d{1,5}M|TMP\d{1,5})$/
-
requinix's post in Trying to find out what these examples (<FOOTER>) is called. was marked as the answer
"Tag" is still fine. It's not like that term has died off or anything. And it applies to all... well, to all tags... not just certain ones. "META tag", "HTML tag", "NAV tag", whatever.
"Element" is the other one in common usage. Means the same thing. Probably a bit more proper.
Maybe the word you're looking for is "semantic"? Because the idea of those new tags/elements is that they have a semantic meaning: while DIV is just whatever, HEADER is specifically for "a header", and NAV is specifically for navigation, and such. Makes it easier for automated processes (like search engines) to analyze a page.
-
requinix's post in Help with dropdown menu integration with switch case was marked as the answer
Is the <select> inside a <form>? Has that form been submitted? Because that's the only way PHP will be able to do this.
If you want the text to appear when you change the option without submitting a form, you need Javascript...
-
requinix's post in Which Php Function Checks For Strings That CONTAIN or NOT CONTAIN Certain Chars ? was marked as the answer
array_filter + str_contains
-
requinix's post in Recursive generator was marked as the answer
You can "yield from" another generator.
private function getTextFiles(File $file):\Generator { foreach($file->getChildren() as $child) { if($child instanceof IsTextFile) { yield $child; } else { yield from $this->getTextFiles($child); } } }
-
requinix's post in Possible with 2 ID's was marked as the answer
"Make the button go away and open another button" isn't exactly the most descriptive thing ever...
As long as something isn't visible, it doesn't really matter much whether it exists or not. The simplest thing here is going to be a sort of toggle: start with the first button visible and the second not, then "toggle" the two so the first is not visible and the second is.
1. Start with the HTML that includes both buttons.
2. Figure out how you want to hide the unwanted button and apply it now so that the second one is hidden.
3. When the first button is clicked, do whatever it takes to hide the first button and show the second.
Okay, so reading that now it doesn't seem helpful, but I'm trying to word it in a way that makes it flexible. Because when it comes to HTML and CSS and Javascript, there's always 100 ways to accomplish a task... however 95 of them are terrible.
Here's what I would do.
1. Create a CSS class for these types of button. It doesn't have to do anything (unless you want it to) and only really exists to mark these buttons as being particular types of buttons. So in that sense there's nothing to "create" per se.
2. Create a CSS class for "the active button". Apply it to the first button now, and use CSS to make "these types of buttons" which are not "the active button" be hidden. This means you control visible vs. hidden using a CSS class and not the direct style.* attributes.
3. Add Javascript for the first button that will remove its own "the active button" class and add it to the second button.
4. Add Javascript for the second button that will remove its own "the active button" (assuming you want it to be removed when clicked as well) and make the DIV you want visible; the latter should be through CSS too but it's not really that important.
Personally, if I'm dealing with behaviors that are tied to Javascript, I prefer to deal with data attributes instead of class names, but that's not very important either.
All together you get something like this:
<style> #step-container .step-button:not(.active-step) { display: none; } </style> <!-- This is a nice thing that "scopes" the buttons - using step-button or active-step outside this won't get the CSS applied --> <div id="step-container"> <button id="step1" name="button" class="btn step-button active-step">Click to Verify Information</button> <button id="step2" name="button" class="btn step-button">Show Div</button> </div> <div id="thediv" style="display: none;">...</div> <script> // Creating and running this anonymous function immediately means you can use variables without making them global (function() { // Grab these three ahead of time to make the function code nicer const btn1 = document.getElementById("step1"); const btn2 = document.getElementById("step2"); const thediv = document.getElementById("thediv"); // Add event listeners through code instead of putting them inline with onclick attributes btn1.addEventListener("click", () => { // Use .classList to add and remove classes instead of going through the .className string btn1.classList.remove("active-step"); btn2.classList.add("active-step"); }); btn2.addEventListener("click", () => { btn2.classList.remove("active-step"); // Literally removing the "display" override is better than forcing it to be block/inline/whatever it's naturally supposed to be thediv.style.removeProperty("display"); }); })(); </script> This is closer to the sort of modern stuff that we can do nowadays; the above isn't actually quite ideal, but it's a good step-up from the sorts of stuff we had to do 10 and 20 years ago with inline event handlers and quick-and-dirty Javascript.
-
requinix's post in About the use of the __DIR__ controller. was marked as the answer
__DIR__ is a "magic constant" (it's a constant with a value that varies) that is the directory of the file you put that code in. That's all there is to it. Period. Super simple. Nothing to do with URLs. Nothing to do with MVC design. Nothing to do with your website, really. Just a directory path.
-
requinix's post in SoapServer with operation name with dash was marked as the answer
You don't, and whoever created that WSDL was dumb to not consider potential situations like this.
You can, however, use the magic __call method to intercept calls to methods that don't exist, and create a properly-named method to do the work.
class MySoapServerClass { public function __call(string $method, array $args) { return match ($method) { "ProvideDocument-b" => $this->ProvideDocumentB(...$args), }; } private function ProvideDocumentB(...) { ... } }
-
requinix's post in If statements with icon was marked as the answer
So with this,
<a href="<?php print wp_kses_post($item['linkedin']); ?>"><i class="fab fa-linkedin-in"></i></a> the link is wp_kses_post(...) and you don't want to show the <a> if the link is empty.
Get the value of the link into a variable, use it with the if statement, then only show the <a> if not empty.
<?php $linkedinlink = wp_kses_post($item['linkedin']); if ($linkedinlink) { printf('<a href="%s"><i class="fab fa-linkedin-in"></i></a>', htmlspecialchars($linkedinlink)); } ?> Remember to use htmlspecialchars when you do not know if a value is 100% safe for HTML.
-
requinix's post in CRUD create form, output PHP was marked as the answer
1. Don't use mysqli_multi_query because you're running the three queries by themselves individually already.
2. Don't create queries where you put $_POST values directly into the SQL. It's extremely unsafe. Use prepared statements instead.
-
requinix's post in CSS grid question - flow around an element was marked as the answer
The template does one name per cell so you can't overlap things on their corners.
grid-area is shorthand for grid-row/column-start/end, so you could explicitly set the column-end to be "right". That'll stretch it out over that column, but text won't wrap and I don't know if there is a way to essentially "float" that right element.
So what you could do, given you know the size of the columns and rows (or do you?) is to create a floating div inside the content that positions where the overlapping right cell is.
https://jsfiddle.net/e1hg05af/
-
requinix's post in PHP 8.x and PEAR - Windows was marked as the answer
Some Googling suggests that there's a weird and long-standing issue with the .phar such that you can't download it from a browser but need to use a tool like curl.
PHP itself might work too.
> php -r "copy('http://pear.php.net/go-pear.phar', 'go-pear.phar');"
-
requinix's post in [cakephp] Database driver Cake\Database\Driver\Mysql cannot be used due to a missing PHP extension or unmet dependency. Requested by connection "default" was marked as the answer
It would appear that the driver cannot be used due to a missing PHP extension or unmet dependency.
Do you have the pdo and pdo_mysql extensions installed?
-
requinix's post in Fulltext searching was marked as the answer
FULLTEXT searching just does not do that. It doesn't offer particularly sophisticated features: it's oriented towards taking an input list of words and trying to find things that are relevant to those list of words.
"M/C" isn't going to work because those aren't words. Prices aren't going to work because those aren't words. "Within 10 words of each other" isn't an option.
-
requinix's post in Upgrade website from 7.3 to 8 was marked as the answer
Sure: upgrade to PHP 8 and see what it complains about. Not on the real site, of course, but in some development version of it. That's really the most effective method.
I don't know what "tags" are, but the online documentation has migration guides.
Go through each guide in sequence; if you want to upgrade to latest, which is 8.2, then you need the 7.3->7.4 and 7.4->8.0 and 8.0->8.1 and 8.1->8.2 guides.
-
requinix's post in Subracting a number from decimal value in mysql was marked as the answer
DECIMAL(65,0) means it can store a number with 65 digits and 0 after the decimal point.
-
requinix's post in Structure for Small Custom System was marked as the answer
You already know the answer to that: some point before you end up with 116 functions in a 2600+ line file.
As for where "before" is, that's tricky. Because despite what many others will say, sometimes having complicated things contained in one single place makes them easier to understand than if they had their components spread out across multiple locations - but having that as an exception to the rule also lends itself to being an excuse to ignore the rule.
The simplest approach is what I hinted at: separate by category, or purpose. With 116 functions there are going to be a much smaller number, perhaps a dozen, of groupings. Like notes functions, and activity functions. Even if you only had one "createNote" note function, the fact that it's a different subject matter than activities warrants having it in its own place.
The other answer is that good code design won't let you create massive utility classes to begin with - no offense. Following principles like SOLID (its "single-responsibility principle" is what that whole categorization thing is essentially about) or DRY will naturally encourage you to break things up as a side-effect.