0

Hello. I am trying to get the correct code in order to get specific content shown according to the current site the visitor is on.

I have done two tests:

<!--START TEST 1-->
<?php
class address
{
    function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
}

$current = new address;
$current->curPageURL();
$address2 = "http://www.mydomain.com/travel/hotels/jaco";
if($current == $address2) {
        echo "HELLO WORLD!";
    }

?>
<!--END TEST 1-->

<!--START TEST 2-->
<?php

$address = $_SERVER['REQUEST_URI'];
$address2 = "http://www.mydomain.com/travel/hotels/jaco";
if($address == $address2) {
        echo "HELLO WORLD!";
    }

?>
<!--END TEST 2-->

By the way, on my .htaccess I have some rewrite rules, for example:

RewriteRule ^hotels/jaco$ index.php?p=1&q=jaco&region=1

The working directory is /travel

Please, any help would be greatly appreciated.

Kind regards.

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by P0lT10n
0

I'm no expert on classes in php but from what I have seen and used, shouldn't line 19 be something more like $curadd = $current->curPageURL(); and thus changing line 21 to if($curadd == $address2) {?

Please correct me if I'm wrong.

0

I'm no expert on classes in php but from what I have seen and used, shouldn't line 19 be something more like $curadd = $current->curPageURL(); and thus changing line 21 to if($curadd == $address2) {?

Please correct me if I'm wrong.

Wow, that exactly did it! I'm a beginner programmer, so thanks a lot!!! That was a nice lesson, thanks again Nyight. I'm gonna test tomorrow with the complete cases and then post back.

0

You're welcome :) and if all is solved make sure to mark the post as solved lol.

Hi. In the end, it worked just fine. This is the code I used. Surely it could much less code, but I'm a beginner. Thanks for your help.

<?php
class address
{
    function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
}

$current = new address;
$curadd = $current->curPageURL();
$address1 = "http://www.eco-vacationscostarica.com/travel/hotels/arenal-volcano";
$address2 = "http://www.eco-vacationscostarica.com/travel/hotels/jaco";
$address3 = "http://www.eco-vacationscostarica.com/travel/hotels/mal-pais-santa-teresa";
$address4 = "http://www.eco-vacationscostarica.com/travel/hotels/manuel-antonio";
$address5 = "http://www.eco-vacationscostarica.com/travel/hotels/monteverde";
$address6 = "http://www.eco-vacationscostarica.com/travel/hotels/nosara";
$address7 = "http://www.eco-vacationscostarica.com/travel/hotels/osa-peninsula";
$address8 = "http://www.eco-vacationscostarica.com/travel/hotels/puerto-viejo";
$address9 = "http://www.eco-vacationscostarica.com/travel/hotels/punta-islita";
$address10 = "http://www.eco-vacationscostarica.com/travel/hotels/san-jose";
$address11 = "http://www.eco-vacationscostarica.com/travel/hotels/tamarindo";
$address12 = "http://www.eco-vacationscostarica.com/travel/hotels/tortuguero";
$address13 = "http://www.eco-vacationscostarica.com/travel/eco-special-deals";
$address14 = "http://www.eco-vacationscostarica.com/travel/eco-hotels";
$address15 = "http://www.eco-vacationscostarica.com/travel/favorite-eco-packages";
$address16 = "http://www.eco-vacationscostarica.com/travel/favorite-eco-hotels";
if ($curadd == $address1) {
    include("includes/arenal-volcano");
} elseif ($curadd == $address2) {
    include("includes/jaco");
} elseif ($curadd == $address3) {
    include("includes/mal-pais-santa-teresa");
} elseif ($curadd == $address4) {
    include("includes/manuel-antonio");
} elseif ($curadd == $address5) {
    include("includes/monteverde");
} elseif ($curadd == $address6) {
    include("includes/nosara");
} elseif ($curadd == $address7) {
    include("includes/osa-peninsula");
} elseif ($curadd == $address8) {
    include("includes/puerto-viejo");
} elseif ($curadd == $address9) {
    include("includes/punta-islita");
} elseif ($curadd == $address10) {
    include("includes/san-jose");
} elseif ($curadd == $address11) {
    include("includes/tamarindo");
} elseif ($curadd == $address12) {
    include("includes/tortuguero");
} elseif ($curadd == $address13) {
    include("includes/eco-special-deals");
} elseif ($curadd == $address14) {
    include("includes/eco-hotels");
} elseif ($curadd == $address15) {
    include("includes/favorite-eco-packages");
} elseif ($curadd == $address16) {
    include("includes/favorite-eco-hotels");
}

?>
0

Hey, tick solved, and would be more easier if you use

$_GET['']

ex. I want to show news if you go to news, but in the same page... my page is example.com, and in the menu you have products = url(http://www.example.com?data=products) and news = url(http://www.example.com?data=news)...

// First form to show...

<?php

$type = $_GET['page'];

if($type == "news"){
     // do include("news.php"); or with code, show news page.
}else{
     // do include("products.php"); or with code, show news page.
}

?>

// Second form to show...

<?php

$type = $_GET['page'];

switch($type){
     case "news":
          // do include("news.php"); or with code, show news page.
     break;
     case "products":
          // do include("products.php"); or with code, show products page.
     break;
     // if you have more, do another case
     default:
          // do include("home.php"); or with code, show home page.
     // do break; or not, here anyways finish the switch.
}

?>

Is more easir to do, and will do the same... you dont have to use objects in php for select type or url of web page... you can do this...

AND if you want to do it the way you coded it, do swtich, is more efficient...

<?php

switch($curadd){
     case $address1:
          include("includes/arenal-volcano");
     break;
     case $address2:
          include("includes/jaco");
     break;
     case $address3:
          include("includes/mal-pais-santa-teresa");
     break;
     case $address4:
          include("includes/manuel-antonio");
     break;
     case $address5:
          include("includes/monteverde");
     break;
     case $address6:
          include("includes/nosara");
     break;
     case $address7:
          include("includes/osa-peninsula");
     break;
     case $address8:
          include("includes/puerto-viejo");
     break;
     case $address9:
          include("includes/punta-islita");
     break;
     case $address10:
          include("includes/san-jose");
     break;
     case $address11:
          include("includes/tamarindo");
     break;
     case $address12:
          include("includes/tortuguero");
     break;
     case $address13:
          include("includes/eco-special-deals");
     break;
     case $address14:
          include("includes/eco-hotels");
     break;
     case $address15:
          include("includes/favorite-eco-packages");
     break;
     case $address16:
          include("includes/favorite-eco-hotels");
     break;
}
 
?>

Edited by P0lT10n: n/a

0

Thanks P0lT10n. Thanks for simplifying things, great =)

Already marked as solved, thanks everyone.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.