-
Posts
6,101 -
Joined
-
Last visited
-
Days Won
159
Everything posted by gizmola
-
I don't think you understand rewrites. Rewriting in this way allows you to use a non-existent url like /slugname/ to the scripts that can actually process them. You can't "rewrite" the actual scripts to a non-existent url. They could never be resolved. Rewrites are not magical "rewrite my url's to the rest of the world on the fly". It's the responsibility of your markup and code to display your url's in the virtual/ pre-rewritten form you want users to see them. If I've misunderstood your statement, please let respond with a specific example as in: Client sends https://www.domain.com/a/ ---> Server rewrites to https://www.domain.com/page.php?slug=a
-
The fields that are part of the result from 4 joined tables, isn't really important in comparison to the number of rows in the result set, and any limiting where clause criteria. As @requinix stated: EXPLAIN query... is your analysis tool. We'd need to see the query and its explain plan to offer further insight. Many times, if performance is bad, you'll be able to see the reasons in the explain. Depending on the criteria, adding a covering index might solve your performance issue, but the only way to know for sure is via the explain. You want to take a look at the rows and key columns to see how many rows are being examined, and what indexes (if any) are used in generating the final result.
-
trying to insert multple form data into msyql database
gizmola replied to jcarney1987's topic in PHP Coding Help
There are different strategies for handling multiple entries, but the one employed most frequently is to implement some javascript that will allow you to add a new form group to the table dynamically, using an "Add another item" button or something similar. Rather than trying to make the input names unique, utilize array name syntax like so: echo '<td><input class="item" name="item_number[]"></td>'; Once you do this, $_POST['item_number'] will be an array, and you can foreach() through it to validate data and do as many inserts as you have validated items. Hopefully, it is clear that you will use the array syntax with all the fields, and when you dynamically add a new input row, be sure to also use that syntax for the dynamically created row/input group. -
Warning: file_exists(): open_basedir restriction in effect. File
gizmola replied to kako0000000's topic in PHP Coding Help
Gonna throw out my best guess here, based on the snippet and some variable naming, that OP has gotten a script designed to be run from the cli, that automates interaction with some crypto faucets. OP didn't write the app, doesn't really know PHP, isn't likely to learn it, and is just trying to run this script to get it running as a means to an end. Script contains features designed to isolate it from anything else that might be running on a server offering PHP. -
PHP is in a pretty good place now, and is a very different experience than what it was 10 years ago. With that said, it's really not a highly used Devops/sysadmin language. Neither is Perl, for that matter. Devops, and the emergence of the practice of Devops will likely be new to you. It's where system administration has evolved to. Here are the main take aways in my opinion: Virtualization/The Cloud is pervasive Much of hosting is done on virtualized servers. So familiarity with the different types of virtualization is highly valuable In addition/ Containers (Docker, Kubernetes, etc) have been taking over application development, and increasingly production deployments DevOps makes git and hosted git repositories a core component of deployment and administration. You have to know git well, and the options for hosted git like github, gitlab and bitbucket DevOps groups use Hashicorp Terraform for "infrastructure as code" to setup/teardown/alter complicated environments in the cloud The tools for additional provisioning and maintenance of servers continues to evolve Chef and Puppet were both popular and continue to be used by many orgs, but Ansible and Salt(stack) have emerged as alternatives for automation of administrative tasks Ansible and Salt are both written in Python Chef is written in a combination of Ruby/Erlang Puppet was originally written in Ruby, but has evolved into a hybrid c++/clojure/ruby product Once you start using any of these provisioning/admin tools, you end up focused on their recipes/modules and in some cases, you might be able to extend them, or use elements of the core language. Notice that there is no java/javascript/php or perl to be found in this list. I don't mean to discourage you from jumping into modern PHP development, but it has to be said, that it's not a big player in the world of System administration/Devops, so you might be better off learning Python & Ansible if you plan to get back into hosting & system administration.
-
Add some extra checks in to prevent the rendering of dates in the table if they are in the past. This should work: <section class="content" id="termin"> <?php $dt = new DateTime; $thisWeek = $dt->format('W'); $thisYear = $dt->format('o'); if (isset($_GET['year']) && $_GET['year'] >= $thisYear && isset($_GET['week']) && $_GET['week'] >= $thisWeek ) { $dt->setISODate($_GET['year'], $_GET['week']); } else { $dt->setISODate($dt->format('o'), $dt->format('W')); } $year = $dt->format('o'); $week = $dt->format('W'); ?>
-
I don't understand the question. You created the table with code to have a range of days and times. Your code created the table. What would you want to be different about the days or times output?
-
HTML5 date inputs have a min/max attributes you can set. See the mozillla page.
-
You need to define what "not working correctly" means. $mail->Host = 'localhost'; This tries to send mail through your server. That is not going to work. With godaddy, you need to send your email through their mail servers. Typically they provide that information to you in some fashion.
-
This is going to be a little more complicated with your date string, because you will need to turn the date string back into a valid javascript date, so that you set your form date element value. See if you can figure out how to do that. I'll give you a hint, on how to strip out the <br> tag from the date string, leaving you only with the text. function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; console.log('dateValue: ' + dateValue); dateValue = dateValue.replace('<br>', ' '); let dateEl = document.getElementsByName("tDatum"); let timeEl = document.getElementsByName("tVreme"); dateEl[0].value = dateValue; timeEl[0].value = time; } Another hint: google for javascript Date.parse()
-
You should see a pattern by this point, in terms of how you select a dom element in html. So long as the element has an id, you can use: let someVar = document.getElementById('someId'); So that is one way. You did not give your form elements id attributes. It would be simpler if you did in this case. However, there are other ways to select an element into a javascript variable. Since you did use name attributes, you can use that. However, the same name can be used for multiple elements, so you would need to do this instead. function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; console.log('dateValue: ' + dateValue); let dateEl = document.getElementsByName("tDatum"); let timeEl = document.getElementsByName("tVreme"); dateEl[0].value = dateValue; timeEl[0].value = time; } You reference the 0th element in the arrays returned by getElementsByName, which is fine in this case, because we know that there is only one form element with that name in your html document.
-
The time is being passed as the 2nd parameter as a string. In my function it was named time. If you console.log('Time:' + time); you should see the value.
-
Pictures of code don't help either of us. If you need to, you can paste your code into the forum here, or you can use a pastebin like the one on my site here: https://forum.gizmola.com/pastebin/
-
You also did not see that I did not provide you the complete code for setting the 2 form element values. Prior to adding that code you first should console.log the values inside MyFunction so that you can test that the onclick is doing what you want it to do. <script type='text/javascript'> function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; console.log('dateValue: ' + dateValue); } </script>
-
To be clear that refers to changes to the timeslots function. Put that back to the way it was in your original post.
-
As for it disappearing, there's clearly some bug in your code. I don't know exactly what your code looks like, but you need to debug the html using devtools, to see what has gone wrong. You should revert the changes suggested by Barand, back to your original code if you plan to use the ideas I have proposed. They are based on your original code.
-
Also, you have not given your table an id. In my example, it would need to be <table id="myTable">
-
No you missed the fact that the column needs to be incremented for each cell. MyFunction(0, MyFunction(1, MyFunction(2, ... MyFunction(6,
-
This is why I linked you to the github project. Did you take a look at it? Clone and run it locally? Try and understand what it does and how it is designed? It's essentially a sort of PHP SPA. If you look at all the functions I had to add for the simple routing and handling of the form, you get an idea of what a routing class, or the HTTP classes that lots of projects (Laravel included) borrow from the Symfony components. In summary, frameworks are a collection of different component classes, usually with things like configuration figured out. My demo project includes use of a "dotenv" processing class, which is best practice for web app configuration of things like database credentials which should not be hard coded and stored in your source code repository. You don't have to use use an entire framework, but instead can use components you find helpful. Also, again, DBAL wraps PDO. By using DBAL, you will be using PDO, only in a simplified form. It has some very nice features, one I illustrated and documented. When you use symfony or laravel, you won't be using PDO directly -- you use their ORM that then uses PDO for you. My project would have been even smaller and simpler if I'd used the Symfony Http foundation component. My point is, that modern PHP development should always start with the user of composer, and a skeleton directory setup with a /public directory where directly executable scripts will go. All classes should go into either your own component, or in an app space. You make at most a few modifications to the composer.json, and as you develop, rely on composer to generate the autoloader you need, which you include in any of the script that directly execute within /public. An alternative to that is to create a bootstrap include that does the same thing, and include that in all your directly executable scripts.
-
Please read my updated post. It has nothing to do with the database. It is the way you created the html table of dates and times. The dates in the first table row are in no way connected to the times, and I don't think Barand saw that. If you had one unified computation that would be a better solution, but I basically provided you a hacky way of getting to where you want to be, albeit in a less elegant way. Using data-* elements are a better practice for connecting static data to html elements, which would be simpler, but you would also have to rewrite things that already work for you, and I would suggest you just get it working with what you have.
-
You have painted yourself into a bit of a corner because the Dates computed in the first row are disconnected from the time period slots. When you click on a cell in the table, you not only need to determine what the time period is, but also what day that time period is relevant to. This is essentially what Barand is trying to help with. While I agree that would be a great solution, I don't think he realized that the timeslots don't correspond with the dates, so this is not going to work, until a connection is made between the two. One way to get around this would be to use javascript to get the date value from the first row, and the corresponding column inside MyFunction. To facilitate this you should give the table an id, so you can select it easily. Then you can do something like: function MyFunction(col, time) { const tbl = document.getElementById("myTable"); let dateValue = tbl.rows[0].cells[col].innerHTML; // Set the Form Date element value using dateValue // Set the Form Time element value using time ) Change the table output to something like this: <td><a href="#" onclick="MyFunction(0, '<?php echo $ts; ?>');return false;"><?php echo $ts; ?></a></td> <td><a href="#" onclick="MyFunction(1, '<?php echo $ts; ?>');return false;"><?php echo $ts; ?></a></td> etc.
-
Warning: file_exists(): open_basedir restriction in effect. File
gizmola replied to kako0000000's topic in PHP Coding Help
These messages are all related to the open_basedir settings of your php installation. You need to locate the php.ini file for your system. Either a script that only has phpinfo(); in it, or use of cli php run with php -i will let you see where the configuration file(s) are located. On most systems, the base php.ini will load files in a subdirectory like /etc/php.d. You can ignore those files if they do exist, as the open_basedir configuration will be in the main php.ini script. The first place to look would be /etc/php.ini, but you need to be sure that you are editing the actual php.ini being loaded when you run your script. In some cases, there are different php.ini files so that php used with a web server can be configured differently from the cli version you use to run command line scripts with. Once you are sure you are changing the correct php.ini, edit it with a text editor and look for the line open_basedir = You can either add the directories in question to the list you find, or disable it entirely by adding a ; before the line like this: ;open_basedir = If this script is being run through a webserver, then you would want to restart the web server, or possibly php-fpm, if that is your web server configuration. If this is a cli script, running it again after you added the directories or disabled open_basedir should solve the issue. -
It would be helpful if you provided the version of libssh on the client server running php, as well as the php version. Likely this issue is that you have libssh2, and the message is telling you that the key exchange doesn't work. This is because libssh2 upon which the php routines were built, used diffie-hellman-group1-sha1, and the version of openssh no longer will accept that exchange, hence the error. To understand why this all came about, you can read about the Logjam exploit which attacked the SHA1 key exchange, as well as recommended configuration changes to a variety of commonly used services. While openssh was not specifically vulnerable to logjam, given its focus on openssl, there was still a concern that the key exchange had a weakness, so support for diffie-hellman-group1-sha1 was removed from openssh. This page has more specifics. So at this point, you should be able to remedy the problem with an upgrade of libssh2 to a more modern version (version >= 1.7) which supports newer key exchange methods. One alternative to the reliance on the php extension would be to modify your code to use phpseclib instead, which supports modern servers.
-
I'm with @requinix -- Webalizer is pretty much a dead product. I believe that AWStats is the defacto standard FOSS web log reporting tool, being that it is typically bundled with CPanel. It's probably the closest thing to what Webalizer was, only it continues to be maintained and enhanced. It's a package of perl scripts, and is highly portable, as it mainly requires perl, and has documentation for installation, and in your case, has a windows installer. There are many log analysis systems that go far beyond the web, and for that reason, are often used instead of AWStats, and of course a lot of people just use google analytics or commercial alternatives. Most large commercial websites use multiple services to provide different types of analysis, including bug logging, which is not something traditional web analytics products try to track or categorize. With that said, there are numerous alternatives to awstats you might want to investigate. GoAccess is one that I'd recommend looking into. It also has to be said, that these products go through your http logs, and as the old saying goes, are subject to the possibility of GIGO (garbage in/garbage out), by which I mean, that they work with the data available to them in the http logs. In many cases, the default settings for apache or IIS are not sufficient to support accurate or enhanced reporting, depending on your environment. Often you need to modify the log format (as in for example, using enhanced log format) and/or creating a custom log format, that bakes in data specific to your system like specific cookies or non-default client IP settings. That's up to you, as well as automating ingestion of log files, or movement of log files from another server to an intranet or your workstation.
-
Oracle database has been around a long time, and has a lot of features and extensions that are specific to it. If you are not going to use it immediately, or need a certification for a job, I wouldn't recommend going down that rabbit hole, even though I do think that Oracle database is a great RDBMS in many ways, but it is commercial and expensive. You often see it paired with java/enterprise java applications. For reasons I won't go into, besides cost, very few people pair PHP with Oracle database. The open source database closest in design and features to Oracle is Postgresql, so if anything, exploring postgresql would be a step in that direction. Since you use SQL Server, I would suggest getting certs in that, and in particular, learn about the specific things you listed, like transactions and concurrency (locking), and Views, stored procedures and triggers. Sprocs and Triggers are very important and highly used in SQL server development (Transact-SQL aka T-SQL), and in Oracle (which has an entirely different stored procedure language). MySQL also has stored procedures & triggers, but they are not commonly used, in comparison to the way that they are very often baked into applications that use sql server on the backend, as is the case with a lot of .NET applications. I don't think you can really say you are confident in your SQL knowledge until you are confident in the many ways you can use joins (including self joins), and the use of grouping and aggregation, as these are some of the primary reasons people use relational databases. It also helps to learn about the way rdbms's work in terms of datatypes, constraints and indexes. You want to have a good working understanding of the different types of indexes and the ways they overlap with primary key/unique constraints. You also really need to understand concurrency and locking, as it pertains to each database, and an understanding of transactions as well as "2 phase commit" support. While all the major relational database engines have configuration options that can be used to alter the concurrency/locking models, MySQL (and forks like MariaDB) is particularly different in that it allows for the use of different engines. For example, the original MySQL engine (myisam) is very different from the popular InnoDB engine that most companies use. It's a simple example, but MyISAM has no support for transactions, so you can write code that starts transactions and commits or does a rollback, and mysql will happily except that code, when in fact it actually ignores those statements entirely and doesn't support transactions whatsoever. You also want to understand how you install and configure these databases, and what options and tradeoffs might be involved in how you set them up. This affects how a database might/might not recover from a crash/ lose some data/transactions (or not), have backup options, or support replication in various flavors. With the existence of Docker, it's now much easier to experiment and learn about these databases, and create local test configurations. I think it helps to keep in mind, that there are categories of developers (DB Architects & Administrators & DB developers) who specialize in these products, and they have extensive levels of depth to them. There are some well known experts with books you might be interested in. A couple off the top of my head, are Joe Celko, who wrote some well known SQL books, and Tom Kyte, who authored many books on Oracle, and was well known for his "Ask Tom" column where he answered oracle questions and demonstrated ways certain problems could be solved. PHPFreaks is fortunate to have a number of developers who have consistently shared their expertise with relational database design and SQL, so this is still a great place to get advice and in many cases example code.