php-starter seeking 4 help :)

Discussion in 'PHP' started by sunbeam, May 4, 2006.

  1. #1
    lo ppl, just a few months of php experience on amateur-level and im starting to need some help from pros :)

    here is what im trying to do:
    i have 2 webserver, im running on the 1st an application, and on the second one i want to store some simple variables.

    on my first server, in the index.php file, im including the file from the second server like:

    include("http://my_second_server/thepath/thefile.php");

    this file has only one variable,

    <?php
    $thevariable = "looser" ;
    ?>

    so, what to do, so i can use the index.php file from the fisrt server, to output the word "looser" ???

    i tried as the index.php file that :

    <?php
    include("http://my_second_server/thepath/thefile.php");
    echo "you are a $thevariable" ;
    ?>

    why isn't that working, and what do i have to do so it is going to work ??

    your help is appreciated
     
    sunbeam, May 4, 2006 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Some, sorry most servers block access so people can not require include ect files

    This is saftey, otherwise people can just include the file and see the code. Horrible
     
    onlyican.com, May 4, 2006 IP
  3. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it seems that my server allows the include to take place, i added on the include file thefile.php

    <?php
    $thevariable = "looser" ;
    echo "you are a $thevariable" ;
    ?>

    and when i call the index.php file (from the first server)

    <?php
    include("http://my_second_server/thepath/thefile.php");
    echo "YOU MUST BE A ".$thevariable." WHEN YOU CANT DO THAT" ;
    ?>

    im getting on the screen

    you are a looserYOU MUST ME A WHEN YOU CANT DO THAT

    somehow on the index.php, the $thevariable cant be displayed
     
    sunbeam, May 4, 2006 IP
  4. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #4
    Try modifying file's attributes/privileges. But that WILL pose a security risk!
     
    mihaidamianov, May 4, 2006 IP
  5. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    what do you mean by that ? what file to modify its attrib's ? and what to set as attibutes ?
     
    sunbeam, May 4, 2006 IP
  6. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #6
    file: thefile.php
    attributes: start from 666 downwards
     
    mihaidamianov, May 4, 2006 IP
  7. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    tried from 666 to 555 to 444, nothing worked :(
     
    sunbeam, May 4, 2006 IP
  8. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Have you tried TOP
    0777
     
    onlyican.com, May 4, 2006 IP
  9. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    yeah that too, still nothing on the output :(
    im thinking maybe if there was a way to have on the index.php something like $_POST[$thevariable] or $GET[$thevariable] or something like that
     
    sunbeam, May 4, 2006 IP
  10. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The reason you're seeing the 'you are a looser' first is because when you include via HTTP, the script gets parsed.

    It's very simple: whatever your browser sees if you go to a PHP script, another PHP script will see if you include via HTTP. It doesn't do anything special.

    So, when script A prints a string and then is included via HTTP from script B, then script B basically gets a bit of text that is not within the PHP tags and so prints it straight out. Just like when you 'include' a file that doesn't have its own PHP tags.

    One way of doing what you want to do is name the file that you want to include with a non-.php extension. That way, the file doesn't get parsed by the server. It just gets sent to the script that is including it. Because of this, however, you have to realise that anyone that sends a browser to that script will get the file, too.

    The better way to do what you want to do is to maybe make a webservice on the server you want to include from and make it return an array of all of the variables you want.
     
    TwistMyArm, May 4, 2006 IP
  11. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #11
    Dunno if this is the problem, but quoting from the documentation:

     
    mihaidamianov, May 4, 2006 IP
  12. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    @ TwistMyArm:
    tried to remane the file thefile.php to thefile.txt but im getting on index.php that output :

    $thevariable = "looser" ;YOU MUST ME A WHEN YOU CANT DO THAT

    it prints the content of thefile.txt complete !
     
    sunbeam, May 4, 2006 IP
  13. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #13
    sunbeam: did you still have the <?php and ?> tags around the line, even though it was a .txt file?

    If so.... then I don't know, sorry :(
     
    TwistMyArm, May 4, 2006 IP
  14. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    NOPE, I REMOVED THE <?PHP ... ?> CAUSE THERE IS NO NEED TO PUT THAT IN A TXT FILE :(

    thanx anyway
     
    sunbeam, May 4, 2006 IP
  15. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Of course there's no need for it in a text file, but what you're effectively trying to do is get your include to grab a complete, valid PHP script. The only way you can do that this way is to have a complete, valid PHP script that doesn't get parsed.

    Hence the extension such as .txt.

    But I'm assuming you've already tried to put them back in, but keep the .txt extension, right?
     
    TwistMyArm, May 4, 2006 IP
  16. sunbeam

    sunbeam Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    @TwistMyArm:

    dude, u r a genius :) left the <?php... .?> thing inside, renamed the *.php file to *.txt, changed the

    include("http://my_second_server/thepath/thefile.php");

    to

    include("http://my_second_server/thepath/thefile.txt");

    and everything worked fine !!!!!

    thanx so much :)
     
    sunbeam, May 4, 2006 IP