#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,996
    Rep Power
    375

    Php sends data twice?


    I was testing running php script through the image. I have no idea why the following scripts puts two lines of text in my text file?

    PHP Code:
    <?php
        
        $name 
    $_GET['name'];
        
    file_put_contents 'test.txt''1'FILE_APPEND );

        
    header('Content-Type: image/jpeg');
        
        
    // Create a blank image and add some text
        
    $im imagecreatetruecolor(11);
        
        
    // Set the content type header - in this case image/jpeg
        
    header('Content-Type: image/jpeg');
        
        
    // Output the image
        
    imagejpeg($im);
        
        
    // Free up memory
        
    imagedestroy($im);
    ?>
    every time i run this, in the text file i see "11" but i was expecting to see 1.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Are you sure the text file is indeed empty before you run the script? Also check the script with a debugger so that you can track the control flow.

    By the way, why do you set the Content-Type header twice?
    Last edited by Jacques1; January 14th, 2014 at 11:56 AM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,996
    Rep Power
    375
    ok i have just tried. if i remove the header(content...) code then it echoes 1 ONCE. if i leave it in, it echoes twice?

    Could the script be running twice by browser in case of problems displaying the fake image?

    btw i am navigating to the script DIRECTLY.

    edited: just confirmed that it is hitting the script twice for some reason..

    i added "output .= here1" here ">>> etc and outputted those to the browser and they get repeated twice so the script runs twice

    edited 2: Not sure if this is a "proper" solution but I set a session value to 1 and then test this if it exists i dont do file_pu_contents()...
    Last edited by paulh1983; January 15th, 2014 at 03:49 AM.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    You don't happen to use Firefox?

    I could reproduce the issue in Firefox, but neither in Chrome nor IE. For some reason, Firefox immediately makes a second request after the first one (verified with the Apache log). I'd say this is a bug.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,951
    Rep Power
    4033
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,996
    Rep Power
    375
    thanks guys.. you are ace.. i didnt even consider checking another browser. Funnily enough I dont think my firebug had this request coming in twice.. (FF did request it two/three times if image had errors but otherwise I could only see one request being made in Firebug).

    So should I be using SESSION solution or just ignore it?

IMN logo majestic logo threadwatch logo seochat tools logo