Jump to content

kicken

Gurus
  • Posts

    4,695
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by kicken

  1. If you want to change the session cookie parameters, you need to do so before you call session_start(), not after.
  2. 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?
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. Try $stmt->bindParam(':fileContent', $fileContent, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
  12. 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.
  13. 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.
  14. 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.
  15. $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).
  16. 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.
  17. Why? You set the action as StoreTrue, which if you look at the documentation, Adding the flag multiple times just stores the value true multiple times. There's no such thing as "more true" and "even more true". If you keep reading that documentation, you'll find there's a different action type Counter which is what you want. It is documented as: The shown example is exactly what you are trying to do.
  18. According to the error, your code is calling $pdf->stream('example.pdf', 'I'); But if you check the Dompdf library code, you can see that the second argument to the stream function is supposed to be an array. What you want to do is pass an array with the key Attachment set to false.
  19. I'd suggest using the same markup with the radio buttons as the example. Just setup your secondary image display instead of using the borders. Updating the secondary image needs to be done with JavaScript, but it a relatively simple change event listener for the group of radio buttons. window.addEventListener('DOMContentLoaded', () => { const preview = document.getElementById('changeToPreview'); document.querySelector('.color-chooser').addEventListener('change', (e) => { const input = e.target; const img = input.parentElement.querySelector('img'); preview.src = img.src; }); }); Updated example.
  20. The radio buttons do not have to be visible, you can hide them and just have a label (which is your image) activate the associated radio. I put together an example. <input type="radio" name="color" value="black" id="black"> <label for="black"> <img src="black.png" alt="black"> </label> You can use CSS to display a border around whichever image is selected, and if you add a class to indication the current one, use a different border to indicate the current item. In my example above, the selected item has a white border, the current has a yellow border.
  21. Are you set on doing it this way? You could instead use a set of radio buttons with a highlight around the color selected and eliminate the need for JavaScript.
  22. There are no internals of spl_autoload_register with regards to the locating and loading of a class. All the details of how that is done is up to the function you provide. All spl_autoload_register does is add your function to a list of functions that get called when an unknown class is referenced. Your function gets the fully qualified name of the class and has to use that to define that class, typically by converting the name to a file location and including that file. Your example essentially just uses the class name as-is as a file path and attempts to include that file. Since your class is defined as Hello then you get a filename of Hello.class.php with a capital H. Your actual filename however seems to be hello.class.php with a lower-case H. On a case-insensitive filesystem such as windows' ntfs, this would be fine and the file would be loaded. On a case-sensitive filesystem such as linux ext4, this is a problem and the file will fail to load. As mentioned, typically one would just use composer to handle class autoloading rather than defining your own function. Combine it with the PSR-4 standard (and ensure you get your case correct) and you mostly don't have to think about it at all.
  23. Some filesystems are case-sensitive, so Hello.class.php and hello.class.php are two completely separate files. You need to either ensure you are using the correct case when creating and referencing your files, or normalize the case in some way (such as making everything lowercase).
  24. I don't understand what it is you're saying is wrong. You should create a fiddle that reproduces the problem and post the link. Then re-describe the problem, optionally with screenshots if you can't describe it well. Your HTML is currently invalid due to a missing quote, you should fix that as well.
  25. Been a long time since I used a positioned popup window. Had to check the docs for the right options. You can center the popup on the screen by setting the top / left options. These control the top-left corner of the window, so to get it truly center you have to calculate the right offset. There's a standard formula for this. centerPoint = (sizeOfContainer - sizeOfThing) / 2 For this case, your sizeOfContainer is the screen width/height and the sizeOfThing are your popup window's width/height. Run that formula for each to get your top/left values and set them in the window options. const popupWidth = 400, popupHeight = 800; let top = (window.screen.height - popupHeight)/2; let left = (window.screen.width - popupWidth)/2; const win = window.open('', 'formpopup', 'width='+popupWidth+',height='+popupHeight+',resizable,scrollbars,top='+top+',left='+left); The final result may be slightly off (mostly in the height axis) due to the window UI elements since they are not part the calculation. The width/height you specify is for the content area of the window, the UI elements are added on top of that. If the slight offset bugs you, you can fix it after opening the window by re-calculating the offset using the window's outerWidth and outerHeight values for sizeOfThing, then using it's moveTo function to re-position it. top = (window.screen.height - win.outerHeight)/2; left = (window.screen.width - win.outerWidth)/2; win.moveTo(left, top); That may create a noticeable jump after the window opens though.
×
×
  • 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.