Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an index php which generates an image, it accepts some parameters, processes it and then outputs an image, but some sites do not allow ? & and = in image urls so I have made another php script:

<?php
    $force_forum = "ce";
    $force_image = "image/.png";
    $_GET['ext'] = $force_image;
    $_GET['forum'] = $force_forum;
    include './../../index.php';
    die();
?>

however this doesn't display any errors or image, just an invalid image, yet, the index.php is this:

<?php
    function open_session(){session_start();$_SESSION['is_open'] = TRUE;}
    function close_session(){session_write_close();$_SESSION['is_open'] = FALSE;}
    function destroy_session(){session_destroy();$_SESSION['is_open'] = FALSE;}
    function session_is_open(){if(!isset($_SESSION['is_open']))return false;return($_SESSION['is_open']);}

    if(isset($_GET['ext']) || isset($force_image))//we want music?
    {
        $gvisits = 0;

        if(isset($force_image))
        {
            $gvisits = file_get_contents("./../../counter.php");
        }
        else
        {
            $gvisits = file_get_contents("counter.php");
        }

        if (!session_is_open())
        {
            open_session();
        }

        $names = array(
            array("eEcR-kCDAug","Two Door Cinema Club - What You Know (Feed Me Cover)"),
            array("r0a-o16i_Gw","Klaypex - Lights"),
            array("pPwhjknId4A","Duelle & CiRRO - Your Addiction (Culture Code Remix)"),
            array("4G10QL3VBrw","Protostar & MakO - No Fire (feat. Rachel Hirons)"),
        );

        $randx = rand(0, count($names)-1);

        if($_GET['ext']=="image/.png" || $_GET['ext']=="image/img.png" || isset($force_image))//display image
        {
            // Set the content-type
            header('Content-Type: image/png');

            // Create the image
            $im = imagecreatetruecolor(850, 30);
            $white = imagecolorallocate($im, 255, 255, 255);
            $blue = imagecolorallocate($im,200,250,155);
            $black = imagecolorallocate($im, 0, 0, 0);
            // Create some colors
            if(isset($_GET['forum']) || isset($force_forum))
            {
                if(isset($_GET['forum']))
                {
                    $force_forum = $_GET['forum'];
                }
                switch($force_forum)
                {
                    case "samp":
                    {
                        $white = imagecolorallocate($im, 246, 246, 246);
                        $blue = imagecolorallocate($im,200,250,155);
                        $black = imagecolorallocate($im, 0, 0, 0);
                        break;
                    }
                    case "ce":
                    {
                        $white = imagecolorallocate($im, 151, 151, 151);
                        $blue = imagecolorallocate($im,200,250,155);
                        $black = imagecolorallocate($im, 0, 0, 0);
                        break;
                    }
                }
            }
            else
            {
                $white = imagecolorallocate($im, 128, 128, 128);
                $blue = imagecolorallocate($im,200,250,155);
                $black = imagecolorallocate($im, 0, 0, 0);
            }

            imagefilledrectangle($im, 0, 0, 849, 29, $white);
            //imagecolortransparent ( $im , $white );

            // Replace path by your own font path
            $font = 'xirod.ttf';
            $fontl = 'arial.ttf';
            if(isset($force_image))
            {
                $font = './../../xirod.ttf';
                $font = './../../arial.ttf';
            }

            // Add some shadow to the text
            imagettftext($im, 9, 0, 8, 11, $blue, $font, $names[$randx][1]);
            imagettftext($im, 9, 0, 8, 21, $blue, $fontl, "http://youtu.be/" . $names[$randx][0]);

            // Add the text
            imagettftext($im, 9, 0, 7, 10, $black, $font, $names[$randx][1]);
            imagettftext($im, 9, 0, 7, 20, $black, $fontl, "http://youtu.be/" . $names[$randx][0]);

            $_SESSION['LINK'] = "http://youtu.be/" . $names[$randx][0];
            // Using imagepng() results in clearer text compared with imagejpeg()
            imagepng($im);
            imagedestroy($im);
        }
    }
?>

the index php works nice when generating the image, but when it's included then not, what is wrong with this code?

The index php is in the root/ and the other php script is in root/img/ce/, that is why the ./../.. have been added.

share|improve this question
try ../../counter.php as you need to move two folders up. Just use one ../ foreach level – Fabio 2 days ago

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.