{"id":378,"date":"2021-11-29T08:34:27","date_gmt":"2021-11-29T08:34:27","guid":{"rendered":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/?p=378"},"modified":"2021-11-29T11:39:19","modified_gmt":"2021-11-29T11:39:19","slug":"creating-a-login-file","status":"publish","type":"post","link":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2021\/11\/29\/creating-a-login-file\/","title":{"rendered":"Creating a Login File"},"content":{"rendered":"\n<p>Most websites developed with PHP contain multiple program files that will require access to MySQL and will thus need the login and password details. Therefore, it\u2019s sensible to create a single file to store these and then include that file wherever it\u2019s needed.<\/p>\n\n\n\n<p>The <a href=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/data\/login.txt\" data-type=\"URL\" data-id=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/data\/login.txt\">login.php<\/a> file:<\/p>\n\n\n\n<p><strong>&lt;?php \/\/ login.php<br>$hn = &#8216;localhost&#8217;;<br>$db = &#8216;publications&#8217;;<br>$un = &#8216;username&#8217;;<br>$pw = &#8216;password&#8217;;<br>?&gt;<\/strong><\/p>\n\n\n\n<p>Type the example, replacing username and password with the values you use for your MySQL database.<br><\/p>\n\n\n\n<p>The hostname localhost should work as long as you\u2019re using a MySQL database on your local system, and the database publications should work if you\u2019re typing the examples I\u2019ve used so far \ud83d\ude42<br>The enclosing tags are especially important for the login.php file,<\/p>\n\n\n\n<p>because they mean that the lines between can be interpreted only as<br>PHP code. If you were to leave them out and someone were to call up the file directly from your website, it would display as text and reveal your secrets. But, with the tags in place, all that person will see is a blank page. The file will correctly include your other PHP files.<\/p>\n\n\n\n<p>The $hn variable will tell PHP which computer to use when connecting to a database. This is required because you can access MySQL databases on any computer connected to your PHP installation, and that  potentially includes any host anywhere on the web. However, the examples in this chapter will be working on the local server.<\/p>\n\n\n\n<p>The database we\u2019ll be using, $db, is the one called publications that we created earlier.<\/p>\n\n\n\n<p>Another benefit of keeping these login details in a single place is<br>that you can change your password as frequently as you like and<br>there will be only one file to update when you do, no matter how<br>many PHP files access MySQL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most websites developed with PHP contain multiple program files that will require access to MySQL and will thus need the login and password details. Therefore, it\u2019s sensible to create a single file to store these and then include that file wherever it\u2019s needed. The login.php file: &lt;?php \/\/ login.php$hn = &#8216;localhost&#8217;;$db = &#8216;publications&#8217;;$un = &#8216;username&#8217;;$pw &hellip; <a href=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2021\/11\/29\/creating-a-login-file\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Creating a Login File<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/378"}],"collection":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=378"}],"version-history":[{"count":4,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":395,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions\/395"}],"wp:attachment":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}