Jump to content

kicken

Gurus
  • Posts

    4,143
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by kicken

  1. I recommend that you do your development work with the developer tools open and cache disabled. If after disabling your browser cache you still have issues then there might be some other cache either on the server or a proxy you're using that is causing problems.
  2. Output the values you get separately so you can verify if they are what you expect. <p>End date: <?=$callEvents['end_date']?></p> <p>End timestamp: <?=strtotime($callEvents['end_date'])?></p> <input type="datetime-local" class="form-control datetime" name="end_date" value="<?=date('Y-m-d H:i:s', strtotime($callEvents['end_date']))?>">
  3. You need to download dependencies to analyze them, since what dependencies you get can depend on the environment you're project is installed into. So you need to start with a project that requires packages that you want. Trying to analyze dependencies without a project doesn't really make sense. If for some reason you don't want to make a project but want to know what packages my/b depends on, you can download my/b and run composer show -t within it's directory. Every package is a composer project with it's own composer.json that defines it's details. There's no way at all to get a list of which packages are dependent on my/b since doing so would require scanning every project ever created by every person on the planet.
  4. Since you're using windows server, you could setup and use IIS instead. It's relatively simple to do and works fine. If you really want to use Apache, I'd suggest installing and configuring it manually rather than via WAMP. Go to Apache Lounge to get windows builds of apache and some help with getting it all configured properly.
  5. if ($_POST['clientNameNew']) This will check if the value is a truthy value or not, but the key still needs to exist or you'll get an undefined index notice. You can avoid the notice in various ways. In modern PHP versions, the simplest is to use the null coalescing operator. if ($_POST['clientNameNew'] ?? '') Other ways to check are with isset, empty, or array_key_exists. Alternatively, you could just force them to exist.
  6. As it says in the error, you need to create a composer.json file that contains the details for your project, including what it requires. For example: { "require": { "my/a": "dev-master" } } I suggest you read through that Getting Started section as was advised.
  7. Use the -t option to get a tree view of your packages. $ composer show -t my/a dev-master └──my/b dev-master └──my/c dev-master
  8. When you use the quotes like in quote_id = ':quoteId' You're asking mysql to search for rows where the column quote_id is equal to the value :quoteId, literally. The quotes prevent it from being used as a parameter placeholder and cause it to be a literal value in the query. Removing the quotes allows the :quoteId to be seen as a parameter placeholder and replaced correctly with the bound value when the query is executed.
  9. PHP doesn't assume something afaik. useradd does though. If you don't explicitly specify a home directory, it defaults to appending the username to the base directory, which is /home by default. And I'd probably go with option three if I were setting up a system with a separate user per site. Makes the most sense to me. For my personal setup where I host myself and a few friends I just created separate users for the different people I host then symlink their sites in /var/www in their normal home directory. Each user has their own PHP-FPM pool and all their sites use their pool.
  10. As an example of a simple but fairly effective solution, my contact form just has an input labeled "Secret Code" and instructs the user to type "nospam" in that field. <div> <label for="secretCode">Secret Code:</label> <input type="text" name="secretCode" id="secretCode" placeholder="Type nospam here"> <br>Type "nospam" above. </div> In your script, just check that the user typed the correct value in the field and show an error if not. $errors = []; //Other validation stuff. if ($_POST['secretCode'] != 'nospam'){ $errors[] = 'You did not enter the correct secret code.'; } if ($errors){ echo "Your message could not be sent because some errors were discovered in the information you provided. "; echo "\r\n"; foreach ($errors as $e){ echo "\r\n* {$e}"; } echo "\r\nPlease click back in your browser, correct the errors and try again."; exit; } I would also suggest you look into an emailing library rather than use the mail function directly. The libraries will help with the other security issues mentioned by properly constructing the headers and other data related the email with the inputs you provide. I'm a fan of Swift Mailer (now Symfony Mailer), but there are others you could try as well.
  11. The intent is to essentially create a single instance script, similar to single-instance applications on the desktop. If you try and launch a second instance, it detects the first instance and either doesn't run or does something different. One possible scenario for this is if you have some cron job that runs every minute. If for some reason it takes longer than a minute to run, sometimes it's easier to just prevent the second instance from starting than to write the scripts in such a way that they don't cause problems. @peter844, assuming that is an accurate description of your goal, file_exists is not really the correct way to solve the problem. If you actually ran both scripts at the exact same moment, it's possible for them both to pass the file_exists test before either of them has a chance to actually create the file. A better solution is to use fopen with mode x flag to create the file. In this mode, fopen will fail if the file already exists, or create the file if it does not. Your script can use that to determine if the other instance is already running. Example: $lockFile = __DIR__.'/monkey.tmp'; $fp = @fopen($lockFile, 'x'); if (!$fp){ die('Script already running.'); } register_shutdown_function(function() use ($fp, $lockFile){ fclose($fp); unlink($lockFile); }); An even better solution, is to use flock to obtain an exclusive lock on the file. If the lock cannot be obtained then that means there is a script still running holding the lock. Example: $lockFile = __DIR__.'/monkey.tmp'; $fp = @fopen($lockFile, 'c'); if (!$fp){ die('Unable to access lock file'); } if (!flock($fp, LOCK_EX|LOCK_NB)){ die('Script is already running.'); } register_shutdown_function(function() use ($fp, $lockFile){ flock($fp, LOCK_UN); fclose($fp); unlink($lockFile); });
  12. Make sure that your regex is correctly matching the end of the output. Sounds like your connection is stalling out because it doesn't detect the end of the output and ends up looping until it hits the script timeout. In addition to the regex, you could add another test that $line contains some data. That should break the loop if fgets times out due to no data to read. do { $line = fgets($this->fp); $r .= $line; } while ($line && !preg_match('/\d{1,4} Bridge Interfaces displayed/', $line));
  13. A remote server will not have access to your local file system, so no you cannot have your remote PHP script copy files to your local system.
  14. I started with PHP somewhere around 2000 or 2001, don't remember exactly when. I was still in high school at that time so I don't know if I'd qualify as an "old fart" though.
  15. This is pointless the way you have it: $file=basename($_GET['f']); $file=__DIR__.'/download/'.$file; You're still using $_GET['f'] when you call the function below. You need to change it to use $file. if (!file_exists($file)) { die; } else { //... } While it's fine to have it, you don't need the else block here since the if branch will cause the script to end. The code is cleaner looking without it IMO.
  16. No, as noted in my reply: The XModem protocol for sending wouldn't be too hard to implement, just as receive wasn't. What would be more difficult is dealing with the serial connection to your device. You'd likely have to create a script that can connect to your device and issue whatever commands are necessary to get it ready to receive. That would be a more complex task and likely have to be tailor made to your device. I don't think it's impossible to do, PHP is capable of dealing with serial connections. I simply don't currently have any xmodem capable serial devices to mess with (did the receive bit over ssh), nor do I really have much free time to continue messing with it.
  17. Flip your if statement so that it checks if the file does not exist and if that is true, exit. if (!file_exists($l_filename)){ exit; } //... While testing, it's easier if you use text files, then you can easily see the results and any potential errors directly in the browser. Once you have it working with the text files you can try binary files. As mentioned before, you also need to validate the filename selected or someone could use your code to download any of your files, not just the ones you intend. If you want to only allow the files within the folder to be downloaded, then you could use basename so the user only inputs a file name and not a directory, then combine that with __DIR__ to make a full path. $file=basename($_GET['f']); $file=__DIR__.'/'.$file;
  18. I was interested since I've actually used Xmodem a couple times in the last year. Implementing the protocol was easy enough, figuring how terminal settings to make it actually work was more of a pain. It's not pretty, but here's a receive implementation (with the help of this crc library) <?php class XModem { const SOH = "\x01"; const EOT = "\x04"; const ACK = "\x06"; const NAK = "\x15"; const CAN = "\x18"; const C = "C"; private $channel; private $channelBuffer; private $outFile; private $lastPacketData; /** * @param resource $channel * @param resource $file * * @return void */ public function receive($channel, $file){ $this->channel = $channel; $this->outFile = $file; stream_set_blocking($channel, false); $lastPacketNumber = 0; do { $packet = $this->readPacket(); if (!$packet){ if ($lastPacketNumber === 0){ $this->writePacket(self::C); } else { $this->writePacket(self::ACK); } continue; } if ($packet[0] === self::SOH){ $packetNumber = $this->packetNumber(substr($packet, 1, 2)); $data = substr($packet, 3, 128); $receivedCRC = substr($packet, -2); $calculatedCRC = $this->calcCRC($data); if (($packetNumber === $lastPacketNumber + 1 || $packetNumber === 0 && $lastPacketNumber === 255) && $calculatedCRC === $receivedCRC){ $lastPacketNumber = $packetNumber; $this->updateReceiveFile($data); $this->writePacket(self::ACK); } else { $this->channelBuffer = ''; $this->writePacket(self::NAK); } } else if ($packet[0] === self::CAN){ $lastPacketNumber = 0; fseek($file, 0); ftruncate($file, 0); $this->writePacket(self::C); } else if ($packet[0] === self::EOT){ $this->finishReceiveFile(); $this->writePacket(self::ACK); } } while (!feof($channel) && !$packet || $packet[0] !== self::EOT); } private function updateReceiveFile($data){ if ($this->lastPacketData){ fwrite($this->outFile, $this->lastPacketData); } $this->lastPacketData = $data; } private function finishReceiveFile(){ fwrite($this->outFile, rtrim($this->lastPacketData, "\x1a")); } private function readPacket(){ $packetType = $this->readChannelBuffer(1); if ($packetType === self::SOH){ $pn = $this->readChannelBuffer(2); $data = $this->readChannelBuffer(128); $crc = $this->readChannelBuffer(2); $packet = $packetType . $pn . $data . $crc; } else { $packet = $packetType; } return $packet; } private function readChannelBuffer($length){ $startTime = time(); while (strlen($this->channelBuffer) < $length && time() - $startTime < 10){ if (!$this->bufferInput()){ usleep(100); } } $data = substr($this->channelBuffer, 0, $length); $this->channelBuffer = substr($this->channelBuffer, $length); return $data; } private function bufferInput(){ $byteCounter = 0; do { $r = [$this->channel]; $w = $e = []; $readable = stream_select($r, $w, $e, 0, 0); if ($readable){ $dataRead = stream_get_contents($this->channel); $byteCounter += strlen($dataRead); if ($dataRead){ $this->channelBuffer .= $dataRead; } } } while ($readable); return $byteCounter > 0; } private function writePacket($data){ $total = strlen($data); $written = 0; do { $dataToWrite = substr($data, $written); $written += fwrite($this->channel, $dataToWrite); fflush($this->channel); } while ($written < $total); } private function packetNumber($pnBytes){ $n1 = ord($pnBytes[0]); $n2 = ord($pnBytes[1]); if ($n1 + $n2 !== 255){ return null; } return $n1; } private function calcCRC($data){ $o = new mermshaus\CRC\CRC16XModem(); $o->update($data); return $o->finish(); } } Requires some terminal setup to work properly. I eventually included this code in my test script to fix terminal problems, but it creates it's own problems (can't ctrl+c the script). system('/usr/bin/stty -cooked -echo'); register_shutdown_function(function(){ system('/usr/bin/stty cooked echo'); }); I'll leave implementing send and other improvements for the reader.
  19. Protocol seems simple enough, you could probably create an implementation of it without a lot of work.
  20. Yea, It's briefly noted in the documentation for the Iterator class. I first noticed this behavior when working with FilterIterator. Seems kind of strange and dumb to me, but oh well.
  21. You could just read the results into an array, then use that for your two loops. $query = "SELECT colname FROM table"; $result1 = $db->SelectLimit($query,10,-1); $resultData=[]; while (!$result1->EOF) { $resultData[]=$result1->Fields('colname'); $result1->MoveNext(); } // 1ST RUN foreach ($resultData as $colname){ echo $colname.'<br>'; } // 2ND RUN foreach ($resultData as $colname){ echo $colname.'<br>'; }
  22. Yes, you can use variables in your path, so you could define a separate prefix for each environment. However, usually it's easier to use the built in __DIR__ constant and build a path that's relative to the current file. For example: include(__DIR__.'/my_file.php');
  23. If you install it on the target system with composer, then composer will install whichever version of the package is compatible automatically, just make sure you have your version constraint for the package setup correctly. If you're trying to pre-package a release and want to make a 5.6 version and 7.1 version, you could have both version of PHP installed and run composer with the appropriate version.
  24. You have output before the session_start call. Probably blank lines before your <?php tag. Remember, anything outside of php tags is output sent to the browser, even blank lines/spaces.
  25. if($subject='') { $error_message .= 'You must select a Category.<br />'; } This is incorrect code, as you're assigning an empty string to $subject rather than comparing to one. The if won't trigger because an empty string is a false-like value, but your subject will be blank in the email. You need to use double-equals (==) for comparison. if(($subject)!=('Questions'||'Report Problem'||'Suggestion'||'Other'||'Website Problem')) { $error_message .= 'The Category you entered is invalid.<br />'; } This is incorrect code, as you cannot compare against multiple values in that way. If you wanted to test against multiple values, you need to repeat the variable name and condition for each one, as in: if ($subject != 'Questions' || $subject != 'Report Problem' || ...){ That would be correct code, but incorrect logic as it would end up being always true. If $subject == 'Questions', then it's != 'Report problem' and the condition is true. Likewise, if $subject == 'Report Problem', it is != 'Questions' and the condition is true. The correct logic would be to use and (&&) as in if ($subject != 'Questions' && $subject != 'Report Problem' && ...){ Alternatively, in this type of situation, you can use the in_array function and check against an array of values. This is shorter and more similar to your original code. if (!in_array($subject, ['Questions', 'Report Problem', ...])){ Finally, $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } While this is not incorrect like the others, it's generally recommended to not try and validate a persons name (beyond something like maximum length / not blank). There's really no specific format for a persons name to validate against, and doing so means you'll always end up eventually telling someone that their name is not valid.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.