-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Then it's easy to change the script. Right now it tracks just the coldest and hottest temperatures; add two more variables for the coldest and hottest locations.
-
FYI, next time you post code, make sure you remove sensitive information like the appid you had in that URL. So that code makes more sense than the one earlier, and doesn't have as much that needs to change. You already have a loop that goes over all the locations, so do the work of determining the highest and lowest in there. Do you only care about the temperatures? You like you don't care where the temperatures are from - just what they are? <?php session_start(); include_once("cxn.inc"); $today = date("Y-m-d H:i:s"); $sql = "SELECT airports.Name,airports.Country FROM airports INNER JOIN rosters ON airports.IATA = rosters.Arr WHERE rosters.Code = '$code' AND rosters.SectorDate >= '$today'"; $result = mysqli_query($cxn,$sql) or die ($cxn->error); $coldest = $hottest = null; while($row=mysqli_fetch_assoc($result)) { $link = 'http://api.openweathermap.org/data/2.5/weather?q='.$row['Name'].','.$row['Country'].'&units=metric&mode=xml&appid=*'; /* WEATHER API */ $xml=simplexml_load_file("$link") or die ("Cannot create object."); $temp = (int)$xml->temperature['value']; // converting to int is important or you'll have a bunch of SimpleXMLElement objects if (is_null($coldest) || $temp < $coldest) { $coldest = $temp; } if (is_null($hottest) || $temp > $hottest) { $hottest = $temp; } } /// OUTPUT GOAL /// echo $coldest; echo '<br />'; echo $hottest; ?>
-
Alright, then we need to start from the beginning. What is the XML you have ($link?) and what does the database have to do with it?
-
Your code doesn't make sense. Is that really what you have?
-
How do you want the user to decide? Do you want them to give them both options at once? Have some sort of "custom" item in the list? For the list itself, a simple for loop will do: echo "<select>"; for ($m = 0; $m <= 24; $m += 0.25) { $hhmm = sprintf("%02u:%02u", floor($m), (60 * $m) % 60); echo "<option value='{$hhmm}'>{$hhmm}</option>"; } echo "</select>";
-
Turn everything into a int, like using array_map with intval, then do min() and max() on the final array. Looks like you're getting this from XML? You might be able to do the min/max from within the XML itself, depending on what the markup is...
-
Can you turn a PHP script into an executable? (Linux)
requinix replied to Hes's topic in Applications
If someone has access to the system then you're done for. Basic tenet of computer security. Obfuscating, hashing, compiling code, none of that will protect you for long. If this information is so secretive that you don't want these people with access to be able to see it then don't give them access. It's that simple. -
Error in mysql DB creation in wamp
requinix replied to girishk's topic in PHP Installation and Configuration
You're running some kind of update script on a database that doesn't need updating. -
Huh. I must have missed the changelog entry that says "file_get_contents() will now attempt to execute what it retrieves as PHP code".
-
stripos not recognizing forward slashes
requinix replied to StoneColdMagic's topic in PHP Coding Help
Nope. What's your real code? -
Yes. Using some Mail class, not vanilla mail().
-
Are you sure that's the direction you want to rewrite? People go to /blog.html and you want that to actually execute /blog/2013.html?
-
No. Because that would also remove the code dealing with the normal To: recipients. See the $to? Make sure $recipients does not have any information about the CC people or the BCC people.
-
update four records daily out of six records----mysql---php
requinix replied to WaqasAhmed's topic in MySQL Help
Are you saying that it does not work right now? Because that query says absolutely nothing about which day's records to update. -
update four records daily out of six records----mysql---php
requinix replied to WaqasAhmed's topic in MySQL Help
UPDATE table SET last_dty_timestamp = /* today's date */, duty_flag = duty_flag + 1 ORDER BY last_dty_timestamp ASC /* earliest records first */, person_id /* unique ID to guarantee a stable sort */ LIMIT 4 /* only update the first four records */ -
Tentatively, yes. And the CC ones too. Those should both be handled with the $headers earlier.
-
JSON is probably your best bet. Upload: Do a POST with a request body containing the JSON data. PHP reads the body, decodes, and inserts into the database. Download: PHP reads the data from the database, JSON-encodes it, and outputs it.
-
if(empty($recipients)){ $recipients = $to; if(!empty($cc)){ $recipients.= "," .$cc; } if(!empty($bcc)){ $recipients.= "," .$bcc; } }Don't put the BCC list in the list of recipients. In fact, shouldn't the Mail code handle all that itself?
-
Can you turn a PHP script into an executable? (Linux)
requinix replied to Hes's topic in Applications
Actual executables? Or simply things you can run as ./script.php? For actual executables... don't. It's not worth it. PHP code was not meant to be compiled into executables. There are projects out there which say they can, but seriously reconsider whether you actually need to do that. Consider what would happen with extensions and INI settings and all that: either you would have to have PHP installed on the system anyways, or all that would need to be baked into the program, or the executable would have to be bundled with all that stuff. If ./script.php is sufficient, stick a #!/usr/bin/php(substitute the appropriate path to PHP) at the top of the file, then chmod +x it. -
How can I store SMTP passwords in a secure manner?
requinix replied to lush_rainforest's topic in PHP Coding Help
Regular users cannot see your PHP code. Regular users cannot "break into" code. Alright, so you want to protect the password in a general sense. Put it in a PHP file that is not part of your source code (like you don't put it up on GitHub or whatever), put it on your live server in a place that isn't part of the website (like /home/you/config when your website is at /home/you/public_html), and have your code read that file (via include/require or parse_ini_file() or whatever). If you use shared hosting then you should check the file permissions, but that depends on how the server is set up... -
How can I store SMTP passwords in a secure manner?
requinix replied to lush_rainforest's topic in PHP Coding Help
The password hashing/verifying stuff won't help: you cannot recover the original password once you've hashed the data. First step: what are you trying to protect against? Someone casually looking at code and seeing the password? A rogue developer who can run code in a development environment but not see any production data? Someone with shell access to the server recovering the password? -
PHP Date workout timescale from Monday and 1st of Month
requinix replied to blmg2009's topic in PHP Coding Help
Here's a quick demonstration of what happens when you use strtotime with a phrase like "next Monday": https://3v4l.org/t9ZaI. Between Tuesday and Sunday, "next Monday" is the next Monday. On Monday itself the date will be the next week - which may be a good thing for you. -
Consider hiring a lawyer/tax company for a bit to make sure you're doing things right. Getting started, the rules are complicated because you may or may not need to start making payments in the middle of the year. It has to do with how much you expect to make during the year and how it compares to what you made in the previous year. Being January you probably do, but between moving to the US and getting married and such, I don't know. (Probably.) In general, you make quarterly-ish payments according to how much money you expect to make during the year. They don't all have to be the same amount, so if you get a big job or have a dry spell then you can pay more or less for an individual payment. When tax season comes the next year you pay taxes like normal, with your quarterly payments counting as taxes paid during the year. You then get a refund (paid too much) or have to pay more (quarterly payments weren't enough) accordingly. Your clients will need to provide you with a 1099-MISC form if they pay you more than $600. They could do that when the job is done or at the end of the year. That's the self-employed equivalent to a W-2. That is then part of the tax forms you submit. The client will also submit forms like that to the IRS. If you plan to do this as a real job, like as a contractor and not mere freelancer, then you should look into forming a S-corporation because the rules are a little different and you can probably pay less taxes that way. IIRC, the most relevant forms are the 1099-MISC (payments made to you), 1040 (main tax form), and Schedule C (specific form for self-employment). I think there's another big one I'm forgetting, and there are a handful of others you'll come across.
- 1 reply
-
- freelancer
- usa
-
(and 1 more)
Tagged with:
-
SMTP error in phpmailer settings
requinix replied to girishk's topic in PHP Installation and Configuration
Try port 587. -
Okay, just did a test. 0. Made a repo on GitHub First directory: 1. Cloned repo, on "master" 2. Added and committed file #1 3. Branched to "branch" 4. Added and committed file #2 5. Pushed both branches, still on "branch" master and origin/master have file #1, branch and origin/branch have files #1 #2. Second directory, 6. Cloned repo, on "master" 7. Added and committed file #3 8. Pushed master Second directory's master and origin/master have files #1 #3, branch and origin/branch have files #1 #2. First directory, 9. Fetched (updated origin/master, local master still has #1) 10. Merged origin/master into master (got file #3) The branch is still where it was: files #1 and #2.