Only need a printed value from included.php file

Discussion in 'PHP' started by basketmen, Oct 17, 2013.

  1. #1
    Hi guys,

    - in index.php, i included another file, that is included.php
    include "included.php";
    PHP:
    - this is the included.php file content, its including another file too, that is included2.php
    
    include "included2.php";
    $name = echo "$list->hospital['room']";
    
    PHP:
    - i only need a variable value that already printed & processed in included.php, that is people name,
    and just get the name printed value in index.php, without including included2.php file too,
    maybe processing included2.php just need to stop in included.php file

    please help how to do that guys
    i already tried add return; in the last included.php file line, but looks like still not works
     
    basketmen, Oct 17, 2013 IP
  2. jscg

    jscg Well-Known Member

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    3
    Trophy Points:
    108
    Digital Goods:
    2
    #2
    remove "echo" from $name variable and on your index.php use: echo $name;

    Anyway maybe i missunderstand this :) if yes than make better description of what you need.
     
    jscg, Oct 17, 2013 IP
    basketmen likes this.
  3. basketmen

    basketmen Well-Known Member

    Messages:
    837
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #3

    thank you for the reply, but its not what i need. current index.php file already can print name value, but its looks like also get the whole included2.php file content, so too big to execute, i just need the name value, without the entire included2.php file content
     
    basketmen, Oct 17, 2013 IP
  4. jscg

    jscg Well-Known Member

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    3
    Trophy Points:
    108
    Digital Goods:
    2
    #4
    So you want stop including included2.php file on the index.php ? Whats content on the included2.php file ? past it here.
     
    jscg, Oct 17, 2013 IP
  5. basketmen

    basketmen Well-Known Member

    Messages:
    837
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #5
    yes like that

    included2.php file is the script configuration file, that connected to the database, the size is very big 180kb, this is the problem

    i just need to get the printed name value that already a text, for example : john, that should be only 0.00000001 kb :D
     
    Last edited: Oct 17, 2013
    basketmen, Oct 17, 2013 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    If you include files, all of their content will, naturally, br included. Hence you get access to everything. If the size of the included file exceeds some sort of filesize limit or execution time, there's something very wrong with the design of the site.
     
    PoPSiCLe, Oct 17, 2013 IP
    basketmen likes this.
  7. jscg

    jscg Well-Known Member

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    3
    Trophy Points:
    108
    Digital Goods:
    2
    #7
    Well if you stop including the file which holds your database connection how you would than fetch those results from your database ? You want something which is really unpossible. Your file will never be 1kb :)
     
    jscg, Oct 17, 2013 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    Why in God's name does the script configuration take up 180kb? You do not pull everything from db once, you pull what's needed when it's needed.
    But, assign the value to a session variable , and use that to pull what's needed.
     
    PoPSiCLe, Oct 17, 2013 IP
  9. basketmen

    basketmen Well-Known Member

    Messages:
    837
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #9
    the name value already printed when i open included.php in address bar, for example john, is there methode to catch/fetch that text john into index.php?

    if using assign the value to a session variable, please give tutorial link if any
     
    basketmen, Oct 17, 2013 IP
  10. jscg

    jscg Well-Known Member

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    3
    Trophy Points:
    108
    Digital Goods:
    2
    #10
    Anything you do your file will be never 0.00000001 kb as you stated on your post.
     
    jscg, Oct 18, 2013 IP
  11. basketmen

    basketmen Well-Known Member

    Messages:
    837
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #11
    teehee what do you mean, thank you for replying, liked your post & PoPSiCLe

    btw i get 1 more methode, using file_get_contents, in index.php i try use this
    $name = file_get_contents("http://www.domain.com/included.php");
    PHP:
    the result, i get the text value, but its just showing text 0, because the server that fetch the included.php file, not client computer,
    still thinking if there other methode or tricks






    tried this in included.php too
    
    include "included2.php";
    $name = echo "$list->hospital['room']";
    
    if ($_REQUEST['do'] == 'test')
       {
    echo $list->hospital['room'];
       }
    
    PHP:
    and use include this in index.php file
    include "save2.php?do=useridwc2";
    PHP:
    still not works, still requesting the entire included2.php file
     
    basketmen, Oct 18, 2013 IP
  12. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #12
    Okay this madness has to stop.

    I'm sorry to tell you this, but your code is a disaster. You're hacking solutions into your code that are hard to maintain and even harder to work with. How about this: You create a new file that includes a function that gets/returns the data you want to put into your site.

    functions.php:
    
    function getName()
    {
        /* Do whatever you need to do to get this data */
        return $list->hospital['room'];
    }
    
    PHP:
    ... then in index.php:
    
    require_once 'path/to/functions.php';
    $name = getName();
    
    echo $name;
    
    PHP:
    ... and then you just call the function whenever you need the name.
     
    nico_swd, Oct 18, 2013 IP
    basketmen likes this.