• Content count

  • Joined

  • Last visited

Community Reputation

3 Neutral

About Junitar

  • Rank
  1. Thanks for your reply. If I understand correctly, all I've to do to protect my gmail password and username once my site is ready to go online, is to organize my folders on the server that hosts my website like so: :SERVER: myMainFolder _________|_________ | | iniFilesFolder websiteFilesFolder | ______|___________________ | | | | file.ini index.php contact.php ….php and then retrieve my password by adding the following lines in my PHP script: $ini = parse_ini_file('/myMainFolder/iniFilesFolder/file.ini', true); $mail->Username = $ini['email']['username']; $mail->Password = $ini['email']['password']; With the file.ini being something like: [email] username = myUsername password = myPassword Is that correct?
  2. You have to set your html and body height to 100% to make your div height: 100% work. I guess you want to center your logo vertically like in the image you showed. To do so, you can either use flexbox or if you want to support IE ≤ 9, you can wrap your logo in a div the size of your logo and style it like so .logo_wrapper { position: absolute; top: 0; right: 0; bottom: 0; left: 0; height: 100px; /* height of your logo */ width: 100px; /* width of your logo */ margin: auto } BTW, you've an extra closing div in your code right after the closing script tag.
  3. Hi, I'm using PHPMailer to send email from a contact form using gmail SMTP which requires to include the SMTP password directly in the PHP script like so $mail->Password = 'mypassword'; According to what I've found on the net, it seems that it's not recommended since the password can be easily hacked. Thus, I'm wondering how to do to protect my password. I've found people recommending to put the password in an INI file outside the webroot and then to retrieve it using parse_ini_file() function. My problem is that I'm not sure I understand the "outside the webroot" part… if anyone could explain this to me and how to do it, it would be much appreciated. Also, should I protect the INI file with a .htaccess? Thanks.
  4. Thank you very much for the example!
  5. Thank you very much for your input and for the link. I will test it as soon as my site is online. 1a and 2b (after switching <section> with <article> and vice versa) would then be the best options. What do you think about wrapping the orange and red elements into a <section> like in 1a? Knowing that there won't be any other <section> in the <main> tag, do you think it still makes sense or it's just unnecessary? I would tend to say it's unnecessary, can you confirm that?
  6. Hello, I’m restructuring the html code of my site to have the best semantic markup as possible but I struggle with the <article> and <section> tags. I know there are lots of documentations on the internet on how to use these tags. I’ve read many of them but the more I read about <article> and <section>, the more I get confused on how to use them properly, mainly because I’ve seen a lot of contradictory examples from a site to another. I understand that a <section> is used to regroup elements sharing information on a similar thematic whereas an <article> refers to an independent content that is reusable outside the document. It sounds simple in theory but in practice, it's very tricky, at least for me. I’ve made different templates of my "about" page which is he most complex page I have (in regard to semantic), and I would appreciate if you could tell me which of the following images is the most semantically correct or if you have other suggestions I could take into consideration. Beside the <section>/<article> thing, I also question myself on the need of using a single <section> in the <main> container… Do I need to regroup all my "about" elements inside a <section> tag if there is no other <section> in the document? Fig. a Fig. b and 4b -> just like 3b with the blue containers being different <section> instead of being different <article>. 4b is how my page is currently structured. Any help would be appreciated. Thanks!
  7. I'm not a PHP expert but for your first question, I would recommend you to use the FilesystemIterator class (implemented in PHP ≥ 5.3). I've just finished doing an image gallery for my project and this is the easiest, most straigth-forward approach I've found. Here is an example on how to use it: $dir = '/yourDirectory'; $fileDir = new FilesystemIterator($dir); // creates a new instance of the class as $fileDir foreach ($fileDir as $file) { if ($file->getExtension() == 'jpg') { // lists all .jpg in $dir echo '<img src="'.$file.'"/> '; } } Hope that helps.
  8. Works like a charm. Thank you very much!
  9. Hi, I would like to list all the items contained in a folder except for 2 or 3 specific ones. For example, let's say I've item 1, item 2, …, item 10 in /myFolder. I would like to list all the items of /myFolder but item 1, item 3 and item 4. I've come up with the following code which does the work but looks a bit awkward. <?php $dir = '/myFolder'; $filesDir = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS); $fileName = ''; foreach ($filesDir as $file) { $fileName = $file->getBasename(); if ($fileName != 'item1' && $fileName != 'item3' && $fileName != 'item4') { echo $fileName.'<br>'; } } Is there a simple and more elegant way to accomplish this? Any help would be appreciated, thanks!
  10. Thanks for the clarification! Everything's clear.
  11. Thank you very much Ingolme for your example, I understand it now! Yes, I guess it's a good enough reason. Sorry if my question was dumb but I wanted to understand why it was a bad thing not to initialize variables first. I started learning PHP 2 days ago and I don't have enough experience in programming to know it could cause a program to crash. I got it now anyway, thanks.
  12. Thank you to you both for your thorough feedbacks. I'm afraid it's still a bit fuzzy in my mind right now and the fact my English is limited sure doesn't help. I understand that a variable is used to store a content and it doesn't make sense to call a variable that doesn't exist. But in my example, I declared my variables later in the code: … $errors['name'] = 'alert'; … $name = sanitize_input($_POST['name']); … $email = sanitize_input($_POST['email']); … this is why I don't completely understand the need of specifying at the beginning that $errors = [], $name = '', $email = '', etc. If I write: <?php $test['letter1'] = 'a'; $test['letter2'] = 'b'; print_r($test); // the output is Array ( [letter1] => a [letter2] => b ) my array is well declared and ready to be used without being initialized using $test = []. I guess the answer to my question is somewhere in and
  13. Hello, I've just read the tutorial on how to process a form in PHP, available on this site, and I was wondering if there's a specific reason to declare empty variables (or arrays) at the beginning? I don't understand what is the point of doing so. For example, in the following code, why would the 2sd and 3rd lines be necessary? <?php $errors = []; $name = $email = $message = ''; if (condition) { $errors['name'] = 'alert'; } else { $name = sanitize_input($_POST['name']); if (new_condition, $name) { $errors['name'] = 'new alert'; } }
  14. Thank you to confirm my thoughts. I had a doubt after I stumbled upon an old thread on stackoverflow where a guy implied this kind of code was possibly flawed.
  15. Hi, I'm new to PHP and I was wondering if it's perfectly safe to use $_SERVER['PHP_SELF'] like so: <body<?php if(basename($_SERVER['PHP_SELF']) == 'home.php') echo ' class="home"'; ?>> … </body> As far as I understand, the $_SERVER['PHP_SELF'] variable can only be exploited when used as a link or in a form/inputs, where the variable should be wrapped into htmlspecialchars() to counter XSS attacks, am I right?