Jump to content

All Activity

This stream auto-updates

  1. Today
  2. I also use intelephense in VSCode and I don't see it like it's shown in phpstorm. I have to admit i very much prefer popup on hover over inline.
  3. Yesterday
  4. I don't remember if Intelephense provided the feature or not. In fact I might not even have tried it with PHP - maybe it was another language. But I assume the concept works the same way everywhere. But yeah, the hover or autocomplete list has always been sufficient for me. Oh well, whatever works best for each person.
  5. @requinix Are you using intelephense? For me I don't get his injection in VSCode, as mouseover pops up a window that shows me the information for the function call or method.
  6. It might work a little more cleanly in PHPStorm, but when I tried it in VS Code, I found it much more complicated to try to select text or read through code when the editor was injecting those things into the view. Maybe if they weren't inline, though I can't imagine how not, they might be nicer for me... But I'm also a proponent of the idea that you should be able to tell what the parameter is, be that through a variable name or an obvious literal value (or a constant...), and if you can't tell then you should do something about that. // this is obvious on what the parameters are password_verify($password, $hashedPassword) // this is not password_verify($value, $row[1])
  7. Not sure why you would want to disable the hinting feature, which can be quite helpful in understanding what the parameters are for. However the instructions to do so are here: https://stackoverflow.com/questions/41743888/how-to-disable-parameter-name-hints-in-phpstorm
  8. RVS Media provides custom website development services designed to meet unique business goals. Our expert team builds scalable, visually engaging, and user-friendly websites tailored to your brand’s specific needs. From concept to launch, RVS Media ensures a seamless, high-quality experience that drives growth and enhances online presence.
  9. Last week
  10. Right, well things in "web space" ie. relative to the document root, should always be referenced relatively to the document root "/" which is equivalent in webspace to the document root. This is because client browsers can only see what you make available to them in web space via url's. What this means is that things like css and javascript, or images will exist in web space. Document Root relative (web space) Assume you have a header file you want to reference in your html (even if rendered by php) at: /var/www/your_project/images/header.jpg Assume that your documentRoot for your vhost is /var/www/your_project Then your header.jpg file should be referenced relative to the document root: <img src="/images/header.jpg"> The same goes for any css or js files, or any other assets you want available via a direct url. NOTE: that you should always include the beginning "/" equivalent to "document root". This also makes sure that your code is always portable and not hard coded to a specific file system structure. File System Paths PHP commands like require_once/include/fopen etc. work with files on the file system. In other words "web space" is not relevant to PHP. PHP works with files, so it must know where the files exist. With that said, it is typical, that the way to make sure that you don't need to hard wire paths all over the place is to utilize one of the PHP magic constants, and then create a relative path to include files. The best way to do this, is to establish a base variable in a known location, and then to include that file in any script that needs to use it. This can be problematic, depending on the way you have structured your project, but the general idea is to establish this basic variable using the __DIR__ magic constant. Here is a pretty good blog post covering the functions available to implement these techniques: https://www.gavsblog.com/blog/move-up-directory-levels-relative-to-the-current-file-in-php So let's assume the path is: /var/www/your_project/config In this directory you create a script named path.php <?php $baseDir = realpath(__DIR__ . '/..'); The important thing to understand is that $baseDir will be /var/www/your_project It does not matter the location of the file that includes the path.php script, $basedir will be the filesystem path. So the only thing that is important to build off the $baseDir is to include it relative to the script that needs it. At that point you can include all other paths, so long as you know them relative to your_project. So let's say that you have a bunch of scripts in a directory named "utility" one named file.php. The real path of this would be: /var/www/your_project/utility/file.php Assume that I have a script that needs to include a function defined as "function myFile($path)". We'll also assume that you have some files stored outside the webroot that you want to deliver via PHP. One in particular will be at the actual real path of: /var/www/your_project/files/pdf/info.php Assum you have an index.php file that is in a project subdirectory: /var/www/your_project/admin/index.php <?php // your_project/admin/index.php // this gets the $basePath variable require_once('../config/path.php'); // Now we need access to utility/file.php require_once($basePath . '/utility/file.php'); $result = myFile($basePath . '/files/pdf/info.pdf'); What this all does is insure that you never have to configure or hard code paths into variables or within your scripts using relative paths where you have to. For the most part, the major frameworks use techniques like these, along with front controllers to insure that you never have to hard code a specific directory path structure into your application.
  11. You are free to display the date however you choose. I want to go one step further with this, and explain that a date/datetime is relative to the locale setting for the server. There really is only one right option in my opinion and that is for the server to utilize UTC/GMT, so when a value gets stored it is assumed to be UTC. Most likely your hosting company has configured the mysql server to use UTC as its locale/timezone but you should probably check. What should you display to an end user? What they should see is relative to THEIR locale. Now you may very well want to hardcode this into your application if all your users are in one place (let's say they are in New York), which means that when you get date value from the database, you then need to convert it to the date/date time for the locale you want to present it to. The PHP datetime class has methods that do all of this for you nicely, and there are also some great PHP libraries out there that will do all sorts of fancy date to "some string" manipulations for you, depending on what you want. One I'm pretty familiar with, and is widely used is Carbon. At minimum you want to take a look at the PHP Datetime class and look at how to create and use datetime objects.
  12. With modern PHP sites, you don't want your php class and source files to be in the webroot. For the most part modern websites use a "front controller" pattern where bootstrap, config and routing is done through one script (index.php). There are many reasons for this, but even if you don't have a project that uses a front controller, you still want to move any config and include directories outside of the web root for security reasons. It also makes finding the path to those scripts simpler, but I won't go into the techniques to do that. This is all (and should be hopefully) facilitated by setting up a composer.json file for each of your projects. You can set one up for code you already having by running "composer init" in the project directory, and answering a few questions (most you will just answer no) so that it generates the composer.json file for you. You can then issue other commands or hand edit the composer.json file as per your project. For all these reaons, and as many people also use composer to generate the autoloader, you put your classes under project_name/src. Hopefully you understand PHP namespaces. You can namespace inside the src directory if you want, or not. Typically this is just a decision of having a subdirectory with some name for your company/organization etc. but you can also just forgo that and creates directories for individual types of components. So for a simple symfony project you might find in project_name/src Controller/ Twig/ Doctrine/ Repository/ Kernel.php Form/ Entity/ For any classes or function libraries you write, you should put those under the src directory, either in their own directory or (as in the case of this example, for the Kernel.php script) just at the root. The organization in there is up to you. By default, initializing a composer.json file in the project directory, will configure the autoloader to load anything inside the src/ directory so that it can be referred to via the App namespace. This is via a composer.json setting like this: "autoload": { "psr-4": { "App\\": "src/" } }, Another reason for doing this, is that when using composer, component libraries are placed in a vendor directory, but beyond that there might be tests and other artifacts. If your site uses docker, even if it is just for development you want a place for project files and directories to go that is not in web space. So the defacto standard is to have a project/public directory, which is where files that should be in webspace go. Then you map your webroot to that. There are different ways to run and configure PHP today, but the important thing is that the process that needs access to the php files be able to read them. This might be apache, but it also might be a different user, if you are using php-fpm or perhaps not even using apache as the web server, as you might with nginx. This structure has been formalized and I found this helpful repo which documents the structure and the purpose of each directory. So when developing websites this is what you typically will want to use, or will see with a framework skeleton: project_name/ ├── config ├── public (web root)/ │ ├── js │ └── css ├── bin ├── docs ├── src/ (your classes here) ├── tests └── vendor (composer will create) So essentially, things in webspace go in the public directory. Anything else stays out of webspace. That should be all files that are required/included. If you have any command line utility scripts put them in bin. For deployment on linux, often there's a default mapping of /var/www for apache, and what you can then do for any project is to move/copy/git checkout the project to /var/www/project_name. You remove the default setup and for each site, you have a vhost that sets the documentRoot to be /var/www/project_name/public for each project. This standard structure works very well from local development to eventual production deployment.
  13. Your question is not clear. Are you looking for a hosting company, or trying to do local development. Xampp has been updated to the latest PHP version. It does not use MySQL at all, but rather MariaDB. It appears that both are up to date.
  14. What I am saying is that this might be a data problem not a code problem. It is designed to show you events in the future. If the date of the events is not in the future, those rows will not be returned. That is not an error or a bug, that is working as expected.
  15. Want Host Website but PHP8 & MySQL8 was not work, which is best, Xampp is out to date like many other same panels
  16. That's a default feature of PHPStorm, at least. VSCode doesn't do it by default but I suspect there are plugins that will add the functionality.
  17. I suspect that the culprit is your IDE trying to be helpful. Check its settings.
  18. Not sure of a "Setting" in PHP as such but try this: if (password_verify($password, $hashedPassword)) { $_SESSION['user_id'] = $user['id']; $_SESSION['handle'] = $user['user_handle']; echo "Login successful! Welcome, " . htmlspecialchars($username) . "."; } else { echo "Invalid username or password."; } I removed Named Parameters: The password_verify function does not support named parameters in PHP. Therefore, I removed the 'password:' syntax to ensure the code runs correctly.
  19. In the attached image, please see the "IF" statment and it' conditions. Notice the grayed values "password:" and "hash:", which you can't delete because they're not really there. I'm using version 8.3.10 of PHP which I believe is the latest version. How do I remove this feature? Thanks, Blake
  20. Thanks to both of you. I am so new to this so got to admit I don't know what is or what, or what is the best way to do this or other things, but I am learning. So for now I move the file(s) outside of the www dir, and later when my experience has grown, I will use Moorcams solution. I Choose to do it this way because I don't need more scripting to remember now. So, for a later time when I have other things under control, I keep in mind Moorcams solution.
  21. Knowing What You Need for Connectivity: System360 IT Services is a top supplier of all-inclusive Wi-Fi solutions in Houston, committed to meeting the various connectivity requirements of homes and businesses. In the current digital world, dependable and fast internet connectivity is necessary for communication, production, and general efficiency. Recognizing this need, System360 provides a selection of services aimed at giving customers the greatest Wi-Fi experience. Personalized Site Examinations: The first step in achieving optimal connectivity is a comprehensive site evaluation. The team of seasoned experts at System360 does thorough assessments to comprehend the particular needs of every site. The space's layout, the infrastructure that is currently in place, and any sources of interference are all assessed during these inspections.Managed IT Services Expert network design Once the site assessment is completed, System360 creates a customized network design based on the client's exact requirements. Whether for a house, a small business, or a huge corporate office, the design considers the number of users, device kinds, and bandwidth needs. This ensures that the network can meet current demands while being scalable for future expansion. System360 ensures optimal performance and user satisfaction by leveraging innovative technology and best network design practices. Professional Installation With the network design completed, System360's professional experts begin the installation procedure. This stage is carried out with precision to guarantee that all components are properly installed and functioning as intended. ongoing maintenance and Server support . System360 recognizes that in order to function optimally, a Wi-Fi network must be continuously monitored and maintained. To that purpose, they provide continuing support such as check-ups, performance assessments, and troubleshooting. System360 can swiftly address any issues that develop due to proactive network management, providing minimal downtime and stable connectivity for users. Their responsive customer service team is always available to assist clients with any difficulties, giving them peace of mind knowing help is only a phone call away. Meeting a variety of needs System360 distinguishes itself by its capacity to serve a diverse range of clientele. They build home networks for residential users that may accommodate anything from smart home devices to remote work settings.
  22. I personally find it pointless moving the files to outside the www or root directory. I just use the following to protect any file from direct browser access: In this example, I will display config.php with database credentials: <?php // config.php if (!defined('ACCESS_GRANTED')) { die('Access denied.'); } $databaseHost = 'localhost'; $databaseUser = 'root'; $databasePassword = 'password'; $databaseName = 'my_database'; function connectToDatabase() { global $databaseHost, $databaseUser, $databasePassword, $databaseName; $connection = new mysqli($databaseHost, $databaseUser, $databasePassword, $databaseName); if ($connection->connect_error) { die('Connection failed: ' . $connection->connect_error); } return $connection; } ?> return $connection; } And, in the file that I want to grant access to: <?php // index.php define('ACCESS_GRANTED', true); include 'config.php'; $connection = connectToDatabase(); echo 'Connected successfully to the database.'; ?> Moving files outside the www for example, is a royal pain in the buttox and requires some file permissions etc. Just my opinion.
  23. I know a solution has been established, but just wanted to put my 2c in. Here is what I use to show content based on user roles: <?php $user_id = $_SESSION['user_id']; $stmt = $conn->prepare("SELECT role FROM users WHERE user_id = ?"); $stmt->bind_param("i", $user_id); $stmt->execute(); $stmt->bind_result($role); $stmt->fetch(); $stmt->close(); switch ($role) { case 'Admin': echo 'I am admin'; break; case 'Member': echo 'I am Member'; break; default: echo 'Whatever!'; ?>
  24. You need to give is some information as to what the actual issue is. Otherwise nobody can or will help you. Another good tip is to encase your code into the <> tag so it shows like this: <?php // database.php require_once __DIR__ . '/config.php'; // Ensure this path correctly points to config.php /** * Establish a new database connection. * * @return mysqli The MySQLi database connection object. * @throws Exception if the connection fails. */ function db_connect() { // Use MySQLi to connect to the database $connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Check if the connection was successful if ($connection->connect_error) { error_log("Database connection failed: " . $connection->connect_error); die("Database connection failed. Please check the error log for details."); } // Set the character set to UTF-8 for proper handling of characters if (!$connection->set_charset("utf8mb4")) { error_log("Error setting character set utf8mb4: " . $connection->error); } return $connection; } /** * Close an existing database connection. * * @param mysqli|null $connection The connection object to close. * @return void */ function db_disconnect($connection) { if ($connection instanceof mysqli) { $connection->close(); } } // Establish a connection and store it in the variable $db for use later $db = db_connect(); // You can now use $db for your database queries It makes it easier to read. Also, no need for this: if ($connection instanceof mysqli) { $connection->close(); } PHP automatically closes connections. Okay, your turn
  25. This one - in millions of database tables the world over. But if you don't have the sense to follow the best-practice approach then be prepared for slower queries, more date problems and more work.
  26. Thank you! It worked. I did, however, look at the FETCH modes you linked to and chose FETCH_BOTH as I need both. If I were to write the whole script all over again I would use ASSOC here, but when I wrote this particular tool (it’s a seating chart) I didn’t know how to do something like this ${‘cell’.$count} and I’m spending so much time re-writing so much code to bring my PHP5 code up to PHP8 functionality standards that I just can’t re-write the entire tool the way I’d like to. THANK YOU for your help!!!
  27. Store date values in Date fields. MySQL knows how to do "date things" with Date fields, including sorting them. It doesn't know how to do "date things" with Varchar fields. Convert your data [once], store it correctly, and wave goodbye to [almost] all your date-related problems. Regards, Phill W.
  28. 20000 thanks to each of you. I am not sure if my hosting company allows access to such settings mac_gyver this would be very helpful. I am yet to find a good hosting company with proper tech support and services. Barand it is not just for being pretty. On what planet we start the date with year? It is like starting an address with the country. That said, you been very helpful and you can start the date with seconds as far as I am concerned.
  1. Load more activity
×
×
  • 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.