0

i am trying to display an image in HTML using:

<img src="/logo.php?seq=5" />

then logo.php looks like:

<?php
$sql="SELECT * from reseller where sequence = '".$_GET["seq"]."' ";
$rs=mysql_query($sql,$conn);
$result=mysql_fetch_array($rs);

echo '<img src="http://www.integradigital.co.uk/customer/'.$result["logo"].'" />';
?>

but its not working - whats the best way to do this so the user seeing the image cannot look at the URL of the image. if they open the image in its own window i want them to see something like http://www.domain.com/logo.php?seq=5 ???

charlie
  • 1,268
  • 6
  • 34
  • 71
  • Why don't you place a div instead and set logo as background image so that it will not be straight forward URL to show. – Ganesh Pandhere Sep 18 '13 at 10:39
  • i thought about that but if the user looks in the CSS it will show the url – charlie Sep 18 '13 at 10:40
  • 1
    Define "cannot look at the URL." Even if it's referenced in CSS, the user can still look at it if they want to. – David Sep 18 '13 at 10:40
  • 3
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Sep 18 '13 at 10:41
  • its easy, just base64 encode your urls ;) – Kyslik Sep 18 '13 at 10:41

1 Answers1

2

Use readfile() to read the image in the image.php:

// Read URL from database
$sql    = "SELECT * from reseller where sequence = '" . $_GET["seq"] . "'";
$rs     = mysql_query($sql,$conn);
$result = mysql_fetch_array($rs);

// Generate path
$path = '/customer/' . $result["logo"];

// Set proper headers
$headers = get_headers( $path );

foreach( $headers as $h )
    if( strpos( $h, 'Content-Type:' ) !== false )
        header( $h );

// Send file to user
readfile( $path );

Then PHP reads the right logo and outputs it, the user won't be able to see the real path. You can link the logo like you proposed:

<img src="/logo.php?seq=5" alt="Logo">
Rudolf
  • 1,807
  • 2
  • 18
  • 31