-
Posts
5,960 -
Joined
-
Last visited
-
Days Won
146
Everything posted by gizmola
-
Sounds like an interesting project and some unique performance challenges. Thanks for providing the update. The main takeaway I hope you got from my reply, was that Dependency Injection is a pattern, that you can employ and perhaps benefit from, and of course Drupal already supports Services and does Dependency Injection.
-
To add onto what requinix noted, I believe the default for fulltext is words greater than 3 characters in length, so by default it would already have an issue with 'M/C' even if that was interpreted as a word. You can tweak the default length, but I haven't done anything with mysql fulltext search in a while, so I can't tell you off the top of my head, what you would need to do there. Otherwise, you can think of full text as breaking up input into individual words and letting you search for rows that include some or all of those words, with the results "scored" such that it will give you back results that have the highest score first. I think the assumption there is that the user will need to look through the results and determine if what they searched for meets the criteria. I want to add that there are many fulltext search systems out there that you can integrate with your app, which have additional capabilities beyond what mysql offers, and there are often php component libraries available that make working with these other solutions easy. This forum is a good example of that, in that the search features use sphinx, but there are many other options available. Sphinx is popular due to its performance (written in c++) and relatively small footprint, but there are a lot of other options out there. To name just a few worth looking at: Solr Lucene Elastic Search Manticore Typesense
-
We get these type of questions all the time. I'm not sure what you mean by "I am not getting to the OTP page" or what this has to do with phpmailer. If emails are not going out as expected, one reason would be that this wouldn't work with godaddy, as you'd need the hostname and whatever other credentials for their mail server. $mail->isSMTP(); $mail->SMTPAuth = false; $mail->Port = 25; $mail->Host = "localhost";
-
Hi there, Please use the <> code snippet button and put one or more snippets of your code into a new post to this thread.
-
No, and I doubt you will find any. In the past there were few different paths: try and use apps like openoffice to open ms documents and use the openoffice api Use windows specific integrations In recent years, microsoft has introduced "add-ins" primarily for companies looking to integrate their office data into intranets or publish data on a website: https://learn.microsoft.com/en-us/office/dev/add-ins/overview/office-add-ins These are avenues I'd look into. I don't know what scale you are looking at. I worked for a company some years ago with millions of customer accounts, and that product needed to transform any of a large number of different document formats, into other formats, and this involved a complicated ingestion process that, depending on the type of document, passed it on to a cluster of different servers that would run native apps and perform various processes often running macros and other code native to the specific application, before exporting to other formats. I suspect you would need something similar. And of course pdf is a whole different company and different platform.
-
That was not a forum-wide function, but related only in that one thread. Most forums have an underlying database, so if you understand the database structure, have the appropriate access to develop code and connect to the underlying database using credentials, it is possible to write code that goes through the posts in the thread, and performs calculations on them. It appears to me that the developer of that "game" did something like that, and likely automated the update process of the original thread post, as the statistics appear to be current, even though the "gaming" was initiated 4 years ago. Any approach to something like this would be entirely based on the underlying forum software.
-
I don't know what you found on SO, but it's unrelated to the intl extension. What operating system are you running? What version of php? How is your development environment configured? Are you using Docker? Note: The library you are trying to use states that it is "depreciated" (sic). It was also forked by the originator to a different repo, with the intention of passing it on to other maintainers. Since you are using Laravel, this one might be a better fit for your project: https://github.com/TechTailor/Laravel-Binance-Api It states it is still in alpha, but depending on what you intend to do it might be a better fit for you.
-
I don't disagree with requinix's advice here, as you need to be aware of what breaking changes are, but there are some popular tools that can help you understand the quality and inherent issues in your code. In general, one category of these tools is "static analysis" which evaluate your source files and report on a variety of problems or things that violate best practices or a particular coding standard. There are a number of these tools, with one of the most popular currently, being phpstan. Depending on what editor you use, there may be a phpstan integration available that helps with evaluating and fixing problems it finds. There's also a nice article, albeit a bit old now, about php8 migration with a lot of good information I would encourage you to check out: https://haydenjames.io/php-8-compatibility-check-and-performance-tips/
-
There is nothing in the spamassassin daemon api that is designed for spam marking. As far as I know what you need to do with spamassassin is run sa-learn to train it: https://geekthis.net/post/spamassassin-training/ Notice that it is just as important to have the "ham" as it is to have the "spam". So in general, you want to get your box in a state, where you have marked the spam, and then run sa-train on those boxes. In general, marking something as spam in a client is basically for the purposes of moving it to a spam folder that has a retention limit on it that will automatically delete the spam emails when the email gets to a particular age. Of course in doing so, based on your configuration you can then use that as the basis for running sa-learn, perhaps as a cron job. FWIW large emails sites can't trust the userbase to train their systems, and there is also mail filtering that goes on to knock down a lot of spam before it ever gets to the point of being in the mail system.
-
I think that requinix gave you some very good abstract advice. Stepping back from this, a big part of your conundrum, without a doubt, was the choice to create a real estate portfolio management application in Drupal, where Drupal is not providing you the vast majority of value. Drupal is a CMS, and its value proposition is based upon people that have a variety of media (text, images, video, documents) they want to categorize and organize (taxonomy) for the purposes of publishing information in a variety of ways. I have no idea why Drupal was chosen in this circumstance. It's no different than when people start with wordpress, then build out a whole custom, because the system will have a blog page. Either symfony or laravel would have been a much more appropriate starting point in my opinion. While it sounds like it's far too late to change course for you, that doesn't mean that recognition of the disconnect isn't worth recognition, because you can sometimes look at the gap, and build in thing to fill the gap using models from frameworks and perhaps orm's like Doctrine. I saw this portion of your original post" So starting with getTentantsByUnit, if you were working with a standard MVC framework like symfony, it's clear using doctrine that this the type of thing that you would have in a Doctrine "Repository" class. Essentially, a repository class is associated with a "model" (aka a class associated with a database table) that can be used to make queries against that model. One of the values of an orm is also that you are able to define the underlying relationships between models (which again map to tables) and get certain built in behaviors when querying, like in this case, querying for a unit and getting all the related tenant rows in the result. The name says to me, that this is a function that should be in a class associated with the "Unit" table/model. Doctrine implements the "Data mapper" pattern, as opposed to the "Active Record" pattern implemented by many other frameworks most notably for php, by laravel eloquent, or famously by Ruby on Rails. I personally prefer the Data Mapper pattern, and the key thing to recognize is that these are "patterns" and even though you aren't using an ORM, doesn't mean you can't implement your own version of these patterns. As an example, I worked for a consumer service company that had a large legacy laravel code base, and even though they started with Laravel, over time, developers had essentially added classes to implement the "Repository" pattern on top of Eloquent. "recordActivity" sounds more to me like a "service" that you would create. One of the major engineering decisions of Drupal, was when they rebuilt it using the symfony components as a starting point, so that it would be a dependency injection framework, and support integration and extensibility with php components. This means that you can "wire" and/or configure your own services and use them in your application. Perhaps you already know this, so please excuse this digression if you do. Here's a quick pointer to some discussion of that: https://www.drupal.org/docs/drupal-apis/services-and-dependency-injection/structure-of-a-service-file So the idea behind this is that you use interfaces to describe your core dependency objects (things for database manipulation, mailers, logging etc.) and if you need that service, the DI container is able to instantiate the service at runtime, and you will be able to use it, taking advantage of configuration, lazy loading etc. rather than having to do all the setup work yourself. This is another reason why you want to separate things into appropriate classes, since you are using Drupal and Drupal is now a Dependency injection framework at its core. To do all this you want logical organization of classes using dependency injection principles, and you want to use interfaces where appropriate, or at the very least, typing of classes that will be inject into other classes or services as dependencies. You also mentioned traits, and traits should by used sparingly and only when you 100% understand and can justify why you need them. Typically this is to merge code into a class that is highly generic across a lot of classes. The classic example of this, is having a code base, where you generically want some logging capabilities. Since PHP is a single inheritance model, that is the way to go. Just a throw away thought for you, but lately there's been a lot of talk by PHP developers about declaring most of your top level class methods as "final", and in many cases the class itself as final, so that it won't be used in inheritance when that ends up being a kludge. I'd throw in that practice. Here's a nice blog post by a symfony/doctrine core developer who has written a huge amount of code for those projects on the practice: https://ocramius.github.io/blog/when-to-declare-classes-final/
-
Assuming you are able to pinpoint the point at which the object is created and you have a variable assigned to it to work with: // Use object attribute access syntax echo $obj->data->ip;
-
I believe it was meant as a colorful reply. Requinix is saying that things will "explode". What I believe will happen is that auto_increment will not work the way you expect. Rather than start at 1, the first allocated auto_increment value will be the largest id that exists, plus 1. So the first new inserted value in the table will have id 31. There won't be an error, so I guess the main question is whether or not you actually care about the loss of available key values. BTW, a similar issue exists with tables you might truncate or delete all values from. That does not by itself reset the auto_increment value. You can however, use a mysql/mariadb specific sql statement on the table to reset the auto_increment counter back to 1 ALTER TABLE tablename AUTO_INCREMENT = 1 This however would not work with Innodb tables (which is what you should always be using with mysql) as the auto_increment counter can never be set below the highest available one that exists.
-
Yes, storing a path is the way to go, but you also need good reliable routines for maintaining the images. Typically, you need a table that stores: the "stored" filename When you move the uploaded file, you should change the name to something you use internally via a sha1 hash. this insures that you won't have name collisions from users uploading a file with the same name it protects you against named based exploits The original name when the image was submitted You can use this if you allow users to download the file as the original name it was uploaded as The mimetype (not strictly required, but a best practice in many cases) The path to the image file
-
Calling a MSSQL Stored Procedure with multiple inputs and outputs
gizmola replied to Thomas_Bode's topic in PHP Coding Help
He meant, did you try adding more parameters to the array. You have a basic misunderstanding of the manual: https://www.php.net/manual/en/function.sqlsrv-query.php "params" is an array of arrays, where each array element represents one, in, out or in/out parameter. Your code seems to imply that you think there are separate arrays for input and output. That is not the case. There is only one array, and you need a child array for each parameter (in order of declaration for the sproc). Since you did not provide us the source of the sproc, we don't know how it is defined. Just trying to intuit what you are doing from your sample code, this looks more likely to work: $params = array( array($myPMSource, SQLSRV_PARAM_IN), array($period, SQLSRV_PARAM_IN), array($myDB, SQLSRV_PARAM_INOUT), array($myCLSource, SQLSRV_PARAM_INOUT) ); This style requires that the sql server driver assume the php and mssql server data types from a preset of the variables, but there are optional parameters (3 and 4) that can be used with constants documented on the query page, you could pass to explicitly tell the driver what is expected, within each single parameter array. I haven't done any PHP with mssql in a long time, but it is possible that for any output variables you may need to pass those by reference. That at least is what the current microsoft documentation shows. So you might need something like this: $params = array( array($myPMSource, SQLSRV_PARAM_IN), array($period, SQLSRV_PARAM_IN), array(&$myDB, SQLSRV_PARAM_INOUT), array(&$myCLSource, SQLSRV_PARAM_INOUT) ); Last but not least, mssql does have a PDO driver, and that might be simpler and easier to use, as you would simply bind each parameter prior to the call. See: https://learn.microsoft.com/en-us/sql/connect/php/pdo-sqlsrv-driver-reference?view=sql-server-ver16 -
Hope your studies are going well flap. Web development is a huge area of study, with a lot of interdependent technologies and complexity. If you want to do development with PHP, then you should focus on the front end things you need (html, css, js) and a backend technology (php or python or nodejs or ruby or... ) + mvc framework. Typically any backend application needs a way to persist and organize data, so that often leads into SQL and relational databases, or possibly a document database or some other alternative. That is a substantial and highly valuable area of study in itself, separate from a server side language. It tends to be that, for example, a good understanding of relational database design and SQL is a skill that is applicable across backend languages. Each has one or more client library implementations that allow you to interact with the database, but all of them work from the same set of fundamentals, and it's only the specific language syntax that is different. When you are proficient in building apps, then it's great to become a polyglot. From a computer science student point of view, I would recommend that rather than go from, let's say, learning PHP to learning Python, a student is far better off learning C. From that point, learn whatever you want. Many languages are either object oriented or have an object oriented layer/extension to the language. PHP is no different and has added many oop features in the last 10 years, most of them aimed at framework developers and professionals who want to implement OOP design patterns in their PHP applications. So this is one other area of complexity. From a front-end standpoint css frameworks like bootstrap or materialUI and Tailwind have proliferated. Javascript frameworks like react and Vue are being employed to create interactive web UI. Your time would be best spent figuring out a stack of tech that works for you, and creating apps with that stack.
-
I have not looked through all the code, but to begin with, no you can not store image data (binary data) in a varchar field. FIrst of all, varchar fields have a fixed maximum length (64k), but they also are limited to characters and a character set. The data for an image is a byte stream of values, so you must use a blob field to store raw image data. There is a way to "encode" binary data in a format that transforms it into a text version, and in fact this format (base64) is built into browsers, such that it is possible to include in an html page an "inline image", and this format is base64. Here is an example of that (which is the mysql logo as a jpg image): <img src=" data:image/jpeg; data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQ gFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQM EBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB QUFBQUFBQUFBT/wAARCAAuADUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAw QFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS 0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXq DhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6er x8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBA cFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygp KjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoq OkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tP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8uVZZbgvtw77RjCYO OSfm7V3VFeRjsHTzCadZvlX2dLeWtub7mvPqerg8TPAwapL3v5tb+fW33p+XQ891qPxBeeGYtI1PSc248 qK+vLGXzjJEpBYxxYDEsFxjGV3cbsVqx2usaT4t1a6t9MS9s79rfEouVjMYRArHaRz1J/CutorzllCU1U9tLm VrP3brlUlb4bNWm91e7vc73mTcHD2UbO9171ndxd973vFdbeQyNnZnDoFAPBBzkUU+iveSsrXPHep/9 k= " alt="MySQL" /> So, it would be technically possible to base64 encode the raw image data, and store it in a text type field, then either include it in an inline tag or decode it from base64 after it's fetched and return that data. I'm not going to go into the many issues and reasons that for most people this would be a bad idea, but since you asked, I presented the technical background. I don't know what your reasoning is behind wanting to try and store image data in your database as something other than as a blob. I would suggest you explain your reasoning, and the desire to make this type of change, so people can provide you some usable feedback and suggestions.
-
I went through and tried to clean up/make sense of the OP's posts, and lack of experience with the forum tools. To @prosperchild Start with your description text etc. in the editor window Don't write up everything in another editor and try and paste it all into a code snippet When it is time to put a snippet into the post Use the code snippet button: <> Paste the code snippet into that window, set language appropriately to reflect the language DO: use one or more snippets for each file you are trying to get help with DON'T: paste the code from a bunch of different source files/multiple languages into one snippet. Use different code Snippets for each portion of the code Example: "Hey, this code has a bug, around line xyz that says: blah blah blah. I am not sure how to fix this" /Index.html Use <> Code snippet button here <html> <header> </header> <body> </body> </html> sources/code.php Use <> Code snippet button again here <?php phpinfo(); die('What is going on?');
-
We need more information. First off, you probably can't change a lot of these setting using ini_set if you are using mod_php. Many distributions have a scheme of ini files that will separate the cli settings from the settings applied to the web server. Provide us the output from a page that only has this in it: <?php phpinfo(); Last but not least, when you change any php.ini settings you need to restart either apache or php_fpm (depending on your setup and which you are using). post_max_size is certainly in this list of things that can not be changed on a script by script basis. The phpinfo() has important information about the runtime settings, starting with the location of any ini files read. You may be surprised to find that the file you have been changing is not the one actually being read. It will also show you the actual runtime values, so you can verify any settings.
-
PHP script to export for Facebook data feed CSV
gizmola replied to ludwig's topic in PHP Coding Help
The other obvious problem with your code is that it appears to be based on a database query result set, but you didn't include that in your code, nor is there a "foreach" loop over the result set building up the csv file with the results. So while you may or may not need the csv header row, your code as presented has no hope of actually working, without the availability of the data in a $row variable that is fetched from the result set in a loop. Another issue you need to be aware of is that strings should always be delimited with double quotes around them. So you need to be cognizant of which columns are strings, and also you need to make sure that any embedded double quotes are escaped. So for example, these lines are improper: $output .= $productTitle . ","; $output .= 'Visit our website for more info.' . ","; That needs to be this: $output .= $productTitle . ","; $output .= '"Visit our website for more info."' . ","; These problems are already solved for you in the function requinix linked you to. -
Well the first thing I typically would do in a situation like yours is to do some googling for something like "php revolut api". I will then look to see if there are any libraries available, where someone has already put in the time and effort to understand what is needed. I found what looks to be a relatively up to date project that you should look into: https://github.com/sverraest/revolut-php There are other things you should do like searching packagist using "revolut" (notice the double quotes to eliminate partial matches).
-
Ratings in database ala Amazon. How many of each?
gizmola replied to tunnelboy's topic in MySQL Help
Don't confuse sum and count. It works here, but the two functions are very different. Highly recommend you not get used to substituting sum for count as if they are interchangeable. I also always alias computed columns so I can predict what the column name will be when fetched. SELECT rating, count(*) AS count_of FROM reviews GROUP BY rating Now I heartily agree with @requinix that a simple class or function is best here. There is no way for the database to know the available universe of values with a scheme like this, which might facilitate an outer join solution to your problem. With that said, here is a SQL solution that makes a number of assumptions that might not be directly applicable to your database structure, but at least illustrates the idea. I don't think this is a good solution for a number of reasons, including the fact, that you have to hardwire the ratings into your SQL statement AND you are doing a distinct query to figure out which values you need to exclude. There might be a better way to accomplish this (maybe @Barand has something better? This does work, and I provided everything you would need to verify in a test database. create table reviews (id int unsigned PRIMARY KEY AUTO_INCREMENT, rating int); insert into reviews(rating) values (5), (5), (2), (3), (1), (3), (2), (5), (1); SELECT * FROM (SELECT * FROM (SELECT 1 as rating, 0 as count_of union SELECT 2 as rating, 0 as count_of union SELECT 3 as rating, 0 as count_of union SELECT 4 as rating, 0 as count_of union SELECT 5 as rating, 0 as count_of) as t1 WHERE t1.rating NOT IN (SELECT distinct(rating) as rating FROM reviews) union select rating, count(*) as count_of FROM reviews GROUP BY rating ) as u1 ORDER BY rating ASC; With this test data you get your desired result: rating count_of 1 2 2 2 3 2 4 0 5 3 Just to reiterate, a php function using range to pre-populate an array you then use to merge with your result, would be a great way to handle this in your PHP code, and that's what I would do here rather than utilize the convoluted solution I demonstrate here. -
I just checked in on this now. The function I pulled is part of a utility class, and not a standalone function, so it was scoped. I'm glad you got that figured out. Learning a bit about PHP Object Oriented Programming would be a great next step for you. The main thing I wanted to contribute was the best way to store IP addresses, and it appears you've implemented that successfully.
-
I'm guessing something like this might work for you (assuming you have a reverse proxy or load balancer). protected function getClientIP() { // This assumes a classic AWS Load Balancer is proxying if (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && !filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { $ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); return $ip[0]; } else { return $_SERVER['REMOTE_ADDR']; } }
-
is this the good method to block an ip adress?
gizmola replied to alexandre's topic in PHP Coding Help
In general, the less information you provide the better. The message should simply say something like "Too Many Requests" and shouldn't disclose that you are banning things by IP, or what the IP actually is. Don't provide information to bad actors that helps them work around your system. One other thing about apc: it's memory on a specific server, so if you ever have load balancing in place, these stats are going to be spread out across servers. It's also fairly standard to store bad attempts against a particular username, and perform an account lockout if a particular bad password attempt threshold is reached.