-
Posts
1,698 -
Joined
-
Last visited
-
Days Won
53
Everything posted by maxxd
-
Sounds like you want a custom form action: https://developers.elementor.com/forms-api/custom-form-action/ I've only played with Elementor so I could be wrong, but it sounds right.
-
Basically, yeah. the image is an official PHP image and it contains some helper methods that make setting things up much easier. To map your list: Yes, this is PHP 7.4 with Apache on a Debian base This is updating the apt package manager so it's got the most recent packages, then install packages I know I'm going to need for my environment Yup - this is copying customized config files Yup Install xdebug and redis PHP interfaces Actually, I don't recall why this is done - I know there was a reason when I created the file, but it's been a long couple weeks and I can't remember now... Yeah - customized PHP config This is one of the helper methods that make things easier - installing php extensions Yeah, in the second step I'm installing Debian zip for the OS, this step installs the php extension Bingo - enable the extensions I know I'm going to need Cleaning up - no need to keep installation files COPY --from will actually copy from the named instance, so this copies the specified files from the composer:latest image into the specified files in this image ***See below*** This just installs the AWS CLI API I built this for Laravel and I find typing 'php artisan' annoying at times, so I tried this as a work-around (not gonna lie, it didn't work) *** Installing Node/npm *** I find dealing with Node installer annoying - nvm lets me switch versions at will, which is very important in the work I do right now. But there's not an official or recently updated nvm base image on dockerhub so I installed it myself (this is one of the non-best-practices part I spoke of earlier). However, you'll need to source your .bashrc after install before you can use nvm, which necessitated the SHELL command. The -lc parameters passed in let bash start in a login shell state, and read the commands from strings. So basically all of that is an equivalent to exec() that copies nvm from github to local, runs it through bash to install, then symlinks the executable directory into the path directories, installs node v12.x, and finally sources .bashrc before running npm install to pull any dependencies in the project directory.
-
I'm not going to pretend that @requinix's explanation isn't far beyond what I could do given the topic, but the way I see it is that if you can use a discrete server for a service, that's a separate service (image from DockerHub) in docker-compose. I know it's not considered best practice in the world of Docker but I have no problem installing programs and apps on a service container in Docker - for instance, if I need Composer, I'll gladly install it in my Dockerfile for the PHP service. However, if I need MySQL I'll use the official image from DockerHub as a separate service in my docker-compose file. Same with Redis, AWS (LocalStack), and MailHog. For instance: docker-compose: version: '3.5' services: laravel: build: context: . image: laravel:new volumes: - ../project:/var/www/html - ../logs/:/var/log/ ports: - 8001:80 environment: - ENVIRONMENT=development networks: - laravel depends_on: - redis - database database: image: mysql:5.6 ports: - 3308:3306 environment: - MYSQL_ROOT_PASSWORD=mypass - MYSQL_DATABASE=laravel - MYSQL_USER=myuser - MYSQL_PASSWORD=mypass # command: '--innodb-flush-method=fsync' volumes: # NOTE: this is not possible in mysql 5.7+ - you'll get an error that the directory # is not empty, therefor is unusable. gotta figure that out. - ./sqldump/mysql/init/:/var/lib/mysql/ - ./sqldump/mysql/init/:/docker-entrypoint-initdb.d networks: - laravel redis: image: redis:latest ports: - 6379:6379 volumes: - ./sqldump/redis:/data - ./redis.conf:/usr/local/etc/redis/redis.conf networks: - laravel localstack: image: localstack/localstack:latest ports: - 4566:4566 - 8080:8080 environment: - DEBUG=1 - DATA_DIR=../logs/localstack - PORT_WEB_UI=8080 - DOCKER_HOST=unix:///var/run/docker.sock - USE_SSL=false volumes: - ./data:/tmp/localstack - /var/run/docker.sock:/var/run/docker.sock - ./localstack/aws_services.sh:/docker-entrypoint-initaws.d networks: - laravel networks: laravel: name: laravel Dockerfile: FROM php:7.4-apache RUN apt-get update RUN apt-get install vim -y RUN apt-get install -y \ git \ zip \ curl \ sudo \ unzip \ libicu-dev \ libbz2-dev \ libpng-dev \ libjpeg-dev \ libmcrypt-dev \ libreadline-dev \ libfreetype6-dev \ libonig-dev \ libzip-dev COPY apache.conf /etc/apache2/sites-available/000-default.conf COPY redis.conf /usr/local/etc/redis/redis.conf RUN a2enmod rewrite headers RUN pecl install xdebug \ pecl install redis RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-redis.ini \ rm -rf /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini COPY ./php.ini /usr/local/etc/php/php.ini RUN docker-php-ext-install \ bz2 \ intl \ iconv \ bcmath \ opcache \ calendar \ mbstring \ pdo_mysql \ mysqli \ pcntl \ zip \ gd \ gettext RUN docker-php-ext-enable \ bz2 \ intl \ iconv \ bcmath \ sodium \ opcache \ calendar \ mbstring \ pdo_mysql \ mysqli \ pcntl \ zip \ xdebug \ gd \ redis \ gettext RUN docker-php-ext-configure gd RUN docker-php-source delete # Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # Install npm and node SHELL ["bash", "-lc"] RUN curl --silent -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash RUN source ~/.bashrc RUN nvm install v12.16.3 RUN ln -s ~/.nvm/versions/node/v12.16.3/bin/node /usr/bin/node RUN ln -s ~/.nvm/versions/node/v12.16.3/bin/npm /usr/bin/npm RUN ln -s ~/.nvm /usr/bin/.nvm # AWS PHP SDK RUN composer require aws/aws-sdk-php # Customization RUN echo "alias artisan='php artisan'" > ~/.bashrc My project directory for this particular one is as such:
-
There are some fundamentals that you need to understand. Take a look at variable scope and how to pass variables from one function/method to another, visibility and how it affects properties and methods, and static methods and properties. Once you work on that you can look at the pattern you're using - right now you're going from the outside in. You're calling to the display functions and asking them to include the functions that do the work. You want to call the functions that do the work, store the result of that work, then pass that to the display class.
-
It sounds like something's confused in what you're doing. Are you calling the Display class now instead of the Post class? And either way, if your IDE is giving you red squigglies in the Display class then Display clearly does use the variables. It sounds like you want to still call the Post class as the instigator, then call from the Post class to the Display class for output - this way your interface to the overall system doesn't change, and you can only pass the parameters that are needed to the Display class methods. It also allows you to swap out Display classes is you need to at some point, as long as the interface is consistent. Post some actual code and we can take a look.
-
What's your docker-compose file look like? Also, I recommend using docker locally for development as that way it's completely portable. You'll be able to work off line, and every system you (or a teammate) uses to develop on will be identical. Getting the docker-compose file correct will build all the local containers, so it's really not an extra step.
-
Assuming you're just looking at your development environment, you're going to want to use Docker on your local PC. Docker Desktop for Windows makes the installation straight-forward, but creating a custom docker environment can be confusing. As requinix says, using multiple smaller images will make your life easier in long run so look at the documentation for docker-compose. If you start from a basic php image it's fairly simple to set up a local development environment (feel free to DM me if you have questions). I will admit that deploying via docker is something I'm still exploring and don't have a lot of experience with, so I can't be much help on that side of things at the moment.
-
You could use modern browser technology with flex or grid. Or add a third div to the left and use vw units to size all three.
-
Calling an API and Testing within PHP (noobie help needed)
maxxd replied to GalenAltaiir's topic in PHP Coding Help
You can use plain php curl, but honestly I think it'll be easier to deal with if you use Guzzle. I find it much easier, especially when dealing with passing tokens and keys and whatnot; as the docs say: $client = new GuzzleHttp\Client(); $res = $client->request('GET', 'https://api.github.com/user', [ 'auth' => ['user', 'pass'] ]); echo $res->getStatusCode(); // "200" echo $res->getHeader('content-type')[0]; // 'application/json; charset=utf8' echo $res->getBody(); // {"type":"User"...' Give it a shot and come back with code if something goes weird. -
Seemingly unconnected file causing header mash up
maxxd replied to TechnoDiver's topic in PHP Coding Help
If you've got files that are strictly php, don't use the close tag (?>). More than likely, this is where your issue is coming from - some IDEs will add a new line at the end of files. If the php is closed, this is output to the browser and will blow up any header interaction. If the php is not closed, however, it'll be interpreted as whitespace in the code and ignored. -
OK, now we've got the part of the code that matters. It would also be very helpful if you would provide any errors that are happening, or just what is happening in general. That being said, there are a few things; first and foremost, your mail host is smtp.office365.com, but you've turned off SMTP in PHPMailer by commenting out the $mail->isSMTP() line. Secondly, as far as I know, there isn't a `smtp/PHPMailerAutoload.php` file - the instructions tell you to include `vendor/autoload.php` and then use the PHPMailer, SMTP, and Exception namespaces. And finally, turn on verbose error reporting with the line $mail->SMTPDebug = SMTP::DEBUG_SERVER and see what's actually happening behind the scenes. One more thing I forgot. send() doesn't return a boolean, it throws an error on failure so put all of the PHPMailer code inside a try...catch block.
-
You should include PHPMailer in your php file, then use it to send the email after the record has been successfully added to the database.
-
Also, both methods should be using prepared statements - the delete is being driven off a $_GET variable. Not sure what the overall code base is that this came from, but I'd recommend not trusting anything you see in there all that much...
-
php Mail Contact Form - File Attachment - Not sending file
maxxd replied to cocolembo's topic in PHP Coding Help
Do yourself a favor and use PHPMailer - it's far easier and more robust than PHP's native mail() function. It also has great debugging output. -
It's a prepared statement, hence the prepare() method called on the $connection object. It's the correct way to run a query in PHP these days, so well done! In the SQL statement passed to the prepare() method, the `:username`, `:emailbox`, and `:passwordbox` are placeholders in the query. When you pass an array to execute(), that array contains the values to use in those placeholders, so the ':username', ':emailbox', and ':passwordbox' there are keys for the array so that SQL knows which value to plug in to each placeholder. Basically, using prepared statements blocks a potential avenue that hackers can use to attack your database or get your data. There are other benefits to prepared statements, but that's kind of the biggest and more pertinent for most systems.
-
Display list of records ordered by frequency of use
maxxd replied to NotionCommotion's topic in PHP Coding Help
To tell you the truth, I thought rebooting a server would destroy the cache - I think it used to maybe? Or maybe I'm just remembering incorrectly. At any rate, yes ElastiCache is strictly AWS though I think everyone has their own versions. It's also easy to get mixed up because AWS also has it's own ElasticSearch implementation that isn't called ElastiCache and isn't related in any way. Because apparently they ran out of 2 and 3 letter abbreviations to use... Anyhow, I wasn't involved in setting it up but from the AWS console it looked to me like ElastiCache basically is a Redis cluster. And though I disagree with how we used Redis in the past, I will say there were only a handful of times it fell out of sync or lost data, and those were due to bugs in the code and not server or service failure. And if you're using it as intended it really is just a cache, so if you do lose something it shouldn't be a catastrophic loss - in my case, it was several weeks to a month or so of playing catch-up and rehydrating accounts that were affected but we didn't know until the user complained. -
Hidden text could be seen as keyword packing by search engines, and can hurt your ranking. WP Bakery is a paid plugin, so I'd honestly be a bit surprised if it doesn't do what it claims. The problem could be over-nested elements or, as requinix stated a couple times, the class is assigned to the wrong container element. If it truly doesn't handle the issue, request your money back and be vocal if the author gives you any guff about it.
-
Given what you've posted, there isn't an action later in the page. You're checking for a value in $_POST, which will be set on page load after clicking a fomr's submit button (assuming that form's action parameter is set to 'post'). So you can check if $_POST['cat_title'] is set at the top of your page and redirect if it is. You don't want to render half a page then redirect a user anyway, right?
-
Display list of records ordered by frequency of use
maxxd replied to NotionCommotion's topic in PHP Coding Help
Basically, business logic was designed and built around data being in the store as if it was persistent. Redis was treated as a first-class database and there were portions of logic that would fail catastrophically if the node was unavailable. Technically possible (obviously) just terrifyingly fragile IMO. -
Display list of records ordered by frequency of use
maxxd replied to NotionCommotion's topic in PHP Coding Help
Not saying it's a perfect use case, but it does lend itself fairly well. Persistence is always a consideration with Redis, but honestly with ElastiCache for Redis and the like, restarts aren't that prevalent in my experience. That having been said, my last job abused the crap out of Redis so my attitude may be a bit skewed by Stockholm syndrome... -
Display list of records ordered by frequency of use
maxxd replied to NotionCommotion's topic in PHP Coding Help
You could store usage stats in a Redis hash by user ID, option ID, and number of times selected. Get the top n option IDs per user and grab those from the database. Depending on how often your users interact with the system, you may not even have to crank up the TTL for the hash. -
In that case, Strider64 has given you your answer. Use JavaScript's test method.
-
Showoff. 😜
-
It sounds like you're using procedural programming, in which case I'd go with defining the variables as you need them. If you're using OOP I recommend defining any class properties at top of the class, before the constructor - with PHP it's not technically necessary, but I find it cleaner. As far as the use of isset() on null or == "", try empty(). empty() returns true if the variable is false (which null and "" equates to) or if the variable doesn't exist, so it covers all your angles with one check.
-
I don't know exactly what you mean by this, but android supports HTML 5 semantic markup. If you want to make sure the email actually exists, I believe there are services that can do this. I've not used one so I can't vouch for the accuracy or operation, but a Google search should return some good places to start.