Jump to content

Chrisj

Members
  • Posts

    551
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Chrisj

  1. Ok, thanks again for your help.
    This has succeeded:

    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2, overlay=180:180:enable=between(t\,5\,5+2),scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';

    Yet, on the uploaded test videos, the first watermark in the upper left corner looks small and unsharp, but the 2nd watermark, that displays in the middle after 5 seconds, looks to be the correct size, and sharp.

    Any ideas on how to improve that will be welcomed.

  2. Thanks for your reply.

    Yes, I copied them because I'm trying to add the two same logos with the same code line, as an example showed in the documentation.

    So, my latest (unsuccessful) attempt is:

    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.'-i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.'-filter_complex "overlay=10:10,scale=640:-2, overlay=10:10 'if(gte(t,15), -w+(t-2)*20, NAN)',scale=640:-2,"-vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';

    any additional guidance is welcomed

  3. If I could find where to edit my previous message here, I would have changed it to say that, upon some more research I see that 10:10 puts the watermark 10 pixels from the top and 10 pixels from the right, correct? So, I added the code above and ran an upload, which appeared to upload, but nothing there when I try to play it.

    Any additional help is welcomed.

  4. Thanks again for your assistance.

    So, in my current original posted line of code, I don't see any coordinates. However, when it processes it places the logo in the top left corner, which is good.

    So, based on the linked documentation, I believe I've added a second instance of a logo showing up after 20 seconds. If I'm incorrect please let me know. 

    And any help I can get with adding coordinates to the center for the 2nd logo is appreciated.

    Here my current modification:

     $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' 
    -i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.'(t,20)
    -filter_complex "overlay=10:10,scale=640:-2, overlay=10:10,scale=640:-2,"
    -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';

     

  5. Much thanks for your reply. I did not write the posted code, but based on what you provided, would you say I would need to integrate this link example:

    overlay=x='if(gte(t,2), -w+(t-2)*20, NAN)':y=0

    into this line of code in my posting?:

    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';

    if I'm correct with that, then I'd somehow replace/integrate this:

    "overlay=10:10,scale=640:-2"

    with this?:

    overlay=x='if(gte(t,2), -w+(t-2)*20, NAN)':y=0

     

    because I'm not clear on what this means:

    "overlay=10:10,scale=640:-2",

    I don't know if it should stay in or be modified. Any additional guidance is appreciated

     

  6. The web video script that I'm using, and trying to modify, works successfully integrating a watermark in the upper left corner of the video file, (so that when it's downloaded, the watermark stays on the video). In the ffmpeg php file code below, the watermarking starts with this line

    $watermark_image_full_path = "watermark.png";

    at line 275 (out of 504 - about halfway).

    I am wondering if there might be a way to make the watermark also display briefly in another location on the video again, maybe halfway through, when playing it. 

     

    <?php
    if (IS_LOGGED == false || $pt->config->upload_system != 'on') {
        $data = array(
            'status' => 400,
            'error' => 'Not logged in'
        );
        echo json_encode($data);
        exit();
    } else if ($pt->config->ffmpeg_system != 'on') {
        $data = array(
            'status' => 402
        );
        echo json_encode($data);
        exit();
    } else {
        $getID3    = new getID3;
        $featured  = ($user->is_pro == 1) ? 1 : 0;
        $filesize  = 0;
        $error     = false;
    
    
    if (PT_IsAdmin() && !empty($_POST['is_movie']) && $_POST['is_movie'] == 1) {
        if (empty($_POST['movie_title']) || empty($_POST['movie_description']) || empty($_FILES["movie_thumbnail"]) || empty($_POST['stars']) || empty($_POST['producer']) || empty($_POST['country']) || empty($_POST['quality']) || empty($_POST['rating']) || !is_numeric($_POST['rating']) || $_POST['rating'] < 1 || $_POST['rating'] > 10 || empty($_POST['release']) || empty($_POST['category']) || !in_array($_POST['category'], array_keys($pt->movies_categories))) {
            $error = $lang->please_check_details;
        }
        // $cover = getimagesize($_FILES["movie_thumbnail"]["tmp_name"]);
        // if ($cover[0] > 400 || $cover[1] > 570) {
        //     $error = $lang->cover_size;
        // }
    }
    else{
        $request   = array();
        $request[] = (empty($_POST['title']) || empty($_POST['description']));
        $request[] = (empty($_POST['tags']) || empty($_POST['video-thumnail']));
        if (in_array(true, $request)) {
            $error = $lang->please_check_details;
        } else if (empty($_POST['video-location'])) {
            $error = $lang->video_not_found_please_try_again;
        } else if (($pt->config->sell_videos_system == 'on' && $pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || ($pt->config->sell_videos_system == 'on' && $pt->config->who_sell == 'users') || ($pt->config->sell_videos_system == 'on' && $pt->user->admin)) {
            if (!empty($_POST['set_p_v']) || $_POST['set_p_v'] < 0) {
                if (!is_numeric($_POST['set_p_v']) || $_POST['set_p_v'] < 0 || (($pt->config->com_type == 0 && $_POST['set_p_v'] <= $pt->config->admin_com_sell_videos)) ) {
                    $error = $lang->video_price_error." ".($pt->config->com_type == 0 ? $pt->config->admin_com_sell_videos : 0);
                }
            }
        } else {
            $request   = array();
            $request[] = (!in_array($_POST['video-location'], $_SESSION['uploads']['videos']));
            $request[] = (!in_array($_POST['video-thumnail'], $_SESSION['ffempg_uploads']));
            $request[] = (!file_exists($_POST['video-location']));
            if (in_array(true, $request)) {
                $error = $lang->error_msg;
            }
        }
    }
        if (empty($error)) {
            $file = $duration_file     = $getID3->analyze($_POST['video-location']);
            $duration = '00:00';
            if (!empty($file['playtime_string'])) {
                $duration = PT_Secure($file['playtime_string']);
            }
            if (!empty($file['filesize'])) {
                $filesize = $file['filesize'];
            }
            $video_res = (!empty($file['video']['resolution_x'])) ? $file['video']['resolution_x'] : 0;
            $video_id        = PT_GenerateKey(15, 15);
            $check_for_video = $db->where('video_id', $video_id)->getValue(T_VIDEOS, 'count(*)');
            if ($check_for_video > 0) {
                $video_id = PT_GenerateKey(15, 15);
            }
            if (PT_IsAdmin() && !empty($_POST['is_movie']) && $_POST['is_movie'] == 1) {
                $thumbnail = 'upload/photos/thumbnail.jpg';
                if (!empty($_FILES['movie_thumbnail']['tmp_name'])) {
                    $file_info   = array(
                        'file' => $_FILES['movie_thumbnail']['tmp_name'],
                        'size' => $_FILES['movie_thumbnail']['size'],
                        'name' => $_FILES['movie_thumbnail']['name'],
                        'type' => $_FILES['movie_thumbnail']['type']
                    );
                    $file_upload = PT_ShareFile($file_info);
                    $thumbnail = PT_Secure($file_upload['filename'], 0);
                    // if (!empty($file_upload['filename'])) {
                    //     $thumbnail = PT_Secure($file_upload['filename'], 0);
                    //     $upload = PT_UploadToS3($thumbnail);
                    // }
                }
            }
            else{
                $thumbnail = PT_Secure($_POST['video-thumnail'], 0);
                if (file_exists($thumbnail)) {
                    $upload = PT_UploadToS3($thumbnail);
                }
            }
    
            $category_id = 0;
            $convert     = true;
            $thumbnail   = substr($thumbnail, strpos($thumbnail, "upload"), 120);
            // ******************************
            if (PT_IsAdmin() && !empty($_POST['is_movie']) && $_POST['is_movie'] == 1) {
    
                $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
                $i          = 0;
                preg_match_all($link_regex, PT_Secure($_POST['movie_description']), $matches);
                foreach ($matches[0] as $match) {
                    $match_url            = strip_tags($match);
                    $syntax               = '[a]' . urlencode($match_url) . '[/a]';
                    $_POST['movie_description'] = str_replace($match, $syntax, $_POST['movie_description']);
                }
                $data_insert = array(
                    'title' =>  PT_Secure($_POST['movie_title']),
                    'category_id' => PT_Secure($_POST['category']),
                    'stars' => PT_Secure($_POST['stars']),
                    'producer' => PT_Secure($_POST['producer']),
                    'country' => PT_Secure($_POST['country']),
                    'movie_release' => PT_Secure($_POST['release']),
                    'quality' => PT_Secure($_POST['quality']),
                    'duration' => $duration,
                    'description' => PT_Secure($_POST['movie_description']),
                    'rating' => PT_Secure($_POST['rating']),
                    'is_movie' => 1,
                    'video_id' => $video_id,
                    'converted' => '2',
                    'size' => $filesize,
                    'thumbnail' => $thumbnail,
                    'user_id' => $user->id,
                    'time' => time(),
                    'registered' => date('Y') . '/' . intval(date('m'))
                );
                if (!empty($_POST['buy_price']) && is_numeric($_POST['buy_price']) && $_POST['buy_price'] > 0) {
                    $data_insert['sell_video'] = PT_Secure($_POST['buy_price']);
                }
            }
            else{
                $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
                $i          = 0;
                preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
                foreach ($matches[0] as $match) {
                    $match_url            = strip_tags($match);
                    $syntax               = '[a]' . urlencode($match_url) . '[/a]';
                    $_POST['description'] = str_replace($match, $syntax, $_POST['description']);
                }
    
                if (!empty($_POST['category_id'])) {
                    if (in_array($_POST['category_id'], array_keys(get_object_vars($pt->categories)))) {
                        $category_id = PT_Secure($_POST['category_id']);
                    }
                }
                $video_privacy = 0;
                if (!empty($_POST['privacy'])) {
                    if (in_array($_POST['privacy'], array(0, 1, 2))) {
                        $video_privacy = PT_Secure($_POST['privacy']);
                    }
                }
                $age_restriction = 1;
                if (!empty($_POST['age_restriction'])) {
                    if (in_array($_POST['age_restriction'], array(1, 2))) {
                        $age_restriction = PT_Secure($_POST['age_restriction']);
                    }
                }
                $sub_category = 0;
    
                if (!empty($_POST['sub_category_id'])) {
                    $is_found = $db->where('type',PT_Secure($_POST['category_id']))->where('lang_key',PT_Secure($_POST['sub_category_id']))->getValue(T_LANGS,'COUNT(*)');
                    if ($is_found > 0) {
                        $sub_category = PT_Secure($_POST['sub_category_id']);
                    }
                }
    
                $continents_list = array();
                if (!empty($_POST['continents-list'])) {
    
                    foreach ($_POST['continents-list'] as $key => $value) {
                        if (in_array($value, $pt->continents)) {
                            $continents_list[] = $value;
                        }
                    }
                }
                $data_insert = array(
                    'video_id' => $video_id,
                    'user_id' => $user->id,
                    'title' => PT_Secure($_POST['title']),
                    'description' => PT_Secure($_POST['description']),
                    'tags' => PT_Secure($_POST['tags']),
                    'duration' => $duration,
                    'video_location' => '',
                    'category_id' => $category_id,
                    'thumbnail' => $thumbnail,
                    'time' => time(),
                    'registered' => date('Y') . '/' . intval(date('m')),
                    'featured' => $featured,
                    'converted' => '2',
                    'size' => $filesize,
                    'privacy' => $video_privacy,
                    'age_restriction' => $age_restriction,
                    'sub_category' => $sub_category,
                    'geo_blocking' => (!empty($continents_list) ? json_encode($continents_list) : '')
                );
                if (!empty($_POST['set_p_v']) && is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > 0) {
                    $data_insert['sell_video'] = PT_Secure($_POST['set_p_v']);
                }
                if ( ($pt->config->approve_videos == 'on' && !PT_IsAdmin()) || ($pt->config->auto_approve_ == 'no' && $pt->config->sell_videos_system == 'on' && !PT_IsAdmin() && !empty($data_insert['sell_video'])) ) {
                    $data_insert['approved'] = 0;
                }
            }
            // ******************************
            $insert      = $db->insert(T_VIDEOS, $data_insert);
    
            if ($insert) {
                $delete_files = array();
                if (!empty($_SESSION['ffempg_uploads'])) {
                    if (is_array($_SESSION['ffempg_uploads'])) {
                        foreach ($_SESSION['ffempg_uploads'] as $key => $file) {
                            if ($thumbnail != $file) {
                                $delete_files[] = $file;
                                unset($_SESSION['ffempg_uploads'][$key]);
                            }
                        }
                    }
                }
                if (!empty($delete_files)) {
                    foreach ($delete_files as $key => $file2) {
                        unlink($file2);
                    }
                }
                if (isset($_SESSION['ffempg_uploads'])) {
                    unset($_SESSION['ffempg_uploads']);
                }
                $data = array(
                    'status' => 200,
                    'video_id' => $video_id,
                    'link' => PT_Link("watch/$video_id")
                );
                ob_end_clean();
                header("Content-Encoding: none");
                header("Connection: close");
                ignore_user_abort();
                ob_start();
                header('Content-Type: application/json');
                echo json_encode($data);
                $size = ob_get_length();
                header("Content-Length: $size");
                ob_end_flush();
                flush();
                session_write_close();
                if (is_callable('fastcgi_finish_request')) {
                    fastcgi_finish_request();
                }
    
                if ($pt->config->queue_count > 0) {
                    $process_queue = $db->getValue(T_QUEUE,'video_id',$pt->config->queue_count);
                }
    
                if ( (count($process_queue) < $pt->config->queue_count  && !in_array($video_id, $process_queue)) ||  $pt->config->queue_count == 0) {
                    if ($pt->config->queue_count > 0) {
                        $db->insert(T_QUEUE, array('video_id' => $insert,
                                       'video_res' => $video_res,
                                       'processing' => 2));
                    }
    
                    $ffmpeg_b                   = $pt->config->ffmpeg_binary_file;
                    $filepath                   = explode('.', $_POST['video-location'])[0];
                    $time                       = time();
                    $full_dir                   = str_replace('ajax', '/', __DIR__);
    
                    $video_output_full_path_240 = $full_dir . $filepath . "_240p_converted.mp4";
                    $video_output_full_path_360 = $full_dir . $filepath . "_360p_converted.mp4";
                    $video_output_full_path_480 = $full_dir . $filepath . "_480p_converted.mp4";
                    $video_output_full_path_720 = $full_dir . $filepath . "_720p_converted.mp4";
                    $video_output_full_path_1080 = $full_dir . $filepath . "_1080p_converted.mp4";
                    $video_output_full_path_2048 = $full_dir . $filepath . "_2048p_converted.mp4";
                    $video_output_full_path_4096 = $full_dir . $filepath . "_4096p_converted.mp4";
    
                    $video_file_full_path       = $full_dir . $_POST['video-location'];
    
    
                    $watermark_image_full_path = "watermark.png";
    
    
                    // demo Video
                    $video_time = '';
                    $demo_video = '';
                    if ($pt->config->demo_video == 'on' && !empty($data_insert['sell_video'])) {
                        $have_demo = false;
                        if (!empty($duration_file['playtime_seconds']) && $duration_file['playtime_seconds'] > 0) {
                            $video_time = round((10 * round($duration_file['playtime_seconds'],0)) / 100,0);
                            $video_time = '-t '.$video_time.'  -async 1';
                            $have_demo = true;
                        }
                    }
    
    
    
    
                    // demo Video
    
                    //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 $video_output_full_path_240 2>&1");
    
                    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';
    				$shell     = shell_exec($ffmpegCommand);
    
    
    
    
                    $upload_s3 = PT_UploadToS3($filepath . "_240p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'converted' => 1,
                        '240p' => 1,
                        'video_location' => $filepath . "_240p_converted.mp4"
                    ));
                    if ($pt->config->queue_count > 0) {
                        $db->where('video_id',$insert)->delete(T_QUEUE);
                    }
    
                    if ($video_res >= 3840) {
    
                        //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=3840:-2 -crf 26 $video_output_full_path_4096 2>&1");
    
                    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_4096.' 2>&1';
    				$shell     = shell_exec($ffmpegCommand);
    
    
    
                        $upload_s3 = PT_UploadToS3($filepath . "_4096p_converted.mp4");
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            '4096p' => 1
                        ));
                        // demo Video
    
                        if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                            $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()). "_video_4096p_demo.mp4";
                            $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=3840:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                            $upload_s3 = PT_UploadToS3($demo_video);
                            $db->where('id', $insert);
                            $db->update(T_VIDEOS, array(
                                'demo' => $demo_video
                            ));
                        }
                        // demo Video
                    }
                    if ($video_res >= 2048) {
                        //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=2048:-2 -crf 26 $video_output_full_path_2048 2>&1");
    
                        $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_2048.' 2>&1';
    					$shell     = shell_exec($ffmpegCommand);
    
    
                        $upload_s3 = PT_UploadToS3($filepath . "_2048p_converted.mp4");
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            '2048p' => 1
                        ));
                        // demo Video
                        if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                            $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_2048p_demo.mp4";
                            $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=2048:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                            $upload_s3 = PT_UploadToS3($demo_video);
                            $db->where('id', $insert);
                            $db->update(T_VIDEOS, array(
                                'demo' => $demo_video
                            ));
                        }
                        // demo Video
                    }
                    if ($video_res >= 1920 || $video_res == 0) {
                        //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1920:-2 -crf 26 $video_output_full_path_1080 2>&1");
    
                    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_1080.' 2>&1';
    				$shell     = shell_exec($ffmpegCommand);
    
    
                        $upload_s3 = PT_UploadToS3($filepath . "_1080p_converted.mp4");
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            '1080p' => 1
                        ));
                        // demo Video
                        if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                            $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_1080p_demo.mp4";
                            $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1920:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                            $upload_s3 = PT_UploadToS3($demo_video);
                            $db->where('id', $insert);
                            $db->update(T_VIDEOS, array(
                                'demo' => $demo_video
                            ));
                        }
                        // demo Video
                    }
                    if ($video_res >= 1280 || $video_res == 0) {
    
                       //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1280:-2 -crf 26 $video_output_full_path_720 2>&1");
    
                    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_720.' 2>&1';
    				$shell     = shell_exec($ffmpegCommand);
    
                        $upload_s3 = PT_UploadToS3($filepath . "_720p_converted.mp4");
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            '720p' => 1
                        ));
                        // demo Video
                        if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                            $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_720p_demo.mp4";
                            $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1280:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                            $upload_s3 = PT_UploadToS3($demo_video);
                            $db->where('id', $insert);
                            $db->update(T_VIDEOS, array(
                                'demo' => $demo_video
                            ));
                        }
                        // demo Video
                    }
                    if ($video_res >= 854 || $video_res == 0) {
                        //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 $video_output_full_path_480 2>&1");
    
                        $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_480.' 2>&1';
    					$shell     = shell_exec($ffmpegCommand);
    
    
    
                        $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            '480p' => 1
                        ));
                        // demo Video
                        if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                            $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_480p_demo.mp4";
                            $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                            $upload_s3 = PT_UploadToS3($demo_video);
                            $db->where('id', $insert);
                            $db->update(T_VIDEOS, array(
                                'demo' => $demo_video
                            ));
                        }
                        // demo Video
                    }
                    if ($video_res >= 640 || $video_res == 0) {
                       // $shell                      = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
    
                    $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_360.' 2>&1';
    				$shell     = shell_exec($ffmpegCommand);
    
    
    
                       $upload_s3                  = PT_UploadToS3($filepath . "_360p_converted.mp4");
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            '360p' => 1,
                        ));
                        // demo Video
                        if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                            $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_360p_demo.mp4";
                            $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                            $upload_s3 = PT_UploadToS3($demo_video);
                            $db->where('id', $insert);
                            $db->update(T_VIDEOS, array(
                                'demo' => $demo_video
                            ));
                        }
                        // demo Video
                    }
    
                    // demo Video
                    if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                        $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_240p_demo.mp4";
                        $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                        $upload_s3 = PT_UploadToS3($demo_video);
                        $db->where('id', $insert);
                        $db->update(T_VIDEOS, array(
                            'demo' => $demo_video
                        ));
                    }
                    // demo Video
    
    
                    if (file_exists($_POST['video-location'])) {
                        unlink($_POST['video-location']);
                    }
    
    
                    pt_push_channel_notifiations($video_id);
                    $_SESSION['uploads'] = array();
                }
                else{
                    $db->insert(T_QUEUE, array('video_id' => $insert,
                                       'video_res' => $video_res,
                                       'processing' => 0));
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'video_location' => $_POST['video-location']
                    ));
                }
                exit();
            }
        } else {
            $data = array(
                'status' => 400,
                'message' => $error_icon . $error
            );
        }
    }
    

    Any guidance with this is appreciated

  7. Thanks again for your reply.

    Yes, I've been reading. I've been given a lot of advice and tried many things without success (including what was provided here and elsewhere).
    But, some of the explanation I don't understand, like this sentence "use the new wallet and balance amounts in that existing single query, per the comment i added at that point, rather than to start adding more queries before the start of where the transaction/rollback logic starts". 

    Earlier in this thread I was told "Try reading your own code. Go through it line by line and check the value of each variable after each line executes". Based on that, as far as I can see, this should work, but shows 'not enough money:

     

    } else {
    
    //     4    +    4      >=    6
    if ($wallet + $balance >= $amount) {
    
    //   8  =               4    +    4
    $balance = (string)($balance + $wallet);
    
    //   2   =              8    -    6
    $balance = (string)($balance - $amount);
    $wallet= '0';
    
    $db->where('id', $user_id);
    $update_user_balance = $db->update(T_USERS, [
    'balance' => $balance
    ]);
    
    }
    }

     

    any additional guidance is appreciated

     

     

  8. Thanks for your reply. 

    This seems to work successfully, where a purchase uses the amount in ‘wallet’ first, and then uses the amount in ‘balance’ if there is not enough in ‘wallet’:

    however, if all videos cost 2 (or higher), and there is “1” left in the ‘wallet’, it will never get used. I am looking to see how I can make more like if ‘wallet’ is zero then deduct from ‘earnings’ (or wallet + balance = amount)…

    I have tried this revision without success:

    		// Check if user has enough wallet amount to purchase video
    		if($wallet >= $amount){
    
    			$wallet = (string)($wallet - $amount);
    			$db->where('id', $user_id);
    			$update_wallet = $db->update(T_USERS, [
    				'wallet' => $wallet
    			]);
    
    			} else {
    
    			if($wallet < $amount && $wallet + $balance >= $amount){
    
    			$wallet = (string)($wallet - $amount) + $balance = (string)($balance - $amount);
    
    							$db->where('id', $user_id);
    							$update_user_balance = $db->update(T_USERS, [
    								'balance' => $balance
    								]);
    							$db->where('id', $user_id);
    							$update_wallet = $db->update(T_USERS, [
    							'wallet' => $wallet
    							]);
    						}
    			}

    I’m trying to say this;
    if what’s in the ‘wallet’ is less than the amount AND $balance has more than or equal to the amount:

    if($wallet < $amount && $wallet + $balance >= $amount){

     

    then proceed to deduct whatever is left in 'wallet' to satisfy the amount + the rest of the amount from $balance:

    $wallet = (string)($wallet - $amount) + $balance = (string)($balance - $amount);

     

    but, apparently I need to say this better in code:
    “then proceed to deduct whatever is left in 'wallet' to satisfy the amount + the rest of the amount from $balance”

    any additional help is greatly appreciated.

     

  9. Thanks for your reply. Much appreciated.

    I have tried your suggestion without success.

    I see a pop-up dialog box  that displays: "Something went wrong. Please try again later!!" (from the script.js file):

     

    function PT_MultipleBuyVideo() {
        var checked = getSelectedVideos();
        if (!checked) { return false; }
    
        swal({
            title: "",
            type: "info",
            html:"Simply proceed to purchase " + countSelectedVideos() + " video(s) at a total cost of " + countTotalCredits() +" credits",
            showCancelButton: true,
            cancelButtonText: "Close",
            customClass: 'sweetalert-lg',
            confirmButtonText:'Proceed'
        }).then(function(){
    
            $.ajax({
                url: PT_Ajax_Requests_File() + 'aj/buy-video',
                type: 'POST',
                dataType: 'json',
                data: {id:checked},
            }).done(function(data){
                if (data.status == 200) {
                    for (var i = 0; i < checked.length; i++) {
                        var button = $("button[data-action='multiple_select_button'][data-id='" + checked[i] + "']")
                        buttonMultipleSelectingStyle(button, 'purchased');
                    }
    
                    swal({
                        title: "Success",
                        type: "success",
                        html:"",
                        showCancelButton: true,
                        cancelButtonText: "Close",
                        customClass: 'sweetalert-lg',
                        confirmButtonText:'Go To Video(s)'
                    }).then(function(){
                        window.location.href='/paid-list';
                    });
    
                } else {
                    if (data.error_num == 1) {
                        swal(
                            'Error!',
                            'Not enough money(test)',
                            'error'
                        );
                    } else {
                        swal(
                            'Error!',
                            'Something went wrong. Please try again later!',
                            'error'
                        );
                    }
                }
            }).fail(function() {
                swal(
                    'Error!',
                    'Something went wrong. Please try again later!!',
                    'error'
                );
            })
        });
    }

    The only thing that shows 'not enough money' from 'wallet' or "success' (when there is enough) is this:

    		if($wallet + $balance >= $amount) {
    		$wallet = (string)($wallet - $amount);
    		 //}elseif    $wallet = 0; {
    		$balance = ($balance - $amount);
    
    		$db->startTransaction();

    Any other ideas will be appreciated

     

     

  10. So, I just tried this without success:
     

    Code:
    	if ($wallet >= $amount) {
    		$wallet = (string)($wallet - $amount);
    		} elseif ($wallet + $balance >= $amount) {
    		$balance = (string)($balance - $amount);
    		$db->startTransaction();
    
    etc....

    By ‘without success’, I mean that the same message appears as if just the ‘wallet’ doesn’t have enough “Not Enough Money” - when I test - by having 3 in ‘wallet’ and 3 in earnings (equals a total of 6) but try to purchase something that costs 5.

    Any suggestion, guess or guidance will be appreciated.

  11.  

    In my account 'wallet' I have 3, and in 'balance' I have 3, which equals a total of 6. I tried to purchase a total of 5, with this code added: 

    if($wallet >= $amout) {
       // take money first from wallet
    } elseif ($wallet + $balance >= $amout) {
       // take money first from wallet and/or balance
    } else {
    		echo json_encode([
    			'status' => 400,
    			'error_num' => 1,
    			'error' => 'Not enough money'
    		]);
    
    } else {

    I saw 
    "Something went wrong. Please try again later!!"

     

    any additional help is appreciated

  12. Thanks for your reply.

    I appreciate your time you've taken to explain. It all makes sense.
    It is  a lot for me to implement, although I'm working on it.

    However, the first step for me, I believe, would be to get help with adding in these things you've commented, please, before I start improving my tables.:
    // it is here that you would include the balance amount
    // you would calculate new wallet and balance amounts
    // you would include the new 'balance' too

    any guidance, examples of what's needed there, will be greatly helpful.

  13. Thank you for your helpful reply. Much appreciated.

    I've replaced my original file with your commented code. Much thanks for helping clarify what is going on there, and for the small changes that you made to the (now improved) code.

    I am still looking for a solution where the script first checks the “wallet” amount, and if empty will then check the “balance” amount, and use a required amount from the balance, and if both are empty, then the “not enough money” appears. This was suggested, but I failed at integrating it into the code:

    if($wallet->balance() + $balance->balance() >= $amount) {
        $walletAmount = min($amount, $wallet->balance();
        $balanceAmount = ($walletAmount < $amount) ? $amount - $walletAmount : 0;
        // could then create deduct() methods to extract funds
        $wallet->deduct($walletAmount);
        $balance->deduct($balanceAmount);
    }
    else {
        // handle not enough money here
    }

    any guidance with that would be very helpful.

    In regard to an 'account' table, thanks for that great advice. The script currently does have u_paid_videos table, as you can see at: // add data to paid table. Would expanding this table to include more be satisfactory? I've attached a picture of it's structure (all though time_date just shows NULL ).

    Any additional comments/direction/advice is welcomed.

    u_paid.png

  14. I am using a php web video script which allows Users to purchase videos successfully. The purchases are made from the amount available in the Users’ “wallet” (the User can also earn compensation, which gets added to his “balance”.). When there’s not enough available in the “wallet” for the purchase, the script checks and displays a message “not enough money”. I’d like help adding the ability where the script first checks the “wallet” amount, and if empty will then check the “balance” amount, and use a required amount from the balance, and if both are empty, then the “not enough money” appears. Here’s the portion of the code that I believe needs the modification:

    // get cost video
        $db->where('name', 'video_play_price');
        $db_cost = $db->getOne('config');
        $video_cost = (float)$db_cost->value;
    
        $count_video = count($id_array);
        $user_id = $user->id;
        $wallet = (float)str_replace(',', '', $user->wallet);
    
    
    	$amout = 0;
    	foreach ($id_array as $id) {
                $video_id = (int)PT_Secure($id);
    
                // get video data
                $video = $db->where('id', $id)->getOne(T_VIDEOS);
    			$amout += $video->video_play_price?$video->video_play_price:$video_cost;
    	}
    
    //   $amout = $video_cost * $count_video;
    
        $charge = ( $video_cost *0.50 );
    
    
    
        if ($wallet >= $amout) {
    
            //$new_wallet = (string)($wallet - $amout);
            $wallet = (string)($wallet - $amout);
    
            $db->startTransaction();
    
            $inserted_records = 0;
            foreach ($id_array as $id) {
                $video_id = (int)PT_Secure($id);
    
    
    		// $uploader_amount = $video_cost - $charge; //100 - 20% = 80
    
                // get video data
                $video = $db->where('id', $id)->getOne(T_VIDEOS);
    
    
    
    			$video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost;
    
    			$uploader_amount = ( $video_cost_new *0.50 );
                // add data to paid table
                $insert_buy = $db->insert('u_paid_videos', [
                    'id_user' => $user_id,
                    'id_video' => $video_id,
                    'session_key' => $_SESSION['session_key'],
                    'video_play_price' => (string)$video_cost,
                    'video_title' => $video->title,
                    'user_id_uploaded' => $video->user_id,
                ]);
    
                if ($insert_buy) { $inserted_records++; }
                //add wallet users' video
            $userwallet = $db->where('id', $video->user_id)->getOne(T_USERS);
    
    
            //$videouserwallet = $userwallet->balance+$video_cost;
            $videouserwallet = $userwallet->balance+$uploader_amount;
            $db->where('id', $video->user_id);
            $update_balance = $db->update(T_USERS, [
              // 'wallet' => $videouserwallet,
                'balance' => number_format($videouserwallet, 1, '.', ''),
            ]);
            }
    
    
            $db->where('id', $user_id);
            //$update_wallet = $db->update(T_USERS, [
            $update_wallet = $db->update(T_USERS, [
                'wallet' => $wallet,
            ]);
    
    
            if (($inserted_records == $count_video) && $update_wallet) {
                $db->commit();
    
                echo json_encode([
                    'status' => 200
                ]);
                exit();
            } else {
                $db->rollback();
    
                echo json_encode([
                    'status' => 400,
                    'error' => 'Buy process error'
                ]);
                exit();
            }
    
        } else {
    
            echo json_encode([
                'status' => 400,
                'error_num' => 1,
                'error' => 'Not enough money'
            ]);
            exit();
    
        }
    
    } else {
    
        echo json_encode([
            'status' => 400,
            'error' => 'Bad Request, Invalid or missing parameter'
        ]);
        exit();

     

  15. I'm using an upload script (I did not write it) that works successfully.

     

    I'm trying to add the function where you 'must check box to agree to terms' prior to uploading a file.

     

    I've added lines 67 thru 75, and lines 88 thru 92, but it is missing something, because, whether the box is checked or not, a file can still be uploaded.

     

    Any guidance will be appreciated.

    <?php
    session_start();
    require_once 'phps3integration_lib.php';
    $message = "";
    if (@$_POST['submit'] != "") {
    $allowed_ext = array("gif", "jpeg", "jpg", "png", "pdf", "doc", "docs", "zip", "mov", "MOV", "flv", "mp4", "3gp", "3GP");
    $extension = end(explode(".", $_FILES["file"]["name"]));
    if (($_FILES["file"]["size"] < 10485760000) && in_array($extension, $allowed_ext)) {
    if ($_FILES["file"]["error"] > 0) {
    //$message.="There is some error in upload, see: " . $_FILES["file"]["error"] . "<br>";//Enable this to see actual error
    $message.="There is some error in upload. Please try after some time.";
    } else {
    $uploaddir = '../Upload/';
    $uploadfile = $uploaddir . basename($_FILES['file']['name']);
    $uploaded_file = false;
    if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
    {
    $uploaded_file = $_FILES['file']['name'];
    }
    if ($uploaded_file != FALSE) {
    $user_name = @$_POST['user_name'] != "" ? @$_POST['user_name'] : "Anonymous";
    $form_data = array(
    'file' => $uploaded_file,
    'user_name' => $user_name,
    'type' => 'file'
    );
    mysql_query("INSERT INTO `phps3files` (`id`, `file`, `user_name`, `type`) VALUES (NULL, '" . $uploaded_file . "', '" . $user_name . "', 'file')") or die(mysql_error());
    $message.= "File Successfully Uploaded";
    } else {
    $message.="There is some error in upload. Please try after some time.";
    }
    }
    } else {
    $message.= "Invalid file, Please upload a gif/jpeg/jpg/png/pdf/doc/docs/zip/mov/flv/mp4/3gp file of maximum size 25 MB.";
    }
    }
    ?>
    
    <?php
    require_once 'header.php';
    ?>
    <head>
    
    <script>
    var ids = ['input', 'message', 'button'];
    var obj = {};
    
    ids.forEach(function (v) {
        obj[v] = document.getElementById(v);
    });
    
    obj.input.style.display = 'none';
    obj.button.style.display = 'block';
    
    obj.input.addEventListener('change', function () {
        obj.message.innerText = this.value;
        obj.message.style.display = 'block';
    });
    
    obj.button.addEventListener('click', function (e) {
        e.preventDefault();
    
        obj.input.click();
    });
    </script>
    
    <script type="text/javascript">
    function validate()
    {
    if(false == document.getElementById("agree").checked)
    {
    alert("If you agree with the terms, check the Agree check box");
    }
    }
    </script>
    
    </head>
    <html>
    <fieldset>
    <form action="" method="post" enctype="multipart/form-data">
    
    <div class="control-group">
    <label for="file" class="control-label"><font size="6" color="#454545"><b>Choose a file to upload:</b></font></label><br /><br />
    <input id="input" name="file" type="file" /></input>
    <button id="button"><font size="3" color="#454545">Click To<br /> Select File</font></button>
    <div id="message"><font size="3" color="#454545">No File Chosen</font></div>
    </div>
    <div>
    <input type="checkbox" name="agree" id="agree" value="agree" /> <label for='agree'>
    <a href="../Terms1.php" target="_blank"><span style="color: #454545; font-size: 10px">By uploading a file here, you agree to these <u>Upload Terms/Agreement</u></a></span>
    </label>
    </div>
    <div class="control-group">
    <div class='controls'>
    <label class="myLabel1">
    <input type="submit" name="submit" value="Submit" class="btn" style="opacity: 0">
    </label><
    </div>
    </form>
    </fieldset>
    
    <script>
    var ids = ['input', 'message', 'button'];
    var obj = {};
    
    ids.forEach(function (v) {
        obj[v] = document.getElementById(v);
    });
    
    obj.input.style.display = 'none';
    obj.button.style.display = 'inline-block';
    
    obj.input.addEventListener('change', function () {
        var filename = this.value.replace(/^.*[\\\/]/, '');
    		obj.message.innerHTML  = filename;
        obj.message.style.display = 'inline-block';
    });
    
    obj.button.addEventListener('click', function (e) {
        e.preventDefault();
    
        obj.input.click();
    });
    
    </script>
    <?php
    if ($message != "" || @$_SESSION['message'] != "") {
        ?>
        <div class="alert alert-success">
        <?php echo $message; ?>
        <?php
        echo @$_SESSION['message'];
        @$_SESSION['message'] = '';
        ?>
        </div>
        <?php
    }
    ?>
    <div>
    </div>
    
    <?php require_once 'footer.php'; ?>
    
    
    
  16. Thanks for your replies.

     

    Regarding "show us the code", I have showed the php in the intial posting, and here is the Form:

    <form action='../ContactForm.php' method='post' name='myform' onSubmit="return checkemail()">
    <div class="row">
    <div class="col-sm-4">
    <input class="form-control" type="text" name='contact_name' placeholder="Name">
    </div>
    <div class="col-sm-4">
    <input class="form-control" type="text" name='email_address' placeholder="Email">
    </div>
    </div>
    <br>
    <div class="row">
    <div class="col-sm-12">
    <textarea name='Description' placeholder="Type your message here..." class="form-control" rows="9"></textarea>
    </div>
    </div>
    <div class="row">
    <div class="col-sm-4">
    <p style="color:grey; font-size:15px;"><b>Security Question:<br> Is Fire Hot Or Cold?:</p>
    <input type="text" name="ans"/><br>
    <div>
    <div class="row">
    <div class="col-sm-4">
    <input class="btn btn-action" type='submit' value="Send message">
    </div>
    </div>
    </div>
    </form>
    

    Regarding "Can you assign a header call to a variable?", I'm not clear on that. Is my url(s) the variable?

    Any clarification, and/or code tweak suggestion will be greatly appreciated.

  17. Thanks so much for your reply.

    Yes, I have this input field:

    <input type="text" name="ans"/>
    

    which works successfully from my windows desktop. After entering 'hot' and select 'Send Message' I am successfully directed to the page(I've changed the url for this posting) listed here"

    // if no errors are set, continue
    if(empty($error))
    {
    header('Location: ww.somesite.com/ThankYou.html');
    exit;
    }
    

    And also, from my desktop if I enter anything other than 'hot', and select 'Send Message', I'm successfully directed to the page listed here:

    $error[] = header('Location: ww.somesite.com/WrongAnswer.html');
    exit;
    

    But from my iPhone when I enter 'hot' (or anything else) and select either 'Send Message", Done(on the phone) and then 'Send Message', or 'Go'(on the phone), no matter what, I'm directed to this page:

    ww.somesite.com/WrongAnswer.html
    

    So, if it's true that "Entering text on a mobile is no different than a fixed desktop", than obviously and not surprisingly, my code needs some type of correction/modification.

     

    Any ideas/suggestions will be appreciated.

    Much thanks again

  18. I realize this is old code (that I didn't write) but works well for a temporary 'under construction' page.
    After filling in the simple Form fields the simple Security question is presented : Is fire Hot or Cold?
    When I enter text into the answer field it works successfully, except, of course on a mobile device. In order for it to work on a mobile device, I believe I need to present a choice, rather than entering text - correct?
    So, I'm looking for a possible simple tweak on this code, so that it will work for a mobile device, please. I don't really want to re-write all of it, and I know it's not super-secure, but it will do for now.
     
    Here's the last part of the Form:
     
    <div>
    <p>Security Question:<br> Is Fire Hot Or Cold?:
    <input type="text" name="ans"/></p><br>
    <p><input class="btn btn-action" type='submit' value="Send message"></p>
    </div>
    </form>
    
    And
     
    
    <?php
    // create an empty error array to hold any error messages\
    $error = array();
    $mailto     = 'someone@somewhere.com';
    $mailsubj   = "ContactForm Submission";
    $mailhead   = "From:SomehereForm\n";
    $mailbody   = "--- Contact form results ---\n";
    foreach($_REQUEST as $key => $value)
    {
    if($key != 'PHPSESSID')
    {
    $mailbody .= $key.": ".$value."\n";
    }
    }
    if(isset($_POST['ans']) && $_POST['ans']!='hot')
    {
    // add error to error array
    $error[] = header('Location: ww.somesite.com/WrongAnswer.html');
    exit;
    }
    // if no errors are set, continue
    if(empty($error))
    {
    header('Location: ww.somesite.com/ThankYou.html');
    exit;
    }
    ?>
    

    Is it possible to add something like:

    <option value="ans">hot</option>
    <option value="">cold</option>
    

    and then change this somehow:

    $error['anything other than hot'] = header('Location: ww.somesite.com/WrongAnswer.html');
    exit;
    

    Any tweak help will be appreciated.

  19. Thanks for your reply.

     

    I saw this on a Support Forum (i'm not sure if it pertains to this) It said this:

    "If you already have your parameters set like $_POST['eg'] for example and you don't wish to change it, simply do it like this:

    $_POST = json_decode(file_get_contents('php://input'), true);
    

    This will save you the hassle of changing all $_POST to something else and allow you to still make normal post requests."

     

    Would that work in my situation?

  20. Thanks again for your reply.

     

    Here's the Form:

    		<form id="ajax-contact" method="post">
            <table class="table10">
            <tr>
            <td colspan="3"><textarea id="contact-message" placeholder="MESSAGE:" required/></textarea>
            </td>
    		<tr>
    		<td>
            <input id="contact-name" name="name" value="NAME" onfocus="if (this.value=='NAME') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Name')" onblur="clickrecall(this,'')" required/>
            </td>
    		<td>
            <input id="contact-email1" name="email" value="EMAIL" onfocus="if (this.value=='EMAIL') {this.value=''; this.style.color='#696969';}" required/>
            </td>
            <tr>
    		<td class="captcha">
    		ENTER IMAGE TEXT:  <input name="captcha" style="width:100px" type="text" required/>  <img src="captcha.php" />
    		</td>
    		<td>
            <input type="hidden" name="submit" ><input class="my-input1" type="submit" value="SEND">
            </td>
            </tr>
            </table>
    		</form>
    
  21. Thanks for your reply.

    But, I'm not clear on what you're asking for. Is it this?:

    <?php
    session_start();
    $code=rand(1000,9999);
    $_SESSION["code"]=$code;
    $im = imagecreatetruecolor(80, 24);
    $bg = imagecolorallocate($im, 177, 78, 78);
    $fg = imagecolorallocate($im, 255, 255, 255);
    imagefill($im, 0, 0, $bg);
    imagestring($im, 5, 24, 3,  $code, $fg);
    header("Cache-Control: no-cache, must-revalidate");
    header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im);
    ?>
    
  22. I merged this code from a captcha script:

     

    <?php
    session_start();
    if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
    {
    echo "Correct Code Entered";
    //Do your stuff
    }
    else
    {
    die("Wrong Code Entered");
    }
    ?>
    

    with a working Contact Form script code:

    <?php
    $data = json_decode(file_get_contents("php://input"));
    $name = trim($data->name);
    $name = str_replace(array("\r", "\n"), array(" ", " "), $name);
    $email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL);
    $message = trim($data->message);
    // Check that data was sent.
    if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "One or more invalid entries. Please try again.";
    exit;
    }
    
    $to = "support@...com";
    $from = "From: contact-form@...com". "\r\n";
    $body = "A message has been sent via the website contact form.\n\n";
    $body .= "Name: $name\n";
    $body .= "Email: $email\n\n";
    $body .= "Message:\n$message\n";
    
    if (mail($to, 'Customer Inquiry', $body)){
    echo "Thank You. Your Message Has Been Sent.";
    } else {
    echo "An error has occurred and your message could not be sent.";
    }
    ?>
    

    to get this:

    <?php
    	session_start();
    	
    	$data = json_decode(file_get_contents("php://input"));
    	$name = trim($data->name);
    	$name = str_replace(array("\r", "\n"), array(" ", " "), $name);
    	$email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL);
    	$message = trim($data->message);
    	// Check that data was sent.
    	if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
    	echo "One or more invalid entries. Please try again.";
    	exit;
    	}
    	
    	if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
    	{
    	echo "Correct Code Entered";
    	//Do your stuff
    	}
    	else
    	{
    	die("Wrong Code Entered");
    	}
    	
    	$to = "support@...com";
    	$from = "From: contact-form@...com". "\r\n";
    	$body = "A message has been sent via the website contact form.\n\n";
    	$body .= "Name: $name\n";
    	$body .= "Email: $email\n\n";
    	$body .= "Message:\n$message\n";
    	
    	if (mail($to, 'Customer Inquiry', $body)){
    	echo "Thank You. Your Message Has Been Sent.";
    	} else {
    	echo "An error has occurred and your message could not be sent.";
    	}
    ?>
    

    but after I tested/completed the Form, including entering the correct Captcha code, I see the message "Wrong Code Entered", and of course the Contact Form info does not send.

     

    I added this (after the 'session start' line):

    var_dump($_SESSION);
    

    and ran the Form, and I see this:

    array(2) { ["security_code"]=> string(6) "9569qb" ["code"]=> int(6133) } Wrong Code Entered
    

    Any guidance with integrating captcha script successfuly will be appreciated.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.