Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. In the ye olden times, yes. In the modern times, the solution to your undefined index issue is much simpler, the Null Coalescing Operator: $arMine["NoField"] ?? ''; It might be a bit tedious to go through the code, but it's not a difficult change to make. Take the file and line number from any warnings you see, go to that location and implement the null coalescing operator. Repeat until you have no more warnings.
  2. The clients you use to access a system, particularly a web based system, are not in any way indicative of the technologies being used to host and serve that system. A 'nix based server stack is far more popular than a windows based one. Remote desktop is a method of access the server to perform tasks (install/update software, troubleshoot issues, etc). Servers are often headless (meaning there is no monitor/keyboard/mouse attached) and remote so a person can't just go sit down at the server and login to it like you would your desktop or kiosk. That means you need a way to connect to it remotely to do certain tasks and remote desktop is the common way of doing that in a windows environment. 'nix based servers typically use SSH. VNC is another alternative. Virtual machines are not "on the server", rather they "are the server". It's common these days to run servers in a virtual environment rather than a single piece of dedicated hardware. This is where the Hypervisor comes in as well. The hypervisor is what runs on the dedicated hardware and provides the virtualization environment. The individual servers are then created as virtual machines within that virtual environment. It's easier to isolate systems and services this way. Before virtualization you either needed to have separate dedicated machines for each system/service or you'd get a single high-spec machine and try and run everything on that single machine. Separate machines for each service gets expensive both in terms of hardware cost and physical space costs. A single system is harder to maintain and any software issues might take down your entire set of services. Virtualization allows you to get the single high-spec machine to minimize cost, while keeping isolated software environments so issues with one service don't interrupt other services.
  3. You can use target on a form tag also. <form method="post" target="_blank"> <input type="submit"> </form>
  4. The server software you use is not that relevant to developing in PHP. Installing and configuring PHP itself to run will vary based on the server software, but once that is done, your scripts run the same regardless of the server. I do all my local development work using Apache, but the production site is hosted on IIS. The PHP code is all the same, there's nothing in it that cares which server software is being used. The server configuration required to get PHP installed and running, and to configure specific things needed by the site vary between the two of course. For example, IIS doesn't understand .htaccess files, it has it's own web.config file for dynamic site configuration settings. The way the domain and document roots are setup is different as well, but that's general server administration stuff and not PHP specific. For that information you'd just find IIS or Apache documentation / tutorials. If your goal is just to learn PHP, then you'd probably have an easier time just setting up apache since a lot of documentation references it. If your goal is to learn IIS, then seek out IIS documentation in general rather than IIS+PHP specific stuff.
  5. Assuming you start with a new, empty directory, running composer require phpoffice/phpspreadsheet would give you output like this: keith@keith-framework:~/Workspace/Demo$ composer require phpoffice/phpspreadsheet ./composer.json has been created Running composer update phpoffice/phpspreadsheet Loading composer repositories with package information Updating dependencies Lock file operations: 9 installs, 0 updates, 0 removals - Locking ezyang/htmlpurifier (v4.16.0) - Locking maennchen/zipstream-php (3.1.0) - Locking markbaker/complex (3.0.2) - Locking markbaker/matrix (3.0.1) - Locking phpoffice/phpspreadsheet (1.29.0) - Locking psr/http-client (1.0.2) - Locking psr/http-factory (1.0.2) - Locking psr/http-message (2.0) - Locking psr/simple-cache (3.0.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 9 installs, 0 updates, 0 removals - Downloading psr/simple-cache (3.0.0) - Downloading psr/http-message (2.0) - Downloading markbaker/matrix (3.0.1) - Downloading markbaker/complex (3.0.2) - Downloading maennchen/zipstream-php (3.1.0) - Downloading ezyang/htmlpurifier (v4.16.0) - Downloading phpoffice/phpspreadsheet (1.29.0) - Installing psr/simple-cache (3.0.0): Extracting archive - Installing psr/http-message (2.0): Extracting archive - Installing psr/http-factory (1.0.2): Extracting archive - Installing psr/http-client (1.0.2): Extracting archive - Installing markbaker/matrix (3.0.1): Extracting archive - Installing markbaker/complex (3.0.2): Extracting archive - Installing maennchen/zipstream-php (3.1.0): Extracting archive - Installing ezyang/htmlpurifier (v4.16.0): Extracting archive - Installing phpoffice/phpspreadsheet (1.29.0): Extracting archive 9 package suggestions were added by new dependencies, use `composer suggest` to see details. Generating autoload files 1 package you are using is looking for funding. Use the `composer fund` command to find out more! No security vulnerability advisories found Using version ^1.29 for phpoffice/phpspreadsheet And you would end up with a directory structure like: Running in your existing /var/www/html/STG folder, you should see the same output, with the same folders mixed in to your existing stuff. If you're getting some other output, then posting the output would help determine the issue.
  6. It is generated by composer once all your dependencies have been installed. It appears you may not be familiar with composer, so you should probably take some time to read it's documentation and get familiar with it and how it works. These errors mean that your PHP installation is missing extensions that are required by the phpoffice/phpspreadsheet package. Specifically, you must install the DOM Extension, SimpleXML extension, XML extension, XML Reader extension, XML Writer extension, and ZIP extension. If you obtained PHP through your systems package manager, it will probably also have packages for these extensions that you need to install. You'll have to do some research on your particular package manager to find out what these packages are and get them installed.
  7. You don't specify a filesystem path when you use a class, you specify it's namespace path. use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; As shown in the documentation example. You also need to include the autoload.php file (again, see the example) or the class will not get loaded.
  8. The documentation says you can combine using |. Throwable&Err is redundant anyway. Anything that is thrown must implement throwable, so just specifying Err is all you need.
  9. Yes, which is why I wouldn't worry about the whole having to load a class thing. Chances are it'll be cached, either in the opcache or filesystem cache so it's not a big deal. If your enums are related to just one class, then you could just define them in the same file as that class, but then you end up with potential auto-loading issues if you later decide you want to use the enum without using the associated class. In the past, whenever I have enum like constants, I have generally always defined them in their own class (and thus file) anyway, so transitioning to a proper enum isn't much of a change. Regarding enum vs constant, I will use a constant when it's use is generally limited to just that class, either strictly internally (in which it's a private constant) or only as a parameter to methods on that class. I'll use an enum if the usage might extend across various classes or be used outside of a class (ie, a method returns one of the enum values).
  10. If you want to change the session cookie parameters, you need to do so before you call session_start(), not after.
  11. Your code doesn't show you doing anything with the response, so how do you know you're not receiving the data in your script?
  12. If you're talk about the new one linked by Requinix, you'd use the build configuration option. You provide a function, the script calls that function when it's time to display the menu. You can dynamically build your items in the function and return them in the items configuration option.
  13. IIS has various timeout settings. If this is a large import, you shouldn't be doing it through a web interface like phpMyAdmin, long running requests don't usually work out well. You'd be better off using the command line tools to do the import or a tool like MySQL Workbench that can connect directly to the database and run the import.
  14. Your JavaScript code doesn't involve a request at all, other than the one to initially load the page which is going to be a standard stateless HTTP request. The only stateful protocol you would possibly end up using in JavaScript code is a WebSocket. The rest of the web revolves around stateless HTTP requests. That blog post has less to do with HTTP and more to do with applications. HTTP is stateless, but most web applications are not as they rely upon session data to track who is logged in or other details. That session data makes the application as a whole stateful even if the individual HTTP requests are not.
  15. If it's not working correctly for you, then you have some other issue besides just your syntax. Maybe your data is not what you think it is, or your condition is not correctly defined. The code correctly identifies data where the message contains 'And Click' and the view spec is no.
  16. The syntax of an if statement looks like this: if (some condition){ //do stuff } The some condition part could be a single comparison, or multiple comparisons joined with logical operators. Note though, how there needs to be a set of parenthesis surrounding the entire condition. Now, look at your attempt: if (strpos($row["message"], 'And Click') == true) && ($viewspec_pref == "no") { You have your two conditions combined with the logical AND operator. What you're missing through, is the parenthesis that surrounds the entire combined condition. Instead, you put parenthesis around the individual conditions (which is ok, but unnecessary). Add the required parenthesis around the entire condition and you'll have something that is syntactically valid. It is a potential issue. The solution, which was never really pointed out, is that you need to strictly compare against false to determine if a match was found or not. Using a loose comparison against true will fail if your message starts with the target string (since strpos would return zero, and zero is falsely). if (strpos($row["message"], 'And Click') !== false && $viewspec_pref === "no") { It can generally be worth getting in the habit of using the strict comparison (identical) operators whenever possible, as it helps avoid such surprise outcomes. If you are using PHP 8.0 or better, you can avoid this whole problem by using str_contains instead.
  17. I always figured it was just a convenience thing so you could either access the data by key or via list() without having to mess with the fetch mode.
  18. The point is that when it comes to things like names, the difference between junk and not junk is hard to define, and you're often better off just not even trying. Better to accept a few junk records than to tell someone their real legal name is not valid. If you want to provide some filtering, you need to be a lot more permissive than you currently are. Your regex for example would be telling Ms Bérénice Bejo that her name is invalid. We had an issue with a public request information form with a bunch of junk submissions, particularly name fields including Emoji characters. What I ended up doing was applying a filter that checked the Unicode code point for each character in the name to ensure it was within a particular set of allowed unicode characters. The sets of allowed characters I went with is pretty broad. There's still plenty of opportunity for junk, but it does stop quite a bit of junk. function validate_unicode_codepoints($allowedRanges, ...$strings) : bool{ foreach ($strings as $str){ $chars = mb_str_split($str, 1, 'utf-8'); foreach (array_map('mb_ord', $chars) as $codePoint){ $isInRange = false; foreach ($allowedRanges as $range){ $isInRange = $isInRange || $codePoint >= $range[0] && $codePoint <= $range[1]; } if (!$isInRange){ return false; } } } return true; } The parenthesis on their own do not change things, but the * after them does. * means "match the previous expression 0 or more times". The parenthesis are "previous expression", which allows for between 1 and 48 occurrences of the indicated characters. So your overall expression then would allow 0 or more instances of between 1 and 48 characters. Effectively, a string of unlimited length so long as it matches the character list.
  19. When working on a regex, it helps to use something like Regex101 so you can easily test and modify your expression. If what you are trying to validate is names of people/places, it's generally best to not bother as names are complicated. I just check a maximum length for such things to ensure it fits in the database column.
  20. Try $stmt->bindParam(':fileContent', $fileContent, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
  21. You need to change your approach, and stop using onchange="" attributes on your fields. Notice how in order to make your remove link work, you bound your event to the body rather than the actual remove link? $("body").on("click", ".remove", function() { $(this).parents(".eventGroup").remove(); }); //remove fields group You need to do the same sort of thing with your change event. Bind it to a parent element, then get the element that triggered it in the event handler. The event handler is passed an event object which has a property called target which will be a reference to the element which triggered the event. You can use that to obtain the input, then check which type of input it is by checking for your various classes. $('form').on('change', checkFormOK); function checkFormOK(event) { //Get the input which triggered the change event. const input = $(event.target); //If the input has class n if (input.is('.n')) { // process the names. if (input.val() === '') { input.addClass('formError'); } else { input.removeClass('formError'); } } //If the input has class p if (input.is('.p')) { // process the prices. } //If the input has class s or class e if (input.is('.s, .e')) { // process the dates. } } Full example.
  22. If you want to explore other mapping options, Leaflet is a free interactive mapping library like google maps. You can also use it with just a static image if you want. Create the leaflet map with your base map image, then you can pull your marker locations from your database and add them to the map.
  23. Hm, so they do. I could have swore I used that trick in the past, but maybe I just did one regular and one private window. In any case, JMeter doesn't use the browser so there's no problem using it to run requests as multiple users if that's the goal. Each test thread can have it's own session state and thus user. Definitely an X/Y problem here.
  24. $test_score = $_POST['test_score'][0]; $exam_score = $_POST['exam_score'][0]; if(empty($test_score)) { $error['test_score'] = "Test Score Field is Required"; }if(empty($exam_score)) { $error['exam_score'] = "Exam Score Field is Required"; } You are only checking the first input with that code. Since your form can contain multiple inputs for those fields, you need to check all of the inputs if that is what you want to require. Here is an example for one of the inputs: $allEmpty = true; foreach ($_POST['exam_score'] as $input){ $allEmpty = $allEmpty && empty($input); } if ($allEmpty){ $error['exam_score']='Exam score is required.'; } Ideally, you would also validate that the input is numeric (see ctype_digit) as well. Using input type=number does not guarantee the input will be numeric (no client-enforced rule is guaranteed).
  25. If you want to be able to login multiple times for testing, use private browsing windows. Each private browser window will have it's own session.
×
×
  • 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.