URL querystring with a php include

后端 未结 3 1983
太阳男子
太阳男子 2020-12-06 07:04

I\'m trying to include a file to output in a tab on a page. The file itself will pull up just fine, but when I try to add the required querystring to it, it gives me a \"fa

相关标签:
3条回答
  • 2020-12-06 07:47

    I created a variable on the 2nd page - and passed it a value on the first page - and it worked for me:

    *Page with include: 'index.php'
     <?php $type= 'simple'; include('includes/contactform.php'); ?>
    
    
    *Page included: 'includes/contactform.php'
    
     switch($type){
      case 'simple':
       //Do something simple
      break;
    
      default:
       //Do something else
      break;
     }
    
    0 讨论(0)
  • 2020-12-06 07:48

    I modify the accepted answer given by Frank Farmer a bit to work for different queries:

    Include twice would cause problem:

    $_REQUEST['mls'] = $_REQUEST['mlid'];
    $_REQUEST['lid'] = 0;
    $_REQUEST['v'] = 'agent';
    include("agentview.php");
    
    //changing the v to another
    $_REQUEST['v'] = 'agent2';
    include("agentview.php");
    

    For those who encounter this multiple include problem, you could wrap you code inside "agentview.php" in a function:

    Inside agentview.php

    function abc($mls,$lid,$v){
       ...your original codes here...
    }
    

    file need to call agentview.php

    include_once("agentview.php");
    abc($_REQUEST['mlid'], 0, 'agent');
    abc($_REQUEST['mlid'], 0, 'agent2');
    

    Hope it helps someone encounter the same problem like me and thanks Frank Farmer for the great solution which saved me alot of time.

    0 讨论(0)
  • 2020-12-06 07:53

    You can't include a query string in an include().

    Assuming this is a local script, you could use:

    $_REQUEST['mls'] = $_REQUEST['mlid'];
    $_REQUEST['lid'] = 0;
    $_REQUEST['v'] = 'agent';
    include("agentview.php");
    

    if it's a remote script on a different server, don't use include.

    0 讨论(0)
提交回复
热议问题