How to print image out in html, using php echo and $_SESSION variable?How can I prevent SQL injection in PHP?Convert HTML + CSS to PDF with PHP?How do I give text or an image a transparent background using CSS?How do I get PHP errors to display?How to create an HTML button that acts like a link?How do I auto-resize an image to fit a 'div' container?How can I set the default value for an HTML <select> element?How do you parse and process HTML/XML in PHP?How does PHP 'foreach' actually work?Cannot display HTML string

What is the origin of the “clerics can create water” trope?

What exactly is a web font, and what does converting to one involve?

Why are two-stroke engines nearly unheard of in aviation?

What was the deeper meaning of Hermione wanting the cloak?

Tips for remembering the order of parameters for ln?

Abilities interrupting effects on a cast card

Why are there two bearded faces wearing red hats on my stealth bomber icon?

Can a Druid Wild Shaped as a horse use Horseshoes of Speed?

Carroll's interpretation of 1-forms

Can one guy with a duplicator trigger a nuclear apocalypse?

If people's daily habits are reliable then why is the stock market so unpredictable?

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Applications of mathematics in clinical setting

Output Distinct Factor Cuboids

Amiga 500 OCS/ECS vs Mega Drive VDP

Whence comes increasing usage of "do" for "have" in ordering food?

Should the pagination be reset when changing the order?

How can I check that parent has more than 1 child?

Who are the people reviewing far more papers than they're submitting for review?

What's the word for a student who doesn't register but goes to a class anyway?

With a 500GB SSD and a 250GB SSD is it possible to mirror a 250GB partition on the 500GB with the 250GB SSD using ZFS?

Floating Point XOR

Persuading players to be less attached to a pre-session 0 character concept

What do you call the battery slot's ends?



How to print image out in html, using php echo and $_SESSION variable?


How can I prevent SQL injection in PHP?Convert HTML + CSS to PDF with PHP?How do I give text or an image a transparent background using CSS?How do I get PHP errors to display?How to create an HTML button that acts like a link?How do I auto-resize an image to fit a 'div' container?How can I set the default value for an HTML <select> element?How do you parse and process HTML/XML in PHP?How does PHP 'foreach' actually work?Cannot display HTML string






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>









share|improve this question





















  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54

















0















I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>









share|improve this question





















  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54













0












0








0


0






I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>









share|improve this question
















I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>






php html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 14:06









executable

2,0682 gold badges11 silver badges27 bronze badges




2,0682 gold badges11 silver badges27 bronze badges










asked Mar 28 at 13:43









Mikkel HebelMikkel Hebel

45 bronze badges




45 bronze badges










  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54












  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54







1




1





You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

– 04FS
Mar 28 at 13:45






You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

– 04FS
Mar 28 at 13:45





3




3





You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

– Pete
Mar 28 at 13:47






You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

– Pete
Mar 28 at 13:47














@executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

– Mikkel Hebel
Mar 28 at 13:54





@executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

– Mikkel Hebel
Mar 28 at 13:54












4 Answers
4






active

oldest

votes


















1
















Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else


?>





share|improve this answer

























  • @executeable Worked, thank you! :D

    – Mikkel Hebel
    Mar 28 at 14:03


















1
















change



 echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


to



 echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





share|improve this answer
































    0
















    You can use something like this:



    <?php
    if (isset($_SESSION['userId']))
    $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
    echo $img . ' <a href="settings.php">Settings</a>
    <form action="lib/logout.php" method="POST">
    <button type="submit" name="logout-submit">Logout</button>
    </form>';
    else
    // @todo

    ?>


    rsrs






    share|improve this answer
































      0
















      You have started a PHP code, within a PHP code...
      This is the correct img src:



      src="img/' . print_r($_SESSION['userIcon']) . '"


      I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






      share|improve this answer



























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399140%2fhow-to-print-image-out-in-html-using-php-echo-and-session-variable%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1
















        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>





        share|improve this answer

























        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03















        1
















        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>





        share|improve this answer

























        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03













        1














        1










        1









        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>





        share|improve this answer













        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 13:58









        executableexecutable

        2,0682 gold badges11 silver badges27 bronze badges




        2,0682 gold badges11 silver badges27 bronze badges















        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03

















        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03
















        @executeable Worked, thank you! :D

        – Mikkel Hebel
        Mar 28 at 14:03





        @executeable Worked, thank you! :D

        – Mikkel Hebel
        Mar 28 at 14:03













        1
















        change



         echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


        to



         echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





        share|improve this answer





























          1
















          change



           echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


          to



           echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





          share|improve this answer



























            1














            1










            1









            change



             echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


            to



             echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





            share|improve this answer













            change



             echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


            to



             echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 14:04









            Danyal SandeeloDanyal Sandeelo

            9,0363 gold badges26 silver badges46 bronze badges




            9,0363 gold badges26 silver badges46 bronze badges
























                0
















                You can use something like this:



                <?php
                if (isset($_SESSION['userId']))
                $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                echo $img . ' <a href="settings.php">Settings</a>
                <form action="lib/logout.php" method="POST">
                <button type="submit" name="logout-submit">Logout</button>
                </form>';
                else
                // @todo

                ?>


                rsrs






                share|improve this answer





























                  0
















                  You can use something like this:



                  <?php
                  if (isset($_SESSION['userId']))
                  $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                  echo $img . ' <a href="settings.php">Settings</a>
                  <form action="lib/logout.php" method="POST">
                  <button type="submit" name="logout-submit">Logout</button>
                  </form>';
                  else
                  // @todo

                  ?>


                  rsrs






                  share|improve this answer



























                    0














                    0










                    0









                    You can use something like this:



                    <?php
                    if (isset($_SESSION['userId']))
                    $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                    echo $img . ' <a href="settings.php">Settings</a>
                    <form action="lib/logout.php" method="POST">
                    <button type="submit" name="logout-submit">Logout</button>
                    </form>';
                    else
                    // @todo

                    ?>


                    rsrs






                    share|improve this answer













                    You can use something like this:



                    <?php
                    if (isset($_SESSION['userId']))
                    $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                    echo $img . ' <a href="settings.php">Settings</a>
                    <form action="lib/logout.php" method="POST">
                    <button type="submit" name="logout-submit">Logout</button>
                    </form>';
                    else
                    // @todo

                    ?>


                    rsrs







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 28 at 14:01









                    Lucas CampeloLucas Campelo

                    12 bronze badges




                    12 bronze badges
























                        0
















                        You have started a PHP code, within a PHP code...
                        This is the correct img src:



                        src="img/' . print_r($_SESSION['userIcon']) . '"


                        I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






                        share|improve this answer





























                          0
















                          You have started a PHP code, within a PHP code...
                          This is the correct img src:



                          src="img/' . print_r($_SESSION['userIcon']) . '"


                          I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






                          share|improve this answer



























                            0














                            0










                            0









                            You have started a PHP code, within a PHP code...
                            This is the correct img src:



                            src="img/' . print_r($_SESSION['userIcon']) . '"


                            I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






                            share|improve this answer













                            You have started a PHP code, within a PHP code...
                            This is the correct img src:



                            src="img/' . print_r($_SESSION['userIcon']) . '"


                            I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 28 at 14:01









                            Hans SchiesslHans Schiessl

                            92 bronze badges




                            92 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399140%2fhow-to-print-image-out-in-html-using-php-echo-and-session-variable%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript