-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
The client script has a couple =s that should be ==s. If you're polling a file then you should look into using inotify: you can have your script "watch" for particular events on a file, with blocking so you don't have to poll so frequently.
-
I'd put my vote for the 5-minute polling thing. Since a 5 minute delay is acceptable, go for that to have things working (you could even have it run every 1 minute), then afterwards you can think about the next version.
-
Same words, multiple meanings. Computer A connecting to computer B could mean that A wants something from B, but that isn't always the case. The networking layer is only concerned about establishing connections, so it doesn't matter who wants what from whom but rather who is going out to connect to the other. As such "client" is connecting and "server" is receiving the connection. In higher layers than that, such as with HTTP or generic applications, the two terms still mean the same thing - they just have added connotations, such as "the client requests a URI from a server". Client connects, server is connected to, and there may be more to it than that. Correct! The operating system running on the server can't know whether a connection to port 80 should go to one application or another, thus the port can only be in use ("bound") by one at a time. A few years ago Skype was using port 8080 (I think?) by default, however some WAMP/XAMPP/et al. bundles had default configurations to use port 8080 as well, and that caused many new developers to ask why they couldn't start up Apache when they had Skype running. It's both: it has code to deal with managing connections and it has the ability to act as an HTTP client. Client connects, server is connected to, maybe other stuff too. ComputerLocal can connect to ComputerRemote with no problem so that's fine. However if they don't want to change the firewall (a stance I agree with) then the only way to get a connection between Local and Remote is if Local initiates. This is the standard "polling" approach: if A cannot inform B of new information then B has to periodically ask A if there is anything. Yup. Yeah, but your hands are tied. It doesn't really have to "wait" to send data. You can follow the normal HTTP approach here: Local connects, sends a request for updated information, Remote responds. Maybe. As far as I'm concerned it comes down to one question: How quickly does ComputerLocal need to know about new information after ComputerRemote has learned about it? Immediately? Within a few minutes? Sometime that day?
-
Oh. I didn't think to mention one pretty big drawback with using such long connections: there's only a finite number of connections that a server can maintain, so this solution does not work for a "large" number of clients. I didn't get the impression that was the case so maybe that's why I didn't remember it. You're going to need to start adopting the proper terminology lest people be confused about what you're saying and what you may know about what you're saying. "Response" is an HTTP thing that may be relevant to your application but isn't part of the general networking paradigm. A server does a listen/accept loop: it listens for a new connection, accepts the new connection (which involves negotiating a new port so the original isn't tied up for long), does whatever it is supposed to do (which almost always involves handing the connection to a different process so the main server one can remain focused on accepting connections), and repeats. Uh no, it's not the same. The docs for stream_socket_server() even say that you need to then call stream_socket_accept(). s_s_s() basically wraps the "bind" call while s_s_a() wraps the "listen" and "accept" calls. Not a whole lot, actually. Check out the examples. Answered earlier. That's up to your application. There is no automatic reconnect at this low of a level. Sounds like you're confusing the client and server. The stream functions help, but if you want more then you'll probably have to find a third-party library for it. Personally, I'd just do it myself: beyond the initial learning experience there's not too much code involved. Like I said, check the examples. Maybe whip up a couple scripts to prototype the client/server communication process and run them on your own computer.
-
Ask your employer what they consider you? I mean it's just a title, it's not like some sort of contract. I called myself the CTO at my last job simply because I was the only IT person there (at a small company).
-
For clarification, exactly what does mean?
-
To be clear, a "stream" is what PHP calls its abstract representation of various things - mostly used with file handles, but it can be used with sockets too. They have a set of functions to operate on streams in a more-or-less general fashion regardless of the underlying entity. "Sockets" (BSD sockets at least) is the networking concept available in pretty much every language, where you deal with TCP/IP and connections and such. They have their own set of functions whose names tend to borrow from the C versions, and documentation for how to use them in one language tends to port over fairly well to other languages. So, Yes: a socket opened between two hosts that tries to stay open for pretty much ever. Realistically the A host would need to be able to reestablish the connection if/when it drops for whatever reasons. Yes. In networking terminology, the "client" is the one doing the connecting and the "server" is the one being connected to. If it weren't for the fact that hardware allows for not needing to do that, yes. What you actually do is called a "select", which blocks (the function call doesn't return) until something about the connection changes - such as there being incoming data or the connection goes down. With an optional timeout, if you want to be able to do other stuff while waiting. Unless poorly configured, firewalls allow traffic to go both ways through previously-established connections. When people talk about blocking stuff with the firewall it really means blocking the initial connection attempt. Read up on TCP/IP networking (to know about what's going on) and BSD sockets (to know about how to do stuff in code).
-
Your options are basically a) A polls B for information b) A establishes a persistent connection to B and waits for activity c) A opens up a port on the firewall and lets B connect The stream functions are a bit higher-level than the raw socket functions so I suggest you try to use them.
-
Print design = someone who designs for print Web design = someone who designs for the web If you can do both then call yourself a "Web Designer" when talking about the web and a "Print Designer" (I guess?) when talking about print.
-
i need help on this payment gateway i'm trying to learn
requinix replied to sparkie1985's topic in PHP Coding Help
Dude. Punctuation and complete sentences. plzkthx It's not entirely clear what they're saying, but what I believe they're trying to say is: You need to make a GET request to a particular URL. You've done one like that in step 1 already. This time the URL is not fixed: it starts with "https://test.oppwa.com/" like before but the rest of it was passed in the request URL to your page as "resourcePath". So the proper URL is "https://test.oppwa.com/" . $_GET["resourcePath"]Add on the authentication stuff like before, do a request like before, and the result will be... something. I don't know that part. -
What's your code?
-
Extracting only specific array elements
requinix replied to NotionCommotion's topic in PHP Coding Help
You aren't really saving yourself much: still typing out the basic key => value stuff for each element you want. A sort of "array_choose" function would be nice to have built-into PHP. I wouldn't implement it in userland just for this one purpose, though. /** * Extract a subset of an array * * @param array $array Source array * @param array|scalar $key An array of keys, or the first key * @param scalar ... Additional keys if $key is not an array * @return array */ function array_choose(array $array, ...$keys) { $return = array(); foreach (isset($keys[0]) && is_array($keys[0]) ? $keys[0] : $keys as $key) { if (array_key_exists($array, $key)) { $return[$key] = $array[$key]; } } return $return; } -
Extracting only specific array elements
requinix replied to NotionCommotion's topic in PHP Coding Help
I'd either do that or the obvious solution, mostly depending on whether I remembered about array_intersect_key at the time. -
Username/Password check - does it matter which way?
requinix replied to benanamen's topic in PHP Coding Help
By the way, in case you were considering it: Don't indicate whether the username does not exist vs. it does and the password is wrong. It reveals information an attacker could use. Use the same error message for both - ideally a single check in code like if (no matching row || password hash does not match) { -
alright just made up this.. can someone edit this need more tweaks
requinix replied to Fryle's topic in PHP Coding Help
ugh... 1. Be more specific. 2. The file has barely anything in it - least of all no PHP code. I don't know what you expect it to do because it's not set up to do anything. 1. There's no button to submit the form. There isn't in security.php either but hitting Enter typically works. 2. You cannot use a redirect to process a form submission. Do the work to delete products in delete.php. (The ID to delete is in $_POST if you know where to look for it.) Be more specific. Be more specific. -
alright just made up this.. can someone edit this need more tweaks
requinix replied to Fryle's topic in PHP Coding Help
We're not going to look through 18 files to do free work for you. We're certainly not going to do your homework. If you can't get help from the teacher then get help from your classmates. If you have specific questions about specific parts of your code, we can help you with that if you post the relevant parts of the code. -
Is this resolved? What you're describing sounds like PHP isn't installed or running on the server, but when I look at the contact form everything appears to be in order.
-
I see you're still doing the thing I told you to stop doing... Name your original HTML inputs like "input[0][0]" for the position, "input[0][1]" for the unit name, and "input[0][2]" for the president. In your Javascript, make it generate the same sort of thing except keep a counter that starts at 1 and increments every time a new row gets added. The first one added will have input[1][...], the second input[2][...], and so on. If someone removes one the "hole" at that index is not a problem. Then take a look at what's in $_POST.
-
Javascript cannot change the appearance of anything. Only CSS can. But you can use Javascript to affect the CSS. Customize the look how?
-
Whitelists are better than blacklists: you should specifically list which files are allowed rather than which files are not allowed. You could do that automatically by using scandir() to build an $allowed_files and excluding ".", "..", and the four you don't want (though really putting them in another directory would be better). Alternatively, you could use ctype_alpha or _alnum on $page to validate that it is only letters/letters and digits. Yes, I know you're basename-ing the page name. That's nice, but this is a matter of principle. Oh. And for SEO you shouldn't use basename as that creates the opportunity for accessing a page through multiple URLs, which is not good. Just do the whitelist/ctype thing.
-
Printing Dynamic Input Results to CSV
requinix replied to theodore_steiner's topic in PHP Coding Help
It replaces the $csvdata line and the fwrite. That work you did about building up the line of CSV data and writing it to the file? fputcsv can do all the work for you if you provide it with an array of all the values you want to write. $csvdata = array( $firstName, $lastName, $homeAddress, $homeAddressTwo, $city, $province, $postalCode, $homePhone, $personalEmail, $confirmEmail, $oectaNumber, $memberStatus, $teacherTraining, $teachingYears, $employmentHistoryValues ); // I don't know where the thing with multiple values is - whether it's one of those variables // or whether you haven't written it into the code yet // whatever the answer, you take that array, implode() it to a single value, and put it in $csvdata // like // $csvdata = array( // ..., // implode(",", $array_with_multiple_values), // ... // ); $fp = fopen("formdata.csv", "a"); if($fp) { fputcsv($fp, $csvdata); fclose($fp); } -
Printing Dynamic Input Results to CSV
requinix replied to theodore_steiner's topic in PHP Coding Help
The only way the CSV would "get confused" is if your code did something weird when generating the CSV data. So... don't do anything weird. Two values? Three values? One value? implode() them to get the comma-separated string, put that into an array with the other values, and use fputcsv to write to the file (instead of building the line yourself and writing using fwrite). $line_of_csv_data = array( "qwertyuiop", "asdfghjkl", implode(",", $array_of_values), "zxcvbnm" ); fputcsv($fp, $line_of_csv_data); -
Printing Dynamic Input Results to CSV
requinix replied to theodore_steiner's topic in PHP Coding Help
If you mean like qwertyuiop,asdfghjkl,one,zxcvbnm two three then no because then it wouldn't be CSV anymore. Another version would be qwertyuiop,asdfghjkl,"one two three",zxcvbnmthen you can try that but there's no guarantee a CSV reader will understand it. How about combining the values like qwertyuiop,asdfghjkl,"one,two,three",zxcvbnmor simply using multiple rows qwertyuiop,asdfghjkl,one,zxcvbnm qwertyuiop,asdfghjkl,two,zxcvbnm qwertyuiop,asdfghjkl,three,zxcvbnmor using two CSV files, one with the base data and another with the lists. qwertyuiop,asdfghjkl,zxcvbnm qwertyuiop,one qwertyuiop,two qwertyuiop,three(pretending that "qwertyuiop" is a unique identifier) -
How to generate unique key of random numbers in PHP
requinix replied to Aarav123's topic in PHP Coding Help
You cannot have both random and unique: if it's completely random then there's a chance you'll generate the same string twice. But you can generate something unique that looks random, or you can pair something random with something unique into one string. What are your criteria for this string?