문제

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?

도움이 되었습니까?

해결책

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

should be

<a href="<?php echo $baseurl . ":5000"; ?>"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top