Simple PHP function and variable confusion

X-Ghost

New Member
I have a couple of simple PHP functions I am using. One to detect wether the user is on an iPhone, and one to resize images if they are.\[code\]<?php /* User agent function */function userAgent(){ $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone"); if ($browser == true) { $var = 1; } return $var;}/* Image resize function */function imageResize($width, $height) { $var = userAgent($var); if($var == 1){ $width = round($width / 2); $height = round($height / 2); }else{ $width = round($width); $height = round($height); } echo "width=\"$width\" height=\"$height\""; } ?>\[/code\]The problem is, if I manually change the $var to 0 or 1 in the userAgent() function, the images do not resize, but if I change the $var to == 0 in the imageResize() function, they do. Why is the variable not carrying across from the first, to the second function, or am I doing something else wrong?
 
Back
Top