Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. No, it does not. PHP doesn't do CORS. You can make whatever request you want to whatever destination you want with PHP. CORS is something implemented by browsers to restrict JavaScript's ability to create requests, it has no affect on server-side requests like those made from PHP, Python, NodeJS, etc.
  2. I don't think their API works like a traditional one where you just hit a URL. They seem to open a websocket connection to a server and then issue requests to it for the API. You would probably have to re-implement that in PHP, which would probably just have to be done by reverse engineering their code. Searching packagist shows one package that might already do this: https://packagist.org/packages/sergix44/gradio-client-php. You could try that package first. Otherwise, the easiest thing to do might be to use either their python or JS packages to make a script that does what you need, then interface with that script using PHP.
  3. Seems like you're outputting both HTML content and your exported CSV in the same request. You cannot do that. Whatever request is being made to export the CSV data needs to only output that CSV data, no HTML content.
  4. Look at the documentation for getAttributes(). There is a flags parameter which is where you use the IS_INSTANCEOF constant.
  5. Your code isn't that far off. imap_sort gives you a list of message numbers after the sorting has been applied. You have that list split into pages using array_chunk. Take the page you want and fetch those messages. The second parameter to imap_fetch_overview is how you specify the messages you want to fetch, and documented as: So to fetch arbitrary messages, specify them as a comma-separated list of message numbers. To do that, you can just implode your page of numbers that you get from the array_chunk result. There is a lot of stuff in your listMessages function that is not necessary and can be removed. After cleaning up the function and adding the call to imap_fetch_overview, the function would look like: function listMessages($inbox, int $page, int $perPage) : array{ $sorted = imap_sort($inbox, SORTDATE, 1); $pageList = array_chunk($sorted, $perPage); $messagesToFetch = implode(',', $pageList[$page - 1]); $details = imap_fetch_overview($inbox, $messagesToFetch); return array_reverse($details); } You can then use it to fetch a page of messages and display the summary info. $messages = listMessages($inbox, $page ?? 1, 25); foreach ($messages as $item){ $number = $item->msgno; $date = $item->date ?? 'Unknown'; $subject = $item->subject ?? ''; printf("[%d] %s - %s\r\n", $number, $date, $subject); }
  6. Your analyzePage function is not returning a value, so your $analysis variable will be null. If you have PHP's error reporting turned up all the way, and are on a modern version of PHP, you should be seeing a warning about not being able to use foreach on a null value. On an unrelated note: This could simply be return $content; There is no need for the check against false there since if it is false, you will just return false.
  7. You don't, because such a thing doesn't make sense to do. How about you describe the problem you think this will solve? Sounds like maybe what you want instead is either a sequence or an identity column.
  8. PHPSpreadsheet uses a lot of memory, about 1.6KB per cell according to the docs. If I did my math right, you spreadsheet contains just over 2.3 million cells, meaning it will require roughly 3.7 Gigabytes of memory just to load the data in the cells. Even more for the various other things your script is going to be doing. The documentation linked above talks about ways you can implement a cache to try and conserve memory. You can also adjust the settings to load only data and apply a filter to control which data is loaded. The best option, in my opinion though, is to abandon trying to read actual excel files and instead generate and read CSV files. You can easily convert your worksheet to a CSV by opening it in Excel and re-saving it as a CSV, then upload that to your import script. You can then read this CSV file line-by-line and only use as much memory as a single line requires.
  9. Accept the incoming data using the appropriate superglobal variables, then use the header function to output a Location header to the desired URL. Your current form is formatted well for this, so first you'd want to change it to give your select box a meaningful name, and remove your hidden input as it is not necessary. $result = mysql_query($sql); echo " <form id='myForm' action='https://mywebsite.com/forum/index.php'> "; echo '<select name="city">'; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['field_181'] ."'>" . $row['field_181'] ." - " . $row['COUNT(field_181)'] . " Events </option>"; } echo " </select> "; echo " <br><br> "; echo " <input type='submit'> "; echo " </form> "; Then in your index.php file, you need code to detect if the city input was submitted and if so, issue the redirect with header. if (isset($_GET['city'])){ $url = '/forum/index.php?/'.urlencode($_GET['city']).'-bowling-tournaments/'; header('Location: '.$url); exit; } I don't see much point in doing this though. If you want pretty URLs you should use URL rewriting or a Router library. Otherwise, just use normal query parameters/form posts. Pretty URLs are not necessary, they are just a nice touch.
  10. Why do you think that? That is not how forms work. Form data is submitted in name=value pairs, each pair separated by an &. What you're getting is exactly what you should be getting. If you want the other URL format, then you need to either Write JavaScript code to read the form and redirect to the desired URL or Accept the standard format form data with your PHP code, and issue a redirect based on the submitted data.
  11. This is where the misunderstanding of what attributes are and are for seems to come in. Attributes apply to the class itself. The only way to make a connection between a specific instance of a class and that classes attributes is when you use reflection on the instance to look up it's class and associated attributes. This process only works one way: instance -> class -> attributes. You cannot go backwards the other way: attribute -> class -> instance.
  12. I think you might be misunderstanding the purpose of attributes. It's not clear what you're trying to do though. If you need to access the instance of an object tagged with an attribute from within the attribute, you need to pass it in after the fact by calling some method on the attribute object. For example: <?php interface Target { public function something(); } #[Attribute] class Attr { public function doSomething(Target $target){ echo "Calling something method on ", get_class($target), PHP_EOL; $target->something(); } } #[Attr] class Target1 implements Target { public function something(){ echo "Did something in test 1 target.", PHP_EOL; } } #[Attr] class Target2 implements Target { public function something(){ echo "Did something in test 2 target.", PHP_EOL; } } if (class_exists($argv[1])){ $target=new $argv[1](); $reflection = new ReflectionObject($target); $attributes = $reflection->getAttributes(Attr::class); foreach ($attributes as $attribute) { $attr=$attribute->newInstance(); $attr->doSomething($target); } } else { echo 'No such class', PHP_EOL; } You'd get better help if you explain what you are trying to do and why, rather than just paste some code with a vague description.
  13. You are joining it to your items table though, implying that any items in the consumable table must also exist in the items table. You also say you only need the item names for your list, but your screenshot of the consumable table shows it doesn't store any name information. So what information do you need out of that table? Do you just need to know if a row exists in the table for the isConsumable flag? If you only one row from your consumables table, you need to define the criteria that will choose that row. Just throwing in a "group by" clause is not a correct solution. If you just need to know if a row exists, you'd get a count() of the relevant rows and check that it's > 0.
  14. From a little searching, this seems like something that was a compatibility issue between older PHP versions and newer Mysql versions. Are you sure your code has been updated to run on PHP 8? Shouldn't be an issue on PHP 8 as far as I can tell. Unless you need to do something with your hosting control panel to update your PHP version, this is something that you might have to get your host's support involved in to get fixed.
  15. I don't understand why you're involving this consumable_price table if you don't care about the information within it. Since you're joining it to your items table, then presumably all the item names are in the items table and if you only want their names, then you can just select from that table by itself. SELECT qs.name as sectionName, qi.id as itemId, qi.name as itemName, qs.display_order as display_order from items qi inner join quote_sections qs on qi.section_id = qs.id union all select qs.name, ci.id, ci.name, qs.display_order from custom_item ci inner join quote_sections on qs on qs.id = ci.section_id order by display_order, itemName
  16. What is the point of your WITH component? A select * query with group by doesn't really make any sense. If you're going to be grouping rows, your query should contain some aggregate function. Seems like you should be able to remove the WITH component entirely and join consumable_price directly.
  17. The error you are getting has nothing to do with Mysql. It's a PHP error caused by trying to pass the wrong type of variable to a function. You'd get a similar error if you did something like: $variable = 'Hello, World'; echo array_reverse($variable); Your query has a problem, so the mysqli_query function returns a boolean false value to indicate that the query failed. You're taking this value and passing it to mysqli_num_rows which is expecting a valid query result as it's parameter, not a boolean false. By turning off the error reporting, you are now responsible for checking if your queries have failed or not and proceeding accordingly. So the solution is either to stop turning error reporting off, or add code that checks if mysqli_query failed and returned false.
  18. I'm not sure why there is a difference, but swapping the order of your alternatives seems to fix it. preg_match('/(^|[^\.])\s*a/', "a", $matches);
  19. That is expected. In that code, the //// is a single-line comment in the final JavaScript code, your PHP code is unaffected by that. Your PHP script would end up outputting something like this: ////var array = [ {"some":"json"}, {"more":"json"} ]; Note only the first line is commented, the rest remains live and causes a syntax error. Adding the additional comment in the PHP tags prevents PHP from outputting the JSON value so you end up with the output: ////var array = ; Which is successfully commented out by the single-line JS comment.
  20. It's a lot like using relative file paths rather than absolute paths in your PHP code or HTML links. Rather than trying to reference everything with an ID and getElementById, you instead reference elements relative to other elements using things like parentElement, nextElementSibling, previousElementSibling, querySelector, etc. You can usually reference some parent element (either by ID or a class name) then locate child elements either via their position in the HTML structure or class names. Without knowing what your HTML is, I can't provide and specific recommendation. Here is an example though: window.addEventListener('DOMContentLoaded', () => { const list = document.getElementById('option-list'); list.addEventListener('change', (e)=>{ const checkbox=e.target; const description=checkbox.parentElement.nextElementSibling; description.style.display=checkbox.checked?'block':'none'; }); }); Paired with the HTML <ul id="option-list"> <li> <label><input type="checkbox"> Test option 1</label> <div class="description">Some description for option 1</div> </li> <li> <label><input type="checkbox"> Test option 2</label> <div class="description">Some description for option 2</div> </li> <li> <label><input type="checkbox"> Test option 3</label> <div class="description">Some description for option 3</div> </li> <li> <label><input type="checkbox"> Test option 4</label> <div class="description">Some description for option 4</div> </li> </ul> The JavaScript code only references the parent list element by and ID and listens for a change event on it (which will be triggered by a change in any child). When that change event is triggered, the input element that triggered it can be references using e.target. Looking at the HTML structure, the div that should be shown/hidden is a sibling to the inputs parent, so a reference to it can be obtained by first getting the input parent (parentElement) then it's next sibling(nextElementSibling). With this code, you can add as many <li> elements following that structure as you want and they will all work. No need to generate unique IDs for each and add custom event handlers to each one. For exactly the reason you created this thread, and more. ID's must be unique, so if you have some repeating structure you need to find some way of generating unique IDs and reference those IDs in your code. Often times, using class names or other more natural references are better and avoid these issues.
  21. I have no idea what you mean by exit the JSON, that phrase doesn't make any sense. JSON isn't some running code that you exit out of, it's just a data structure. Dumping an array into a script block as JSON can work, though I generally prefer to dump the json into a data-* attribute and then use JavaScript to extract it, as that is less likely to cause your code to break or leave you open to a XSS attack. You might not have to dump your array into your JavaScript at all if your generating a repeating HTML structure for each array entry. You could just have your JavaScript code work with the structure rather than having to use getElementById with different ID values. In general, IDs are something best avoided if possible, especially for anything where you need multiple instances of it.
  22. The answer you found on stack overflow is incomplete. In addition to redirecting the output, you need to actually put the operation into the background by including an & at the end. exec("scp -o StrictHostKeyChecking=accept-new -i /var/keys/devDevices_rsa MarTianez1.mp4 awong@10.1.1.16:/tmp/test1 2>&1 > out.log &", $output, $exitCode); This will just kick off the process and move on. You won't have any way in your code to determine if the process completes successfully or not. You'd only be able to detect if there is an error in the shell that prevented the command being run (syntax error, exec failure, etc). If you want to be able to verify the copy is complete, you need to use something more complex than exec, which is the proc_open and related functions. These let you run a command asynchronously while monitoring it's progress. You can handle this easier by making use of the symfony/process package to execute your commands. If you don't want to use a library, you can check my article on fibers for an example of how to run multiple processes asynchronously using proc_open.
  23. Do you want to just kick off some copy commands and move on, or do you want your script to wait for them to finish and verify the copy was successful by checking the exit code?
  24. I use neither ODBC or SQL Anywhere, but my initial wild guess would be that it's failing to verify the server certificate. Some quick googling suggests the trusted_certificate option might help. Something else to try, though I don't think it'd make a difference, would be to set openssl.cafile to a custom CA bundle that includes your server's certificate.
  25. SSH is not typically used in a windows based stack. RDP is generally used to access and manage windows based servers. Modern windows server has other management tools I believe, but I don't have experience with them.
×
×
  • 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.