Authenticate This!

    Date: 11/23/05 (PHP Community)    Keywords: no keywords

    Okay... here's the problem.

    I have a script that works fine unless I put in some password authentication.  What's happening is that one of my functions is becoming "undefined" once I throw it into an if statement.  In the cut below, you'll see where the authentication ends and the script begins.  I have a feeling it has something to do with globals, but I'm not entirely sure.  Anyone have any ideas?


    include("../config.php");
    include("../lib/template_class.php");


    //Starting the session and using the information.
    session_start();
    $session=session_id();
    $username=$_SESSION['username'];
    $password=$_SESSION['password'];



    //Calling the database for login/password information.
    $result = mysql_query("select * from users where username='$username' AND password='$password' limit 1");
    $get_userinfo = @mysql_fetch_array($result);


    //Applying DB results to variables.
    $username=$get_userinfo[username];
    $password=$get_userinfo[password];
    $uid = $get_userinfo[id];


    //login null checks
    if($username=="" AND $password=="" OR $password==""){
    $page = new Page('../template/login.php');
    $page->replace_tags(array(
    'scriptName' => "$scriptName",
    'msg' => "Invalid login or password. Please try again.",
    'footer' => '$footer'));
    $page->output();

    session_destroy();
    }else{

    ##############################################################################
    # #
    # This is the end of the authorizing checks. #
    # #
    # The user is logged in properly and will now access the page's content. #
    # #
    ##############################################################################

    ini_set("memory_limit", "25M");
    $IMG_ORG_HEIGHT="400";
    $IMG_ORG_WIDTH="400";
    $IMG_HEIGHT="100";
    $IMG_WIDTH="100";
    $IMG_ROOT="./images";
    $use_imagecreatetruecolor=true;
    $use_imagecopyresampled=true;
    $JPG_QUALITY=50;


    if( ! $HTTP_POST_FILES ["image"]["tmp_name"] || $HTTP_POST_FILES ["image"]["tmp_name"] =="none")die("Error Uploading Image");

    if($dontResizeMyImage == "1"){

    if( ! $f_org = noresizer_main("image","",$IMG_ORG_WIDTH,$IMG_ORG_HEIGHT))die("
    No Image Received!
    ");
    if( ! $f_res = resizer_main("image","res_",$IMG_WIDTH,$IMG_HEIGHT))die("
    Could Not Resize!
    ");

    $sz_org=getimagesize( "$IMG_ROOT/$f_org" );
    $sz_res=getimagesize( "$IMG_ROOT/$f_res" );
    $fs_org=filesize( "$IMG_ROOT/$f_org" );
    $fs_res=filesize( "$IMG_ROOT/$f_res" );

    }else{

    if( ! $f_org = resizer_main("image","",$IMG_ORG_WIDTH,$IMG_ORG_HEIGHT))die("
    No Image Received!
    ");
    if( ! $f_res = resizer_main("image","res_",$IMG_WIDTH,$IMG_HEIGHT))die("
    Could Not Resize!
    ");

    $sz_org=getimagesize( "$IMG_ROOT/$f_org" );
    $sz_res=getimagesize( "$IMG_ROOT/$f_res" );
    $fs_org=filesize( "$IMG_ROOT/$f_org" );
    $fs_res=filesize( "$IMG_ROOT/$f_res" );

    }



    echo "

    ";

    //include('../footer.php');

    $dateadded = time();
    $user_id = $myclass->member['id'];

    include ("../config.php");

    mysql_query("INSERT INTO images (id, thumbnail_url, album_id, user_id, dateadded, fullsize_url) VALUES (NULL, '$f_res', '$aid', '$uid', '$dateadded', '$f_org')");

    echo "

";

function noresizer_main($image, $dest_file_prefix,$w, $h){
global $use_imagecreatetruecolor, $use_imagecopyresampled, $IMG_ROOT,
$JPG_QUALITY, $HTTP_POST_FILES, $dontResizeMyImage;
$image_name = $HTTP_POST_FILES [$image]["name"];
$image = $HTTP_POST_FILES [$image]["tmp_name"];

if(trim($image) == "" || trim($image) == "none") return false;

$arr_img = image_from_upload($image);

//wow it is exactly like needed!!!
$img_res = $arr_img["img"];

$file_name = make_filename($image_name, $dest_file_prefix);

ImageJPEG($img_res,"$IMG_ROOT/$dest_file_prefix$file_name", $JPG_QUALITY);


return "$dest_file_prefix$file_name";
}




function resizer_main($image, $dest_file_prefix,$w, $h){
global $use_imagecreatetruecolor, $use_imagecopyresampled, $IMG_ROOT,
$JPG_QUALITY, $HTTP_POST_FILES, $dontResizeMyImage;
$image_name = $HTTP_POST_FILES [$image]["name"];
$image = $HTTP_POST_FILES [$image]["tmp_name"];

if(trim($image) == "" || trim($image) == "none") return false;

$arr_img = image_from_upload($image);

if( $arr_img["w"] > $w || $arr_img["h"] > $h){

$wh = get_sizes($arr_img["w"], $arr_img["h"], $w, $h);
$img_res = img_get_resized($arr_img["img"], $arr_img["w"], $arr_img["h"], $wh["w"], $wh["h"], $use_imagecreatetruecolor, $use_imagecopyresampled);

} else {

//wow it is exactly like needed!!!
$img_res = $arr_img["img"];
}

$file_name = make_filename($image_name, $dest_file_prefix);

ImageJPEG($img_res,"$IMG_ROOT/$dest_file_prefix$file_name", $JPG_QUALITY);


return "$dest_file_prefix$file_name";
}





function image_from_upload($uploaded_file){
$img_sz = getimagesize($uploaded_file);
switch( $img_sz[2] ){
case 1:
$img_type = "GIF";
$img = ImageCreateFromGif($uploaded_file);
die("
Sorry, Only JPG's are supported.
");
break;
case 2:
$img = ImageCreateFromJpeg($uploaded_file);
$img_type = "JPG";
break;
case 3:
$img = ImageCreateFromPng($uploaded_file);
$img_type = "PNG";
break;
case 4:
$img_type = "SWF";
die("
Sorry, Only JPG's are supported.
");

break;
default: die("
Sorry, Only JPG's are supported.
");
}//case
return array("img"=>$img, "w"=>$img_sz[0], "h"=>$img_sz[1], "type"=>$img_sz[2], "html"=>$img_sz[3]);
}






function get_sizes($src_w, $src_h, $dst_w,$dst_h ){
#### Calculate multipliers
$mlt_w = $dst_w / $src_w;
$mlt_h = $dst_h / $src_h;

$mlt = $mlt_w < $mlt_h ? $mlt_w:$mlt_h;
if($dst_w == "*") $mlt = $mlt_h;
if($dst_h == "*") $mlt = $mlt_w;
if($dst_w == "*" && $dst_h == "*") $mlt=1;

#### Calculate new dimensions
$img_new_w = round($src_w * $mlt);
$img_new_h = round($src_h * $mlt);
return array("w" => $img_new_w, "h" => $img_new_h, "mlt_w"=>$mlt_w, "mlt_h"=>$mlt_h, "mlt"=>$mlt);
}





function img_get_resized($img_original,$img_w,$img_h,$img_new_w,$img_new_h,$use_imagecreatetruecolor=false, $use_imagecopyresampled=false){
if($use_imagecreatetruecolor && function_exists("imagecreatetruecolor")){
$img_resized = imagecreatetruecolor($img_new_w,$img_new_h) or die("
Failed to create destination image.
");
} else {
//echo("Using ImageCreate (usual quality)
");
$img_resized = imagecreate($img_new_w,$img_new_h) or die("
Failed to create destination image.
");
}
if($use_imagecopyresampled && function_exists("imagecopyresampled")){
imagecopyresampled($img_resized, $img_original, 0, 0, 0, 0,$img_new_w, $img_new_h, $img_w,$img_h) or die("
Failed to resize @ ImageCopyResampled()
");
}else{
imagecopyresized($img_resized, $img_original, 0, 0, 0, 0,$img_new_w, $img_new_h, $img_w,$img_h) or die("
Failed to resize @ ImageCopyResized()
");
}
return $img_resized;
}




function make_filename($image_name){
$file_name = uniqid('s').'.jpg';
$pos = strrpos($file_name, '.');
$file_name = substr($file_name, 0,$pos).".jpg";
return $file_name;
}






##############################################################################
# #
# Nothing passed this point will be authorized. #
# #
# Take caution as to what is added beyond #
# this point as it will be executed #
# without being authorized! #
# #
##############################################################################
}
?>

Source: http://www.livejournal.com/community/php/370010.html

« reading MS Word files || POP3 Webmail PHP Script... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home