1

I'm trying to dynamically insert an URL in an imagemap using PHP.

  1. I check if the current URL contains a substring.
    If yes the url will be ...
    If no the url will be..
  2. In case there is a problem with PHP I do a check if the variable $myurl exists.
    If not assign a default value to $myurl
  3. Then I insert the variable $myurl in the imagemap.

However it doesn't work. When I move the mouse over my image map I see this as URL: <?= $myurl ?> What did I wrong?

The code:

[1]
if (strpos($_SERVER['REQUEST_URI'], "/nl/") !== false){
   $myurl = "url2"
} else {
   $myurl = "url1"
}

[2]
if (!isset($myurl)) {
    $myurl = "url1"
} 

[3]
<img src="../imagemap_blue.png" usemap="#imagemap2">
<map name="imagemap2">
<area shape="rect" alt="" coords="15,5,302,55" href="<?= $myurl ?>">
</map>
Reman
  • 7,931
  • 11
  • 55
  • 97

1 Answers1

2

Does your server support the short tags? If not (perhaps you're using a version of PHP earlier than 5.4), maybe try replacing

 <?= $myurl ?>

with

<?php echo $myurl; ?>

Or try setting short_open_tag to "1" if you can: https://www.php.net/manual/en/ini.core.php

If that doesn't work either, the standard php open/close tags aren't working correctly, and you need to figure out why that is. Make sure your file has a .php extension on the end. Make sure you have an actual server (localhost or an external one) you're opening your page on.

Esn024
  • 63
  • 8
  • While plausible on the face of it, it's worth noting that if this solves the problem the OP must be using PHP 5.3 or older, [which has been out of official support for well over 6 years](https://www.php.net/eol.php)! Since version 5.4, `=` doesn't require that setting. – IMSoP Jan 02 '21 at 11:18
  • Thank you, but it still doesn't work. I just see ` ` as url – Reman Jan 02 '21 at 12:37
  • short_open_tag=On – Reman Jan 02 '21 at 14:05
  • Well, just some guesses... does your file have a .php extension on the end? (Obviously the standard php open/close tags aren't working correctly, so you need to figure out why that is). I also notice that you don't have semicolons at the end of your statements in examples [1] and [2], I wonder if that's messing anything up? E.g. I would replace `$myurl = "http://www.remcon.com"` with `$myurl = "http://www.remcon.com";`. I've often had strange problems appear because I forgot to add a semicolon to the end... – Esn024 Jan 02 '21 at 21:45
  • The other thing I can think of is that you don't have a server running? – Esn024 Jan 02 '21 at 22:04