search

Home  >  Q&A  >  body text

php - How to jump to different pages based on the URL

In PHP, how to jump to different pages based on the URL

For example

When the user accesses

https://www/?a=*

automatically jumps to

https://www/?b=*

How should PHP code be written?

ps: The equal sign is followed by any number. According to different numbers, jump to different pages

某草草某草草2821 days ago871

reply all(5)I'll reply

  • 怪我咯

    怪我咯2017-05-16 13:18:18

    I don’t understand PHP, but there is an idea.
    Before the user accesses (or after accessing https://www/?a=*), first trigger a public event. This event can be written on the front end or at the end. terminal, pass a parameter to this event, and perform a second jump access based on the parameter;
    For example, first visit https://www/?a=*, then jump to a blank page (it can also be made into a refresh current page ), when the page is initially loaded

    $(function(){
        $.ajax({
            type:"Post",
            url:'XXX',
            data: {"a":"传的参数值"},
            Success:function(result)        
            {
                switch(result)
                {
                    //根据需要来写
                }
            }
        })
    })
    

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:18:18

    Get the number
    Judge based on the number
    headerJump

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:18:18

    There are many methods:

    • phpheader

    • jslocation.href

    • Some php frameworks come with jump functions, such as tp, ci's Redirectfunction, etc.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-16 13:18:18

    <?php
    
    $version = intval($_GET['a']);
    if ($version === 1) {
        header('Location: http://www.baidu.com');
    } else if ($version === 2) {
        header('Location: http://www.sina.com.cn');
    }

    reply
    0
  • 某草草

    某草草2017-05-16 13:18:18

    <?php
    $arg = isset($_GET['a']) ? $_GET['a'] : '';
    if( !empty($arg) ) {
     switch($arg) {
         case 'one':
             header('Location:'.$toUrl);        //$toUrl为要跳转的链接
             break;
         case 'two':
             /*
             your code here
             */
         default:
             break;     
     }
    }

    reply
    0
  • Cancelreply