"getting current url" Answer’s

0

From the reference:

<?php

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;
}
?>
Wednesday, March 31, 2021
 
iftheshoefritz
answered 10 Months ago
0

This will give you the current url:

window.location.pathname

edit:

$.getJSON("idcheck.php?callback=?", { url:  window.location.pathname }, function(json){
  //alert(json.message);
});

edit 2: Using PHP (found via)

<?php
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;
}
?>


$.getJSON("idcheck.php?callback=?", { url:  "<?php echo curPageURL(); ?>" }, function(json){
  //alert(json.message);
});
Friday, October 8, 2021
 
Dzawor
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :