TheFilmGod Posted January 15, 2007 Share Posted January 15, 2007 Hey! I'm coding a website that is dynamic. - it uses php include for its sidebar elements so one text file change would edit the whole site. My question results from these elements refering to images/something.jpg The problem here is that if the web page that is being viewed is not in the top directory then images/something.jpg would not work. So a few possible solutions would be to use a meta tag with base url (that refers all pages to the top directory links), or using php variables in the elements depending where the page is located. So what is better using a meta HTML tag, or using some awesome php. Which one would be more google friendly? thanks! Link to comment https://forums.phpfreaks.com/topic/34187-html-or-php/ Share on other sites More sharing options...
emehrkay Posted January 15, 2007 Share Posted January 15, 2007 use ../ to go up one directory ../../ for two and so on Link to comment https://forums.phpfreaks.com/topic/34187-html-or-php/#findComment-160849 Share on other sites More sharing options...
bqallover Posted January 15, 2007 Share Posted January 15, 2007 Yes, this can be a headache at first. :)I tend to create a variable called $siteroot, or some such, in my header.php file that I include on every page. This is usually set to '/', as that will give you the web server's html root directory when it's up and live. While I'm developing though I set it to the sub-folder of the project I'm working on, e.g. '/mynewsite/'. I then reference links and images, etc. like "<a href=\"{$siteroot}images/pic.jpg\"/>". In this way, paths will always be valid no matter where they are referenced from.There may be a better way to do this, but that's what I do. Link to comment https://forums.phpfreaks.com/topic/34187-html-or-php/#findComment-160854 Share on other sites More sharing options...
Hypnos Posted January 15, 2007 Share Posted January 15, 2007 Two ways to solve this common problem, that come off the top of my head:1. Absolute paths to your images. Use a $siteroot var like bqallover suggested, then server moves and home development will be easier.Example:[code=php:0]$siteroot = "http://www.google.com/";echo '<img src="' . $siteroot . 'logo.png'">';[/code]2. You can use the HTML base tag with the absolute site path. Example:[code=php:0]<html><head><base href="http://www.google.com/"></head><body><img src="logo.png"></body</html>[/code]Both methods do basicly the same thing. Link to comment https://forums.phpfreaks.com/topic/34187-html-or-php/#findComment-160902 Share on other sites More sharing options...
Hypnos Posted January 15, 2007 Share Posted January 15, 2007 Blah, ran out of edit time.Now that I've reread your question, to answer it I would now say, "It does not matter".Both will output valid HTML. Both will link to your images correctly. Neither is easier/harder. It's just a matter of choice. Link to comment https://forums.phpfreaks.com/topic/34187-html-or-php/#findComment-160904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.