How to get current page full url in php | Use super global variables to get current page full url in php

How to get current page full url in php | Use super global variables to get current page full url in php 

To get current page url in php there is super global variables like $_SERVER 

<form action="<?php $_SERVER['REQUEST_URI'] ?>" method="post">
        <div class="mb-3">
            <label for="comment" class="form-label">Type your comment</label>
            <textarea class="form-control" name="comment" id="comment" cols="10" rows="3"></textarea>
        </div>
        <button type="submit" class="btn btn-info">Post a Comment</button>
      </form>

In this code REQUEST_URI is used to get full url  of current page.

One more example on this are given below


<!--php
    if(isset($_SESSION['loggedin']) && $_SESSION['loggedin']==true){
       echo '
        <div class="container"-->
          <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
             <div class="mb-3">
                 <label for="comment" class="form-label">Type your comment</label>
                 <textarea class="form-control" name="comment" id="comment" cols="10"
                    rows="3"></textarea>
              </div>
                  <button type="submit" class="btn btn-info">Post a Comment</button>
              </form>
          </div>';
        }
        else{
          echo '
            <div class="container">
            <p class="lead">Please login to post comments</p>
            </div>';
        }
     ?>


Comments