-1

I just created a page which the user can choose the mode to show, such as icon (image) or just temperature (text). Those are my code:

<?lc
#tell the browser that we will send binary data (png)
put header("Content-type:image/png")

#get ip address
if $_GET["ip"] = "" then
    put $_SERVER["REMOTE_ADDR"] into ipAddress
else 
    put $_GET["ip"] into ipAddress
end if

#get the mode
put $_GET["mode"] into mode

#get longtitude and latitude data
put url ("http://vo.afteroffice.com/r/v/public/pub/geoloc?ip=" & ipAddress) into geoInfo
        split geoInfo by cr and ":"

#input lon and lat data into url
put url ("http://api.yr.no/weatherapi/locationforecast/1.8/?lat=" & geoInfo["latitude"] & ";lon=" & geoInfo["longtitude"]) into weatherDetail

#create tree from XML data
put revCreateXMLTree(weatherDetail, false, true, false) into tLocation

#get data about temperature and clouds
put revXMLAttribute(tLocation,"weatherdata/product/time/location/temperature", "value") into temperature

#create the output
if mode = "temperature" then
        put "The temperature is " & temperature
    else if mode = "icon" then
        put URL("binfile:icon/hot01.png")
    else if mode = "" then
        put "Oke"
end if
?>

My image & text problems are:

  • If I don't put put header("Content-type:image/png") in my code and I call mode=icon, the result will be "‰PNG IHDRPPŽò­tEXtSoftwareAdobe ImageReadyqÉe

  • If I put put header("Content-type:image/png") in my code and I call mode=temperature, the result will be "Te image cannot displayed, cause it contains error"

Could you help me? Thank you.

Lupita Noyra
  • 221
  • 2
  • 3
  • 12

1 Answers1

0

And how about adding something like

if mode = "temperature" then 
# do not put header
else if mode = "icon" then
put header("Content-type:image/png")
end if

at the position where you have your content type header now?

You just have to add the definition of mode at the beginning instead of the middle of your script

Tate83
  • 274
  • 1
  • 7
  • 21