Search code examples
phpgetrequest

PHP get method strangely working I don't know how solves


I need get method but not working

my code :

<?php
    $page = $_GET['page'] ? intval($_GET['page']) : 1;
    echo "current page : ".$page."<br/>";
?>

and

$page's result is 1. but i try www.example.com/test.php?page=3

$page's result is still output 1.

Why is this happening?


Solution

  • At first you should check if is page setted, then you can access page

    try this:

    if(isset($_GET['page'])){
        $page = $_GET['page'] ? intval($_GET['page']) : 1;
        echo "current page : ".$page."<br/>";
    }
    

    here is the result i am getting:

    result