Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

3 Neutral

About Junitar

  • Rank
  1. Junitar

    Constants usage

    Got it. Thank you very much!
  2. Junitar

    Constants usage

    Thanks for the reply. But then, what's the benefit of using, e.g. dirname(__DIR__) over $_SERVER['DOCUMENT_ROOT']?
  3. Junitar

    Constants usage

    Hello, I was wondering if it's good practice and if it's safe to define constants that use magic constants to access various directories in a project, even directories outside the webroot. I've found many documentations that discuss how useful are constants when debugging, but what's the usual usage apart from that? For example, is it good practice to write: <?php define('WEBROOT', __DIR__); define('ROOT', dirname(WEBROOT)); define('CORE', ROOT.'/core/'); define('CONFIG', ROOT.'/config/'); define('ADMIN', ROOT.'/admin/'); include CORE.'includes/header.inc.php';
  4. Oops, my bad… Messed up the variable name I wrote in the post with the real variable name I used in my code. It's of course !in_array($id, $galleriesId) Though, I did make a mistake with the || and &&, thanks for pointing it out! Ok, that was it. I had HTML above the PHP code. I've just made the changes to my code, placing the PHP part containing the header() before the doctype tag and it's now working. Spent so much time trying to figure out what was wrong… wasn't even aware of that. Well thank you very much for the help dsonesuk. Thanks also Gabrielphp for
  5. Hello, I've a photo gallery on my site that loads its content based on URL parameter (which is basically the name of the folder the images are taken from). I would like to make a redirection to the main galleries page if the parameter does not exist, is empty or wrong. I'm using an if statement with the header function but can't manage to get it work. $galleryId is the id of the current gallery and $galleriesId is an array containing all the actual galleries id. Here is the code: $id = $_GET['id']; if (isset($id) || !empty($id)) { // Check if the current gallery id match
  6. 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 =
  7. 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.
  8. 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
  9. Thank you very much for the example!
  10. 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?
  11. 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
  12. 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.
  13. Works like a charm. Thank you very much!
  14. 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' &&
  15. Thanks for the clarification! Everything's clear.
  • Create New...