LNDON SOUTH BANK UNIVERSITY COMPUTER SERVICES DEPARTMENT Embedding html and jpeg references into PHP scripts at LSBU Introduction. Because of the security mechanisms implemented at LSBU you need to ensure that your code follows the guidelines below at the development stage prior to uploading your site to the main University Web Site Directory structure ~username means the home directory of a user called username. For example, my home directory is ~swiggtc ~username/.public_html is where your web site should be uploaded. ~username/images is where you must put any image files (.jpg, .png, .gif) ~username/cgi-bin is where you must put your php scripts. Create a file called config.php4 To help make your code more portable so that minimal changes are needed between your development environment and your deployment environment put the following kinds of definitions into a file called config.php4 in the appropriate directory within the cgi-bin area. Database location, name and access (if applicable) // eg // $db_host="mysql.lsbu.ac.uk" // $db_database="username" // $db_login="username" // $db_password="mypassword" // And for images the location of the directory (within .public-html) where you put all your image files which might be // eg $images="~username/images/" $images="/~swiggtc/images/" Tom Swigg\PHPimages.doc 09 March 2016 Computer Services For each of your php scripts you will then have a statement include_once ("config.php4"); which will ensure the these definitions are available to your code, in particular the location of the images directory as ~username/images In your other php scripts, the ones that include config.php4 you can now reference images as follows. <img src="<?php echo $images?>hello-world.jpg" alt="Hello World Image" width="800" height="650"/> Here we have a normal img tag reference to an image with src, alt, width and height attributes. However, we have embedded within the html a piece of php code <?php echo $images?> which will evaluate to the location of the images directory /~swiggtc/images/ and so the value of the src attribute will be "/~swiggtc/images/hello-world.jpg" which will correctly reference the desired jpeg image. Tom Swigg\PHPimages.doc 09 March 2016 Computer Services