Question

I'm working on a PHP script for my homeserver. Sometimes I access the homeserver webpage in my home network (from IP 192.168.192.*) and sometimes from the outside (public IP-address). I've created the following script for this:

<?php
    $baseurl = $_SERVER['REMOTE_ADDR'];
        if (preg_match("/192.168.192.*/",$baseurl)) {
            $baseurl = "http://192.168.192.100";
            }
        else {
            $baseurl = "http://homeserverwebsite.com";
            }
?>

When I use <?php echo $baseurl; ?> somewhere on my webpage it works! From the outside it replies http://homeserverwebsite.com (adres to my homeserver) and from my internal network http://192.168.192.100 (which is my homeserver IP).

However there is a problem. For building my links I use the folling code:

<a href="<?php $baseurl . ":5000"; ?>" target="_blank">Link to website 1</a>
<a href="<?php $baseurl . ":5001"; ?>" target="_blank">Link to website 2</a>

When I click it internaly, it will send me to http://192.168.192.100 and I want it to send me to http://192.168.192.100:5000.

When I use <?php echo $baseurl . "5000"; ?> somewhere on the webpage it works fine, it outputs http://192.168.192.100:5000 but not when I use it in the tag. How is this possible? :( It seems like the doesnt want an URL with URL:PORT links in it if they are generated by PHP? How can I get passed this?

Was it helpful?

Solution

<a href="<?php $baseurl . ":5000"; ?>"

should be

<a href="<?php echo $baseurl . ":5000"; ?>"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top