How to make a check, if in the url on which I am, there is the word id and there is a number next to it, then we do one thing, otherwise we do nothing?

    5 answers 5

    1) If the request is sent by a form or recorded in a standard form ( ), then the value of each such variable ( name , surname , something ) can be obtained through $_GET superglobal arrays or $_REQUEST .

    Here are the links to read about them:

    2) If the request is made in another way, then you need to get the entire URL - this is done as @klopp - $url=$_SERVER['REQUEST_URI'] says @klopp - $url=$_SERVER['REQUEST_URI'] .

    About array $_SERVER .

    Next we go along the line and look for our id and what is behind it.

     for($i=0;$i+1<strlen($url);$i++) { if($url[$i]=='i'&&$url[$i+1]=='d') { //обрабатываем ситуацию } } 

      If you need the digit id, then $_GET['id'] .

        The URL is pulled from $_SERVER['REQUEST_URI'] .

          I would just get the entire url and check the condition using regular expressions . The preg_match () function is fine.

          • one
            @Hlogeon, We need to remember that while the regular expression is being executed, the kitten has time to die somewhere in the world. )) Therefore, if there is an opportunity, then we must try to do without regulars. - Deonis
           echo $_SERVER["REQUEST_URI"]; 

          do not forget to put a tick in the circle)

          • one
            @cnofss, and this is nothing, that the question was asked more than 2 years ago and it already has answers better than yours? And your answer practically repeats the answer of the user @klopp. - VenZell
          • one
            Now, now, I will open the tunnel only in 2012. - etki