I know it must be very simple for php programmers out there, but... I need help.🙂

These are the tabs inside the page: TABS.

<a class="active" href="?id=1&page=1">mine</a>
<a class="active" href="?id=1&page=2">lage</a>
(and so on)

What is the php statement for capturing or getting the current URL address to replace the "id" part? For example:

I'm guessing this php statement: echo "http://" . $SERVER['HTTP_HOST'] . $SERVER['REQUEST_URI'];

The concept what I want is:

<a class="active" href="$SERVER['REQUEST_URI'];&page=1">milese</a>
<a class="active" href="$
SERVER['REQUEST_URI'];&=1&page=2">lane</a>

Need the replacement part for the current URL of a page but I'm keeping the &page=# part as a manual code.

Thanks much!

    I might do something like:

    <?php
    $page = $_SERVER['REQUEST_URI'];
    $page .= (strpos($page, '?') !== false) ? '&' : '?';
    ?>
    <p><a href='<?php echo $page; ?>page=1'>Page 1</a></p>
    <p><a href='<?php echo $page; ?>page=2'>Page 2</a></p>
    

      Thanks NogDog for the direction.

      Here is one problem (anyone helps?): URL addition when it should be a replacement in the browser location.

      For example, when clicking on the tab, the results show like this in the browser location:
      index.php?id=1&page=2&page=3&page=1 (and so on whenever clicking on any pane tabs inside the page)

      It needs to be index.php?id=1&page=2 to index.php?id=1&page=1 (or 3 or whatever) and so on when clicking on a tab.

      Here is the full php:

      <?php
      $currenturl = $SERVER['REQUEST_URI'];
      $currenturl .= (strpos($currenturl, '?') !== false) ? '&' : '?';
      $page = isset($
      GET['page']) ? $_GET['page'] : 1;
      ?>

      <div class="tabpage" id="tabpage">
      <div class="tabs">
      <a <?=($page == 1) ? 'class="active"' : '';?>href="<?php echo $currenturl; ?>page=1">tab 1</a>
      <a <?=($page == 2) ? 'class="active"' : '';?>href="<?php echo $currenturl; ?>page=2">tab 2</a>
      [and so on]
      </div>

      <div class="panes">
      <div class="pane" style="display: <?=($page == 1) ? 'block' : 'none';?>">
      <div class="pad">

      content

      </div> .......

      Thanks!

        Hmm...how about:

        <?php
        $page = $_SERVER['SCRIPT_NAME'];
        $get = $_GET;
        if(isset($get['page'])) {
           unset($get['page']);
        }
        $urlParts = array();
        foreach($get as $key => $val) {
           $urlParts[] = urlencode($key) . '=' . urlencode($val);
        }
        $urlParts[] = 'page=';
        $page .= '?' . implode('&', $urlParts);
        ?>
        <p><a href='<?php echo $page; ?>1'>Page 1</a></p>
        <p><a href='<?php echo $page; ?>2'>Page 2</a></p>
        

          Thank you very much! I'm grateful.

          NogDog;10978733 wrote:

          Hmm...how about:

          <?php
          $page = $_SERVER['SCRIPT_NAME'];
          $get = $_GET;
          if(isset($get['page'])) {
             unset($get['page']);
          }
          $urlParts = array();
          foreach($get as $key => $val) {
             $urlParts[] = urlencode($key) . '=' . urlencode($val);
          }
          $urlParts[] = 'page=';
          $page .= '?' . implode('&', $urlParts);
          ?>
          <p><a href='<?php echo $page; ?>1'>Page 1</a></p>
          <p><a href='<?php echo $page; ?>2'>Page 2</a></p>
          

            You can actually simplify with the help of [man]http_build_query/man, e.g.,

            <?php
            $get = $_GET;
            if(isset($get['page'])) {
               unset($get['page']);
            }
            $page = $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($get) . '&page=';
            $page = htmlspecialchars($page);
            ?>
            <p><a href='<?php echo $page; ?>1'>Page 1</a></p>
            <p><a href='<?php echo $page; ?>2'>Page 2</a></p>

              Thank you, laserlight! I will try it too.

              laserlight;10978791 wrote:

              You can actually simplify with the help of [man]http_build_query/man, e.g.,

              <?php
              $get = $_GET;
              if(isset($get['page'])) {
                 unset($get['page']);
              }
              $page = $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($get) . '&page=';
              $page = htmlspecialchars($page);
              ?>
              <p><a href='<?php echo $page; ?>1'>Page 1</a></p>
              <p><a href='<?php echo $page; ?>2'>Page 2</a></p>
                Write a Reply...