Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3213334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:55:58+00:00 2026-05-17T14:55:58+00:00

1st the background – so that you see, that I’m not trying anything malicious:

  • 0

1st the background – so that you see, that I’m not trying anything malicious: I have a flash app in the russian social network vkontakte.ru which displays user avatars. Until now my .swf file has been hosted at their domain, so that fetching and scaling avatars worked well.

Now I’d like to switch my app to an iframe-type, so that the .swf will be hosted at my domain and thus I’m not able to scale the avatars in my .swf anymore: neither my domain, nor “*” are listed in http://vkontakte.ru/crossdomain.xml and thus the .swf can download and display the avatars, but can’t scale them anymore (accessing myLoader.content throws SecurityError).

I’ve decided to write a proxy script in PHP which would fetch the image specified in scripts ?img= parameter and then just pass it to the stdout (after some checks and without storing anything):

<?php

define('MAX_SIZE', 1024 * 1024);

$img = $_GET['img'];
if (strpos($img, '..') !== false ||
    !preg_match(',^http://[\w.]*vkontakte\.ru/[\w./?]+$,i', $img))
        exit();

$opts = array(
        'http'=>array(
                'method' => 'GET',
                'header' => "Accept-language: en\r\n" .
                            "Cookie: foo=bar\r\n"
        )
);

$ctx = stream_context_create($opts);
stream_context_set_params($ctx, array('notification' => 'callback'));
$fp = fopen($img, 'r', false, $ctx);
fpassthru($fp);
fclose($fp);

function callback($code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
        if ($code == STREAM_NOTIFY_FILE_SIZE_IS && $bytes_max > MAX_SIZE)
                exit();

        if ($code == STREAM_NOTIFY_PROGRESS && $bytes_transferred > MAX_SIZE)
                exit();

        if ($code == STREAM_NOTIFY_MIME_TYPE_IS) {
                $mime = strtolower($message);
                switch($message) {
                        case 'image/gif':
                        case 'image/png':
                        case 'image/jpg':
                        case 'image/jpeg':
                                // XXX this doesn't work XXX
                                header('Content-Type: ' . $mime);
                                break;
                        default:
                                exit();
                }
        }
}

?>

My problem is that the $mime header is never printed (or is printed too late?).

When I fetch for example my avatar directly:
http://cs971.vkontakte.ru/u59751265/a_7567890a.jpg
then I see the Content-Type: image/jpeg header being sent to the browser.

But when I fetch it through my proxy script, I don’t see that header.

Maybe I should better use a different function instead of fopen()? I’m not very proficient in PHP. Also I’m worried if fopen() can be tricked into serving local files from my web server.

And as a bonus question: I’m worried that my .swf will be not the only app calling my proxy.php, but I can’t figure out a good way to secure it (maybe there is no such way) – I can’t store a secret in my .swf and in the .php – because the .swf can be disassembled.

Thank you, Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:55:59+00:00Added an answer on May 17, 2026 at 2:55 pm

    I believe your first assumption is right, you send the header too late or you are not getting the mime headers you expect.

    First of all try logging the mimes using file_put_contents, then if you find out that it is indeed too late to be of any use, you can look at output buffering.

    If however you dont get to the header at all, you might be in the wrong context, HTTP perhaps?

    For your bonus question; the page of the iframe is hosted on a server, on that server you are probably running PHP, create a session with session_start(), set $_SESSION['gotvisit'] = TRUE (or something like that). Then retrieve the session id using $id = session_id(), this id you can now pass to your flash with standard flash variables. Have flash pass that variable in the request for the image, next up in your img script, do;

    session_id($_GET['ses']);
    session_start();
    if(!isset($_SESSION['gotvisit']))
        die('no access');
    

    Good luck to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1st post on stackoverflow, hope to have great feedback :) I'm currently trying to
Background There are a lot of App Store released iPhone apps that require an
I need to have a JToggleButton (that has custom background) that contains a JPanel
Check out http://waterski.allthingswebdesign.com/index.php/site/index and you can see that my Nivo Slider is not centered
I have a login page that has 2 tags that have a background image
I have a Silverlight control that tries to have the same background as the
I tried that as 1st took image view as background of table view and
I have the following function that returns only the 1st row of data and
1st phase I have a problem shutting down my running JBoss instance under Eclipse
1st disclaimers: I'm not a programmer, never was had never been taught higher math

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.