Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Using Echo Properly

  • This topic is empty.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #30764
    lon
    Member

    First I apologize if this question is too basic for this forum, if it is just tell me to go away and I will without any hard feelings.

    Can someone point me to something that explains how to properly use echo within a web page?

    I am trying to password protect a directory on a website for someone who knows even less about the web and HTML then I do and I came upon the page:
    https://css-tricks.com/easily-password-protect-a-website-or-subdirectory/
    It says I can get the path information needed by “echo(ing) out a phpinfo(); on a page in that directory” but I have not been able to get the echo statement to work. I know I am missing some fundamental knowledge here and would love to learn it.

    Thank you for your help and patience.
    Lon.

    #73062
    Chris Coyier
    Keymaster

    Yeah that’s probably an incorrect usage of “echo”. Just do:

    
    phpinfo();
    ?>
    #72847
    lon
    Member

    Thank you for your help. Unfortunately I am still having problems setting and echoing out a variable.
    Here is the code I am using that is not working:

    
    $path=phpinfo();
    ?>


    <br /> Be Very Affraid<br />


    echo " the path is ".$path." ";

    That produces: “echo ” the path is “.$path.” “; ” on the web page.

    Is there anything I can read on the proper use of echo itself?
    Thank you again.

    #72848
    lon
    Member

    I messed up. How Do I use those black boxes that you use to show your HTML?
    Sorry.

    #72849
    Roxon
    Member

    You use:


    or click the code icon.

    #72853
    AlexA.
    Participant
    
    $path = phpinfo();
    ?>


    or

    
    $path = phpinfo();
    echo " the path is " . $path;
    ?>

    or

    
    echo " the path is " . phpinfo();
    ?>
    #72837
    lon
    Member

    This is driving me crazy. The code makes perfect sense to me, but nothing displays on the web page.




    <br /> Be Very Affraid<br />


    $path = phpinfo();
    echo " the path is " . $path;
    ?>


    I have tried this above the HTML tag, within the head tags and within the body tags; but nothing displays.
    What fundamental piece of information am I missing? Dam I feel stupid.
    Thank you Chris, Roxon and Alex all! Your code could not be more clear, it makes perfect sense. I’m just missing something that everyone else seems to know.
    (explicatives deleted)

    #72829
    TheDoc
    Member

    I don’t shoot me for asking the question, but I thought I’d ask the obvious – are you sure you are working on a page that can handle PHP?

    For example, if you’re editing an HTML page (page-name.html), without some fancy .htaccess trickery your PHP won’t actually work.

    #72775
    Rob MacKay
    Participant

    Ok.

    phpinfo(); is a function that gives you all the information about the PHP installation on your server. It tells you everything you can and can’t do by default – and lets you know if you need to turn anything on or off depending on what features you have.

    If you create a file called phpinfo.php then add

    
    
    phpinfo();

    ?>

    Then if you navigate to it you will be shown a page with a table of info on it :) phpinfo() won’t return a path when you use it as you are trying to, but it will show you a path within the mountain of other info it gives you.

    So when you echo out a phpinfo – that’s what that means. It will give you the info you need automatically.

    #72642
    lon
    Member

    Dear TheDoc, I do not find any fault for you asking if the environment can handle PHP. It definitely was the question to ask. Thank you for trying to help me. You are greatly appreciated.

    Dear robSkiwarrior, Thank you Thank you thank you! You explained exactly the underlying idea I was missing. I did as you suggested and got the table you said I would. I was able to find the path info and have gotten the password protection to work. Did I say thank you? Thank you! You are definitely the skiwarrior of my heart.
    I am in your debt,
    Lon.

    #72612
    Rob MacKay
    Participant

    haha no probs :)

    #158188
    stenseven
    Participant

    I think it is useful to point out that each code example shown above contains an error, specifically the first space between the outward carat < and the question mark ?

    < (word space here) ?php does not work.

    #158195
    __
    Participant

    Since everyone was doing it, I think it may have been a problem with how the forums parsed posts with code in them (I remember that we had seemingly endless troubles with that, for a time. It seems to work just fine now, though).

    <?php
    
Viewing 13 posts - 1 through 13 (of 13 total)
  • The forum ‘Other’ is closed to new topics and replies.