Jump to content

HTML or PHP?


TheFilmGod

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.