Results 1 to 10 of 10

Thread: How to send argument through php include?

  1. #1
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to send argument through php include?

    Code:
    include("language.php?show=lang");
    Throws up this:

    Warning: include(language.php?show=lang) [function.include]: failed to open stream: Invalid argument in C:\Program Files\xampp\htdocs\display.php on line 65

    Warning: include() [function.include]: Failed opening 'language.php?show=lang' for inclusion (include_path='.;C:\Program Files\xampp\php\pear\') in C:\Program Files\xampp\htdocs\display.php on line 65
    This is language.php:

    Code:
    <?php
    /* Simply edit the following line to translate Free Smileys into your own language. */
    $themsg="Like this smiley? Simply click the box above and copy its contents, then paste it into the message box.";
    /*Uncomment the following line if you have translated the above to another language*/
    $difflang=" (EN)";
    
    if ($_GET["show"] == "lang") {
    	echo $difflang;
    }
    else {
    	echo $themsg;
    }
    ?>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The included page will inherit $_GET from its parent, so modify $_GET there:
    Code:
    $_GET['show'] = 'lang';
    include('language.php');
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Does not work.

    Code:
    echo '<font size="1">', include("language.php"), '<br />
    Free Smileys 0.9.1.1<script>
    <!--
    document.write(unescape("&#37;3Cscript%3E%0A%3C%21--%0Adocument.write%28unescape%28%22%253Cscript%253E%250A%253C%2521--%250Adocument.write%2528unescape%2528%2522%252520-%252520%25253Ca%252520href%25253D%252522http%25253A//www.a2h.8m6.net%252522%25253Eanger2headshot%25253C/a%25253E%2522%2529%2529%253B%250A//--%253E%250A%253C/script%253E%22%29%29%3B%0A//--%3E%0A%3C/script%3E"));
    //-->
    </script>';
    $_GET['show'] = 'lang';
    include('language.php');
    echo '</font>
    	            </td>
    	          </tr>
                 
    
    	          
    	      </table>    
    </body>
    
    </html>';

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following

    Code:
    include 'http://www.yourserver.com/language.php?show=lang';

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Check the following example

    PHP Code:
    //This is the file which I am going to be include in my second file
    //file name: inc.php
    echo "$var"
    PHP Code:
    //The main file which will be browsed using a browser.
    //file name: first.php
    $var="lang";
    include 
    'inc.php'
    Enter the following address

    http://localhost/first.php

    The $var is available in the inc.php.

  6. #6
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    Try the following

    Code:
    include 'http://www.yourserver.com/language.php?show=lang';
    NOT a good idea - this is the display part of an SMF modification, and so giving all users the same domain to link to would not be a good idea - SMF is a forum system for those who don't know.

    Quote Originally Posted by codeexploiter View Post
    Check the following example

    PHP Code:
    //This is the file which I am going to be include in my second file
    //file name: inc.php
    echo "$var"
    PHP Code:
    //The main file which will be browsed using a browser.
    //file name: first.php
    $var="lang";
    include 
    'inc.php'
    Enter the following address

    http://localhost/first.php

    The $var is available in the inc.php.
    Same result turns up.

  7. #7
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    It worked for me in my machine and according to PHP manual this is the way. My first response might not be correct but definitely my second response worked for me.

    You can check the PHP manual -> Search for include and in the include statement tutorial check the example 11-5

    What is your PHP version?

  8. #8
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    XAMPP
    [PHP: 5.2.1]
    I might as well upload both files for you to have a look at. Be sure to comment out the line requiring SMF's SSI.php in display.php...

  9. #9
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following code in place of your display.php code
    PHP Code:
    <?php
    // Version 0.9.1.1 of the Free Smileys mod
    // Language translators, please check the lang.php file instead.

    require("../SSI.php"); 
    echo 
    '<html>

    <head>
    <title>Free Smileys Mod</title>
    <!-- The ?rc3 part of this link is just here to make sure browsers don\'t cache it wrongly. -->
        <link rel="stylesheet" type="text/css" href="'
    $settings['theme_url'], '/style.css?rc3" />
        <link rel="stylesheet" type="text/css" href="'
    $settings['default_theme_url'], '/print.css?rc3" media="print" />
    </head>

    <body class="windowbg">

                
                <script language="javascript">
                  function next()
                  {
                    try{
                      setTimeout(\'randomImage("http://skins.hotbar.com/skins/mailskins/em/google_emoticons/emoti_","gif",484)\',200);
                    } catch(Error) {}
                  }
                  
                  next();
                  
                </script>
                <script language="javascript">
                function randomImage(baseURL,ext,maxNum)
                {
                    try {
                          randNum= Math.floor(Math.random()*maxNum);
                          randNum++;
                          var url = baseURL+randNum+"."+ext;
                          emoti.src = url;
                          emoti.style.visibility="visible";
                             box.value = "[img]" + url + "[/img]";    
                     } catch (error) {alert(error);}
                }</script>
                
                <table border="0" align="center">
                 <tr>
                <td valign="middle">
                <script>
    <!--
    document.write(unescape("%3Cbutton%20name%3D%22fetchnewsmiley%22%20onclick%3D%22next%28%29%22%3E%3Cimg%20src%3D%22fetchnewsmiley.gif%22%3E%3C/button%3E%3Cinput%20type%3D%22text%22%20name%3D%22box%22%20id%3D%22box%22%20value%3D%22%22%20size%3D%22100%22%20onClick%3D%22javascript%3Athis.focus%28%29%3Bthis.select%28%29%3B%22%3E"));
    //-->
    </script>
              </td>
                  </tr>
                  <tr height=150>
                    <td align=center valign=center>
                      <img id=emoti style="visibility:hidden" border="0"><br />
    <font size="1">'
    . include("language.php"). '<br />
    Free Smileys 0.9.1.1<script>
    <!--
    document.write(unescape("%3Cscript%3E%0A%3C%21--%0Adocument.write%28unescape%28%22%253Cscript%253E%250A%253C%2521--%250Adocument.write%2528unescape%2528%2522%252520-%252520%25253Ca%252520href%25253D%252522http%25253A//www.a2h.8m6.net%252522%25253Eanger2headshot%25253C/a%25253E%2522%2529%2529%253B%250A//--%253E%250A%253C/script%253E%22%29%29%3B%0A//--%3E%0A%3C/script%3E"));
    //-->
    </script>'
    ;
    $show 'lang';
    include(
    'language.php');
    echo 
    '</font>
                    </td>
                  </tr>
                 

                  
              </table>    
    </body>

    </html>'
    ;
    ?>
    It worked for me once I comment that require line without any problem. I strongly suggest to test the above mentioned code in place of your original display.php page and make sure that the path information is correct.

  10. #10
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK...

    OH SHOOT, I OVERWRITED LANGUAGE.PHP WITH AN OLDER VERSION

    Oh wait, there's a copy in the first post...

    Let's see...

    Well it appears the credits have been removed and so has the (EN) message...

    You replaced ', include(language.php), ' with full stops!

    Code:
    <?php
    // Version 0.9.1.1 of the Free Smileys mod
    // Language translators, please check the lang.php file instead.
    
    //require("../SSI.php"); 
    echo '<html>
    
    <head>
    <title>Free Smileys Mod</title>
    <!-- The ?rc3 part of this link is just here to make sure browsers don\'t cache it wrongly. -->
        <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?rc3" />
        <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/print.css?rc3" media="print" />
    </head>
    
    <body class="windowbg">
    
                
                <script language="javascript">
                  function next()
                  {
                    try{
                      setTimeout(\'randomImage("http://skins.hotbar.com/skins/mailskins/em/google_emoticons/emoti_","gif",484)\',200);
                    } catch(Error) {}
                  }
                  
                  next();
                  
                </script>
                <script language="javascript">
                function randomImage(baseURL,ext,maxNum)
                {
                    try {
                          randNum= Math.floor(Math.random()*maxNum);
                          randNum++;
                          var url = baseURL+randNum+"."+ext;
                          emoti.src = url;
                          emoti.style.visibility="visible";
                             box.value = "[img]" + url + "[/img]";    
                     } catch (error) {alert(error);}
                }</script>
                
                <table border="0" align="center">
                 <tr>
                <td valign="middle">
                <script>
    <!--
    document.write(unescape("&#37;3Cbutton%20name%3D%22fetchnewsmiley%22%20onclick%3D%22next%28%29%22%3E%3Cimg%20src%3D%22fetchnewsmiley.gif%22%3E%3C/button%3E%3Cinput%20type%3D%22text%22%20name%3D%22box%22%20id%3D%22box%22%20value%3D%22%22%20size%3D%22100%22%20onClick%3D%22javascript%3Athis.focus%28%29%3Bthis.select%28%29%3B%22%3E"));
    //-->
    </script>
              </td>
                  </tr>
                  <tr height=150>
                    <td align=center valign=center>
                      <img id=emoti style="visibility:hidden" border="0"><br />
    <font size="1">';
    include("language.php");
    echo '<br />
    Free Smileys 0.9.1.1 - <a href="http://www.a2h.8m6.net">anger2headshot</a>';
    $show = 'lang';
    include('language.php');
    echo '</font>
                    </td>
                  </tr>
                 
    
                  
              </table>    
    </body>
    
    </html>';
    ?>
    This new version isn't working well either...

    BTW (language.php from the first post, not the one in the zip file!)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •