Jump to content

gizmola

Administrators
  • Posts

    6,060
  • Joined

  • Last visited

  • Days Won

    153

Everything posted by gizmola

  1. Did you look at the links I provided? There's not much more to it. Pack will let you pack the bytes into a binary string. You make the socket connection and fwrite the packed string to it.
  2. The comments and concerns expressed in that SO question are in no way applicable to what you are talking about doing. You might also note that the author of the comment, never demonstrates the supposed danger or where the section you quoted in any way matters. The most comical thing about it, is that there is no semi-truck table. The original requirement was completely lost. The ultimate model added to the original question does nothing other than to add tables only relevant to the car tree hierarchy. Adding a unique index and referencing that as a foreign key only matters in that scenario because there is a cars table where lots of different car subtypes could go. Are you implementing a hierarchy with multiple subclasses and sub-subclasses? No you aren't. Did you look at the other answer from Walter Mitty? It literally calls out the solution I provided you with the tag shared-primary-key I made you a model and generated the DDL. You could have run it in a test db and played with it, and created a few queries. Could you create a row in a subtype table for the wrong product type? Yes. But considering the missing semi-truck table, the same issue existed in the non-solution presented and accepted in the question you referenced. The main focus of the solution was the hierarchy of car types, which again isn't relevant to your product subtypes. It's not a concern for you because the procedural code you need to write, which uses the product_type attribute to determine which child table the subtype row needs to be created in, must do that properly for your system to work. If it doesn't do that properly 100% of the time, then your system doesn't work at all, and we are talking very simple logic. If you are super paranoid, then a simple trigger could be written to prevent it happening in any of the child tables. You could also, as an alternative, write a trigger to create the row in the correct subtype table, when you insert the product row. Ordinarily I am not a big fan of MySQL triggers or sprocs, as they reduce concurrency and insert performance, but your system will not have a lot of insert/update activity against the tables in question, and will primarily be selecting the data, so it's worth considering.
  3. Aside from the things Requinix listed, another thing that influences spam scoring is having a valid reverse DNS. Here's a list of some services you can use to check your rep: https://sendgrid.com/blog/5-ways-check-sending-reputation/. You also have to make sure your domain and your MTA IP is not on a RBL. The reality is that sending email from a Shared server is only as reliable as the worst client they have had on the server, or your ISP, depending on how email works for you with your hosting company. The other issue is that some systems may consider your emails to be spammy. Most analysis works on a scoring system, so if your emails are getting rejected outright as spam, that tells you something. Throttling isn't going to help you improve your score, and depending on the server you are communicating with, getting help with finding out how and why you are being rejected may be next to impossible for you. This is another reason to use a commercial email delivery company, since it's their business to insure delivery of client emails, and they have paid staff to correspond with sysadmins of major email systems.
  4. Yes. Take a look at stream_socket_client and pack. I don't think this type of application is PHP's forte, but it is possible. Creating an executable with c, c++ or Go would be a simpler final product upon completion, but PHP is certainly capable.
  5. You have Xampp, so you do have a database. The 'M' in Xamp stands for MySQL database. You can use the phpMyAdmin that is installed with your Xamp to create the tables. Again, you have to learn something about MySQL and the SQL queries, but as they will be very simple as far as SQL goes, that should not be a problem. Let's assume you name your table Medialist... All you will need is: SELECT * FROM Medialist INSERT INTO Medialist (columns..) VALUES (?, ?, ?...) DELETE FROM Medialist where id = ? UPDATE Medialist set column = ? where id = ? The basics of doing this is covered in the tutorial video I linked. My suggestion to you is to follow along and create the application with the tutorial. Doing so will teach you 95% of what you need. Then use what you have learned to create your app. Once you have most of it working, it will be feasible for people here to help you with the last 5%
  6. Here's what you want: header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1. header("Pragma: no-cache"); // HTTP 1.0. header("Expires: 0 "); // Proxies. Major Stackoverflow discussion of this topic. Keep in mind that if you are using sessions, PHP session configuration can screw with your cache control settings: Read about session-cache-limiter.
  7. A step by step tutorial on how to build your specific application is the same as writing it for you. Nobody is going to do that. You are going to have to learn some PHP. I already suggested to you that a TODO list app is very similar to what you need. Here's a tutorial in 3 or 4 parts that covers building a UI, making Ajax calls, writing PHP scripts to persist the data in MySQL and writing the persistence code using the PDO api. My suggestion to you would be to follow this tutorial and see if you can build it. At that point, you would be able to take the TODO app, and tweak it to fit your application.
  8. Which is why I linked you to a tutorial that shows you how to fix your mysqli code and use prepared statements. Did you bother to look at that? Did you make an attempt to refactor your code?
  9. I also realized that you might be asking about deployment. Again, this has a lot to do with the target production infrastructure. Lots of companies have a Devops group to work on deployment. More often than not, companies are using Github or Gitlab or Bitbucket. From a simplicity point of view, a real simple way of handling deployment is: You develop and test. If you have lots of tests, which most companies do, then they are doing continuous integration, where test servers run on every branch, and merging code only happens if all the tests pass. Then a manager/lead will do a final production merge, typically from a pull request, and version the code. That build can then be gotten from the git repo, perhaps via a version tag. What is even simpler for a small system perhaps with one developer is to use bitbucket or github with a private repo. You set up a read only user that can checkout/pull from your repo, and you configure your production environment's effective user for the application as that user. Getting the new build into production is as simple as git pull, or perhaps git checkout tag-name.
  10. Yes, that is what most developers are doing. Truthfully, I don't want to blow your mind, but for quite a while people have been using some form of virtualization as well. That provided a best of both worlds, where you have a deployment server environment (usually centos, ubuntu or whatever) running in a virtual machine, with drives mapped into it from your mac. For a time people were typically using virtualbox & vagrant. You'd install these, grab a vagrant file for the os you wanted (often with a stack preinstalled), and vagrant would download and configure the virtual server in virtualbox. This is still viable and works very well and is extremely simple. You might try going down that path. Setting up xdebug with any "remote server" even if it's a virtual machine running on your mac, can be a little complicated and have pitfalls, but otherwise, it's a great option. Here's an example Centos7 with LAMP stack vagrant: https://app.vagrantup.com/Gigasavvy/boxes/centos7-LAMP More recently people have moved to utilizing containers. The most popular container wrapper is Docker. So now, people are using Docker instead of the vagrant/virtualbox combo more often than not. There are some advantages in that docker is more compatible with running a cluster of virtual containers in the cloud, which is often done using an "orchestrater", the best known of which is Kubernetes. It doesn't really matter whether you grok all this stuff or not -- it's very sysadmin/devops specific stuff, but truthfully if you want to know what most companies that have SAAS or PAAS infrastructures or just large web based systems are doing, they are using Docker regardless of the stack. There are things as elaborate as Devilbox, which literally gives you a mega wamp/mamp style system, with options galore. If you install Docker you can tryout things like Devilbox. There's also Laradock which offers a similar even more development oriented docker file build that was put together for Laravel developers, but can be used more generically. You can also look for more minimal docker files that just set up a few different containers (apache + mysql +php) for example and articles like this one that will walk you through creating a docker file from scratch to your requirements. Vagrant is still great and extremely simple, but Docker is more current as a development environment virtualization solution. Unlike Vagrant, which just simplifies running a virtual linux server, Docker has some complexity specific to running containers, and certainly has a bigger learning curve, but if you want to do what most pro developers are doing, then I'd invest the time in playing with and learning the basics of Docker. If you just want to get a dev environment up that matches your target deployment environment, go with a vagrant. In either case, you need a pretty good working understanding of linux and the different ways of installing from packages.
  11. 11 years ago, it was unusual for people to use UTF-8. This was also before HTML5 became the defacto standard, but previous to that, people often used a particular character set, so check your app to see what if any meta charset it's setting. <meta charset="UTF-8"> //or possibly <meta charset="ISO-8859-1"> In the past it was not uncommon for people in the west to use ISO-8859-1 as it covers english and a lot of the european languages, and Finnish and Swedish. There is also ISO-8859-4 which supports "Scandinavia/Baltic". They overlap to a fair degree, but obviously there are some characters that are different. As requinix stated, we really need more info on the OS of the server. Again, going back 11 years, windows servers were still possibly using a codepage rather than unicode. There's also some issues with different OS's as to the support or lack thereof for case sensitive filenames. It would also be helpful if you could provide a specific example of a file that has one name on the filesystem and displays as garbage or something else in your app.
  12. So now you need some sort of persistence mechanism. This is a small application that requires some programming to accomplish. I have known people to write a lot of code to help out people in the past, but generally speaking, you have to come with some code, and some aptitude for learning, and some desire and elbow grease. I am not sure how we could help you further, that doesn't involve us writing your small web app for you. I can say this structurally, that this is very similar to and could be based on a mysql backed todo list application. Todo lists are frequently used as basic programming proficiency projects, so there are probably some you can find that you could make minimal modifications to and get a big jump start on this: You need a simple database or other persistence solution. Most people would use MySQL. Alternatively, you could persist the data as a file. I'd probably use json format, but then you would need to deal with file io routines. If you did use a database, the database for this system only needs a single table, so that's good from a simplicity standpoint You need an entry form that displays the current list of items from the database, and lets you add, edit, or delete and optionally reorder items. The same form can have a generation button that goes through the list of database items and generates the xml file I don't know if, like RSS this xml file needs to be available at a url or you actually need to generate the xml as a downloadable file, although there's not much difference between the 2. Still it does matter. The image paths are ambiguous. Are these images that should be hosted on your server? The relative paths suggest that is the case, but you didn't specify. If you need to be able to upload images and set that attribute from a list of images, then you need a subsystem/feature that lets you submit an image through the form, and a feature that allows you to pick from the list of pre-existing images when you create or edit an entry. It's a good chunk of work, and maybe a day (non optimal time) project for an experienced programmer. If you're learning, I will say it sounds like a cool project. If there is some specific thing that doesn't involve asking someone to write this for you, please let us know.
  13. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can find these described in a few different ways. Here's an article for you to get you kickstarted on looking into them: https://www.isitwp.com/smtp-transactional-email-services/ Depending on your volume, some of these services have a free tier, but depending on the amount of email you are creating you might need to pay for them. One benefit that most of them have is access to the types of log information that you would otherwise need to be a sysadmin for. Some have programmatic api's and some you just configure smtp-to-smtp, so you don't even have to change your current code or setup, other than to configure your MTA. Since you stated you are on a shared server, you probably don't have any option to mess with the MTA, so you'll likely have to reconfigure. There are also full maillist SAAS providers like Mailchimp or Constant Contact that are specifically built to offload email list services. This may or may not be something worth looking at for you.
  14. My point with phpMyAdmin is that it is a tool that hides all the details from you. So yes you can go in and make a table, add indexes, relationships etc., table by table. Than you can go in and add things. The expectation of the tool is that its for people who don't really know SQL. It's ubiquity is largely a function of the fact that it's been around a really long time. The basic ingredients are: 1st time creating a table = CREATE TABLE Changing something = ALTER TABLE But neither of these is a script you can play and replay. The time it will take you to make all the tables with phpMyAdmin is guaranteed to be equal to or greater than the time to make an ERD in workbench, with none of the quality, and no ERD diagrams to look at when you're done. I refer you to the other thread on foreign keys and the subtype. Having read your post: I Installed Workbench on my mac ran it for the 1st time ever Made a model of the tables (click type click drag) Related the tables (click drag) Generated the diagram generated the SQL I put in the thread Took me about 15 minutes or so, and I was doing this while talking to my kid. I have never used Workbench to make a diagram ever before. There was one non-intuitive thing I had to figure out but overall it was a lot more functional than I expected. There are things I've mentioned like domains, that I probably would want to use that I didn't attempt to figure out in it, but again I spent absolutely no time learning it. Now I grant you that I've used about 5 different commercial tools over the years, so I know what I'm looking for, but I just don't believe it would take you that long to figure it out. I'm also sure there are probably 50 video tutorials on the basic of it on Youtube. Also FYI these tools including workbench have a reverse engineering feature where they will read either a live db schema or a db dump and bring the existing model into the tool. Again, I'm beating a dead horse here. I think you've built these things up in your mind. Using workbench to digitize your diagrams is not the same as becoming a master of photoshop. I will do my best not to bring it up again
  15. Every PHP framework I know of has some form of ORM, back to CakePHP and Codeigniter, to Zend Framework. The 2 big boy PHP frameworks are currently Laravel and Symfony. Laravel has Eloquent, and Symfony has Doctrine (which is a separate project). It's possible to use Doctrine with any framework, and it's not uncommon for people to use Zend Framework with Doctrine. There is another ORM named Propel that has a similar history to Doctrine and was once on equal footing within the Symfony framework, but Symfony has more or less adopted Doctrine as its standard now. These are all open source/free as in beer with open source licenses. If you have heard of Ruby on Rails, you might know that Rails is an MVC framework, but it comes with an ORM known as ActiveRecord. Several of the ORM's I mentioned are Active Record implementations. Active Record is an OOP design pattern. Doctrine, which I prefer, is a "Data Mapper" pattern implementation. It has some different concepts to it. If you don't use an ORM, you will likely try and build something yourself that has some of the properties of an ORM. You would do yourself a lot of good, on whatever phase you are on, to adopt one of these libraries, even if you aren't using every aspect of them. They provide the "model" portion of Model View Controller (MVC) systems. It is also possible to build a subsystem using an ORM even if the system has lots of existing code that doesn't use the ORM. I have done this on projects any number of times. I don't think you really can afford to delay that. It explains autoloading, dependency management and component libraries. Even if you don't plan on using a full framework, what this explains is how the modern dependency injection frameworks are put together. They aren't a monolithic blob of interdependent code, but rather a number of component libraries that each do a different thing. The last half of the video is him going through a number of the symfony component libraries, with dead simple examples of things you can do with them in 5 lines of code. The world of professional PHP programming involves using component libraries now. If you aren't using them, you are doing it wrong. This isn't some thing you should get to some time in the future. It's been 8 years since this became the defacto standard way of developing PHP applications. Logging for your app? Component Library. Generate a pdf? Component Library. Send emails? Component Library. The video explains this and a bit on how to identify the ones you want to lean towards, as there are often many component libraries out there that solve a certain problem.
  16. This is your subtype table, correct? You do not need id+product_type. You simply need id in the subtype table. You need the product_type_code (why code btw?) to determine which subtype table, but there is no value in bringing along the product_type_code. This is called a "defining relationship". The best way to think of it, is that the primary key of product (id) will be the primary key of product_{product_type} Here is a basic ERD of the relationships in MySQL Workbench Here's generated SQL: -- ----------------------------------------------------- -- Table `mydb`.`product_type` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`product_type` ( `code` CHAR(1) NOT NULL, `name` VARCHAR(30) NULL, PRIMARY KEY (`code`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`product` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`product` ( `id` INT NOT NULL AUTO_INCREMENT, `product_type_code` CHAR(1) NOT NULL, `name` VARCHAR(60) NULL, PRIMARY KEY (`id`), INDEX `fk_product_product_type_idx` (`product_type_code` ASC), CONSTRAINT `fk_product_product_type` FOREIGN KEY (`product_type_code`) REFERENCES `mydb`.`product_type` (`code`) ON DELETE RESTRICT ON UPDATE CASCADE) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`product_subscription` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`product_subscription` ( `product_id` INT NOT NULL, PRIMARY KEY (`product_id`), CONSTRAINT `fk_product_subscription_product1` FOREIGN KEY (`product_id`) REFERENCES `mydb`.`product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`product_article` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`product_article` ( `product_id` INT NOT NULL, PRIMARY KEY (`product_id`), CONSTRAINT `fk_product_article_product1` FOREIGN KEY (`product_id`) REFERENCES `mydb`.`product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`product_promotional` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`product_promotional` ( `product_id` INT NOT NULL, PRIMARY KEY (`product_id`), CONSTRAINT `fk_product_promotional_product1` FOREIGN KEY (`product_id`) REFERENCES `mydb`.`product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; Notice what there is and isn't. There is no code that creates indexes, because INDEX and KEY are the same in MySQL/InnoDB DDL. Making the key makes the index.
  17. You can run the httpd.exe from a cmd and get a list of the installed modules: drive:/path/to/apache/httpd.exe -t -D DUMP_MODULE
  18. I thought you were planning to write the DDL. Clicking away at phpMyAdmin like a monkey is about the least efficient way to do this I can think of. You were arguing to me that you didn't have time to learn how to use mysql workbench and make an ERD! This is the type of response that you sometimes use to rebuff advice, which leaves many of us with the impression that you rationalize your predispositions. You absolutely should have a full sql script with all the DDL to create all the tables, and constraints.
  19. Those are reasonable standards, but you have to keep in mind that postgresql and mysql have significant differences. With Mysql/InnoDB there is no difference between keys/indexes and constraints. Of course constraints have optional on update and on delete configuration, but in terms of the underlying mechanics of indexing, an fk constraint creates a corresponding index. I don't want to get into re-writing the MySQL manual, but there are now check constraints in the latest versions of MariaDB and MySQL I really haven't used, but I only mention this for completeness. The only way you can name an index or constraint is to create it separately from your create table statement via alter table. So you'll need to decide if naming things via a convention that is different from the defaults is important enough for you to have to break up the activity of table creation into multiple create and alter statements, and of course keep track of this fact should you need to make changes during the development phase and in the future, which in my experience is inevitable.
  20. There are some things you need to name yourself, so having a standard way of doing it, isn't a terrible idea. The counterargument to your concerns is that you don't need to organize anything, because the data dictionary already maintains the relationships between these database objects. If you want to find something, you will be able to by querying the data dictionary.
  21. Again, I haven't said you shouldn't use a subtype. I have used them myself. Ideally you would be using an ORM where a lot of the complexity is handled for you by the ORM. At this point, I don't see value in continuing to discuss it. At the end of the day, it's your business plan, your database and your code. So long as it works for you, and you can make the system work as you need it to, it doesn't matter that we likely aren't 100% on the same page. I don't take it personally. It's free advice, and at the end of the day, I'm not hurt or offended if you decide not to take it, nor do I personalize it. There are many ways to accomplish things. You are welcome to think of it that way, even if I don't. To me the use of the word "history" has a connotation to it, that means it's a repository for things that are now obsolete. I don't look at it that way at all, even though prices do have an expiration. From my point of view, that table facilitates getting the price for any product that is valid as of this second. You need expired pricing so long as you need it, which might be until the system is decommissioned, assuming there is order history attached to a product price row, but that's just for audit and pricing purposes. I understand if you decided to put those fields down in the subtype table child, but that only returns us to more debate about your product/subtype/version model, which just doesn't compute for me. I was just trying to give you the benefit of my experience. I have been the architect/project lead on a lot of projects in my career, and frequently I've been the database designer and pragmatically, the keeper of the schema, and responsible for generation of the DDL. Quality is very important, because mistakes small or large are costly, in terms of code redo, testing and refactoring. On any schema of moderate complexity, it's likely there will be some back and forth. Hand coding all the SQL is a pain, and it's hard to see the forest for the trees when you have a bunch of table definitions. Don't forget that you will want to have constraints, and when even a small change is made to a number of related tables, this can require a cascade of different tables and constraints (and possibly triggers or sprocs) that need to be recreated. Using a tool is vastly more efficient. Again, you have stated you don't plan to use one, and that is your choice, but you shouldn't take it as a personal attack that in my experience building a model in a tool is a boon to productivity, quality and helpful in the iterative process of refactoring to address things that were initially overlooked. It's also invaluable for communicating with developers in a team. Perhaps you don't care, because you don't see a time when you won't be a one person team. If anything I've understated the value of an ERD, and that's why I use one for my projects, large or small. This was simply practical advice. I have worked on many a project where the originator neglected to make integer keys unsigned. Worse yet, they sometimes had foreign keys with a different definition from the primary key of the foreign table. I've also seen people create a small type table, as for example, one might create for the product_type values we've discussed, and make the primary key a bigint. Not too long ago I was working on a project for a service company that had many millions of transaction rows in one particular table, where there were about 14 "flags" or "status" columns. This was just one table, among many others, some of which had the same issue. The flag columns were typically booleans (0 false, 1 true). The status columns had a universe of 20 or less mutually exclusive values. With MySQL they could have used 1 byte tinyints, but the original developers made them all 4 byte integers. They were allocating 56 bytes on these columns per row, when they could have allocated 14. Compound this with a number of indexes on these columns, and the waste was in the terabytes. At that point there was nothing they could do about it, that didn't involve an expensive and painful maintenance process. That mistake had a very real cost to the company as the db was bloated, along with the indexes, which made all their expenditures on the rdbms infrastructure less effective. You were discussing some pattern that would give you referential integrity. As for OOP, a subtype is an OOP concept, as I've commented previously. In OOP you make a class, and you can have other classes that inherit from the a parent class. A class that inherits from a parent class is a subtype. I would hope you plan to at least use component libraries. I have shared this video many times over the years (it's 8 years old now). PHP at the time was in bad shape, compared to its competitors. Then a group emerged from the symfony framework community that created the composer tool for managing component libraries and autoloading, and that completely changed the trajectory of the language. I highly recommend you watch this video, so you can understand the evolution to the current best practices for PHP development.
  22. Haha, Well nobody said modern system development was easy.
  23. Having a default password you will never change is essentially having no security as has been pointed out previously. Putting that aside, your code makes no sense to me. Didn't you state that you were going to load all the data (except for password) into the "tablename"? I'm not sure why you are using a separate table per class other than you don't know how to design a small schema that would allow you to have all the students across tables, which would certainly be easier and cleaner. Given the code you had, it seems you would just need to query with "SELECT * FROM ... table". You get this result and fetch all the rows, then foreach through them. On the inner loop you update each row using the primary key, and set your password column = password_hash($row['number'], PASSWORD_DEFAULT); While looping you can echo the number/name of each student. Here's some partial code: <?php //start PHP session session_start(); //check if login form is submitted if(isset($_POST['gettable'])){ //assign variables to post values $tablename = $_POST['tablename']; // login to the database dbname=allstudentsdb include $_SERVER['DOCUMENT_ROOT'] . '/includes/studentdb.inc.php'; $sql = 'SELECT * FROM `:tablename`'; $stmt = $pdo->prepare($sql) if (!$sth->execute(array(':tablename' => $tablename))) { die("Unable to query $tablename"); } $result = $stmt->fetchAll(); // Set the passwords foreach ($result as $row) { echo "Name: $row['name'], Number: $row['number'] </br>"; // UPDATE each Row set password= :password where id = :id // $password = password_hash($row['number'], PASSWORD_DEFAULT); } } else { // the input form to get the mysql table name header('location: ' . '/makePassword/form.html.php'); }
  24. No worries, reading code and following it along is the way to eventually being able to write it yourself, or at least adapt what others have done, which is a lot of what most programmers do on a daily basis.
  25. If I understand your question, you are having an issue with trailing slashes on your url? # First rule after RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} /(.*)/$ RewriteRule ^ /%1 [R=301,L]
×
×
  • 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.