1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Mihalism Image Hosting Script, DreamHost, cURL, fopen and PHP

Discussion in 'PHP' started by ColorWP.com, Feb 14, 2008.

Thread Status:
Not open for further replies.
  1. #1
    Hello, I am using the mihalism image hosting script (I uploaded it to my site here, because the official site requires registration to be able to download) and I host it on DreamHost, but they don't allow the script to use remote file opening, so my image host's remote uploader doesn't work. The site I am using it in is Image Pik.

    DreamHost allows cURL though, so I though I could modifiy the script so it uses cURL to get the remote file instead of fopen, but I am getting the same error, when I tryed to use the remote uploader.

    Here is the original upload.php file (unmodified by me):
    <?php
    	// ======================================== \
    	// Package: Mihalism Multi Host
    	// Version: 3.1.2
    	// Copyright (c) 2007, 2008 Mihalism, Inc.
    	// License: http://www.gnu.org/licenses/old-licenses/gpl-3.0.txt GNU Public License
    	// ======================================== /
    	
    	require_once('./page_header.php');
    
    	$file_count = 0;
    	$path       = $CONFIG['file_path'];
    
    	switch($_POST['type']){
    		case 'url_upload':
    			url_upload();
    			break;
    		default:
    			direct_upload();
    	}
    
    	function url_upload(){
    		global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
    		for($i = 0; $i <= 15; $i++){
    			$file = array(
    				'name'  => array_shift(explode('?', basename($_POST['userfile'][$i]))),
    				'url'   => $_POST['userfile'][$i],
    				'rand'  => random_string(20)
    			);
    			if($file['name'] != ''){
    				$file_count++;
    				if($file_count <= 15){
    					if($i >= 1){
    						echo "<div class='cell_divider'></div><br>\n";
    					}
    					$extension = file_type($file['name']);
    					$filename  = $file['rand'].".".$extension;
    					$thumbnail = thumbnail_name($filename);
    					if(!preg_match("/(https|http|ftp):\/\/[^\"\s']+/", $file['url'])){
    						message("The file <b>{$file['name']}</b> contains a invalid URL.");
    					}elseif(!in_array($extension, $CONFIG['file_types'])){
    						message("The file <b>{$file['name']}</b> extension is not allowed.");
    					}elseif(!$fcc = implode('', file($file['url']))){
    						message("The file <b>{$file['name']}</b> is not readable or does not exists.");
    					}elseif(strlen($fcc) > $CONFIG['max_file_size']){
    						message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
    					}elseif(strlen($fcc) < 5){
    						message("The file <b>{$file}</b> contains no data.");
    					}elseif(file_exists(ROOT_PATH.$path.$filename) !== false){
    						message("The file <b>{$file['name']}</b> seems to already exists on this server.");
    					}elseif(!fwrite(fopen($path.$filename, 'x'), $fcc)){
    						message("File transfer failed for file <b>{$file['name']}</b>.");
    					}else{
    						if($CONFIG['is_user'] == true){
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
    						}else{
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
    						}
    						$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
    						create_thumbnail($filename);
    						results_table();
    					}
    				}
    			}
    		}
    	}
    
    	function direct_upload(){
    		global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
    		for($i = 0; $i <= 15; $i++){
    			$file = array(
    				'name'  => $_FILES['userfile']['name'][$i],
    				'size'  => $_FILES['userfile']['size'][$i],
    				'tmp'   => $_FILES['userfile']['tmp_name'][$i],
    				'error' => $_FILES['userfile']['error'][$i],
    				'rand'  => random_string(20)
    			);
    			if($file['error'] != 4 && $file['name'] != ''){
    				$file_count++;
    				if($file_count <= 15){
    					if($i >= 1){
    						echo "<div class='cell_divider'></div><br>\n";
    					}
    					$extension = file_type($file['name']);
    					$filename  = $file['rand'].".".$extension;
    					$thumbnail = thumbnail_name($filename);
    					if(!in_array($extension, $CONFIG['file_types'])){
    						message("The file {$file['name']}</b> extension is not allowed.");
    					}elseif($file['size'] > $CONFIG['max_file_size']){
    						message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
    					}elseif($file['error'] != 0){
    						$filerror = array(			
    							1 => "The file <b>{$file['name']}</b> exceeds the <a href=\"http://us2.php.net/manual/en/ini.core.php#ini.upload-max-filesize\">upload_max_filesize</a> directive in php.ini.",
    							2 => "The file <b>{$file['name']}</b> exceeds the <b><i>MAX_FILE_SIZE</i></b> directive that was specified in the HTML form.",
    							3 => "The file <b>{$file['name']}</b> was only partially uploaded.",
    							6 => "Missing a temporary folder.",
    							7 => "Failed to write file <b>{$file['name']}</b> to disk.",
    							8 => "File <b>{$file['name']}</b> upload stopped by extension."
    								);
    						message($filerror[$file['error']]);
    					}elseif(file_exists(ROOT_PATH.$path.$filename)){
    						message("The file <b>{$file['name']}</b> seems to already exists on this server.");
    					}elseif(!move_uploaded_file($file['tmp'], ROOT_PATH.$path.$filename)){
    						message("File upload failed for file <b>{$file['name']}</b>.");
    					}else{
    						if($CONFIG['is_user'] == true){
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
    						}else{
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
    						}
    						$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
    						create_thumbnail($filename);
    						results_table();
    					}
    				}
    			}
    		}
    	}
    
    	if($file_count == 0){
    		message("Please go back and ".(($_POST['type'] != 'url_upload') ? 'select' : 'enter')." at least one file to upload.");
    	}
    
    	require_once('./page_footer.php');
    ?>
    
    PHP:
    And this is how I edited it (just added the cURL option):
    <?php
    	// ======================================== \
    	// Package: Mihalism Multi Host
    	// Version: 3.1.2
    	// Copyright (c) 2007, 2008 Mihalism, Inc.
    	// License: http://www.gnu.org/licenses/old-licenses/gpl-3.0.txt GNU Public License
    	// ======================================== /
    	
    	require_once('./page_header.php');
    
    	$file_count = 0;
    	$path       = $CONFIG['file_path'];
    
    	switch($_POST['type']){
    		case 'url_upload':
    			url_upload();
    			break;
    		default:
    			direct_upload();
    	}
    
    	function url_upload(){
    		global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
    		for($i = 0; $i <= 15; $i++){
    			$file = array(
    				'name'  => array_shift(explode('?', basename($_POST['userfile'][$i]))),
    				'url'   => $_POST['userfile'][$i],
    				'rand'  => random_string(20)
    			);
    if (function_exists('curl_init')) {
    
       $ch = curl_init();
    
       curl_setopt($ch, CURLOPT_URL, $file['url']);
    
       curl_setopt($ch, CURLOPT_HEADER, 0);
    
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
       curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
    
       $content = curl_exec($ch);
    
       curl_close($ch);
    } else {
    echo "cURL problem on the server";
    }
    			if($file['name'] != ''){
    				$file_count++;
    				if($file_count <= 15){
    					if($i >= 1){
    						echo "<div class='cell_divider'></div><br>\n";
    					}
    					$extension = file_type($file['name']);
    					$filename  = $file['rand'].".".$extension;
    					$thumbnail = thumbnail_name($filename);
    					if(!preg_match("/(https|http|ftp):\/\/[^\"\s']+/", $file['url'])){
    						message("The file <b>{$file['name']}</b> contains a invalid URL.");
    					}elseif(!in_array($extension, $CONFIG['file_types'])){
    						message("The file <b>{$file['name']}</b> extension is not allowed.");
    					}elseif(!$fcc = implode('', $content)){
    						message("The file <b>{$file['name']}</b> is not readable or does not exists.");
    					}elseif(strlen($fcc) > $CONFIG['max_file_size']){
    						message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
    					}elseif(strlen($fcc) < 5){
    						message("The file <b>{$file}</b> contains no data.");
    					}elseif(file_exists(ROOT_PATH.$path.$filename) !== false){
    						message("The file <b>{$file['name']}</b> seems to already exists on this server.");
    					}elseif(!fwrite(fopen($path.$filename, 'x'), $fcc)){
    						message("File transfer failed for file <b>{$file['name']}</b>.");
    					}else{
    						if($CONFIG['is_user'] == true){
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
    						}else{
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
    						}
    						$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
    						create_thumbnail($filename);
    						results_table();
    					}
    				}
    			}
    		}
    	}
    
    	function direct_upload(){
    		global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
    		for($i = 0; $i <= 15; $i++){
    			$file = array(
    				'name'  => $_FILES['userfile']['name'][$i],
    				'size'  => $_FILES['userfile']['size'][$i],
    				'tmp'   => $_FILES['userfile']['tmp_name'][$i],
    				'error' => $_FILES['userfile']['error'][$i],
    				'rand'  => random_string(20)
    			);
    			if($file['error'] != 4 && $file['name'] != ''){
    				$file_count++;
    				if($file_count <= 15){
    					if($i >= 1){
    						echo "<div class='cell_divider'></div><br>\n";
    					}
    					$extension = file_type($file['name']);
    					$filename  = $file['rand'].".".$extension;
    					$thumbnail = thumbnail_name($filename);
    					if(!in_array($extension, $CONFIG['file_types'])){
    						message("The file {$file['name']}</b> extension is not allowed.");
    					}elseif($file['size'] > $CONFIG['max_file_size']){
    						message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
    					}elseif($file['error'] != 0){
    						$filerror = array(			
    							1 => "The file <b>{$file['name']}</b> exceeds the <a href=\"http://us2.php.net/manual/en/ini.core.php#ini.upload-max-filesize\">upload_max_filesize</a> directive in php.ini.",
    							2 => "The file <b>{$file['name']}</b> exceeds the <b><i>MAX_FILE_SIZE</i></b> directive that was specified in the HTML form.",
    							3 => "The file <b>{$file['name']}</b> was only partially uploaded.",
    							6 => "Missing a temporary folder.",
    							7 => "Failed to write file <b>{$file['name']}</b> to disk.",
    							8 => "File <b>{$file['name']}</b> upload stopped by extension."
    								);
    						message($filerror[$file['error']]);
    					}elseif(file_exists(ROOT_PATH.$path.$filename)){
    						message("The file <b>{$file['name']}</b> seems to already exists on this server.");
    					}elseif(!move_uploaded_file($file['tmp'], ROOT_PATH.$path.$filename)){
    						message("File upload failed for file <b>{$file['name']}</b>.");
    					}else{
    						if($CONFIG['is_user'] == true){
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
    						}else{
    							$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
    						}
    						$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
    						create_thumbnail($filename);
    						results_table();
    					}
    				}
    			}
    		}
    	}
    
    	if($file_count == 0){
    		message("Please go back and ".(($_POST['type'] != 'url_upload') ? 'select' : 'enter')." at least one file to upload.");
    	}
    
    	require_once('./page_footer.php');
    ?>
    
    PHP:
    But it doesn't work. I am getting the same error "The file xxx.jpg is not readable or does not exist.".

    Can anybody with cURL knowledge help me?
     
    ColorWP.com, Feb 14, 2008 IP
  2. stoli

    stoli Peon

    Messages:
    69
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You don't need the "implode" because $content is a string not an array.

    You could do away with your $content variable and just set $fcc with the curl_exec return value directly.

    Here is your code with that fix applied:
    <?php
        // ======================================== \
        // Package: Mihalism Multi Host
        // Version: 3.1.2
        // Copyright (c) 2007, 2008 Mihalism, Inc.
        // License: http://www.gnu.org/licenses/old-licenses/gpl-3.0.txt GNU Public License
        // ======================================== /
       
        require_once('./page_header.php');
    
        $file_count = 0;
        $path       = $CONFIG['file_path'];
    
        switch($_POST['type']){
            case 'url_upload':
                url_upload();
                break;
            default:
                direct_upload();
        }
    
        function url_upload(){
            global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
            for($i = 0; $i <= 15; $i++){
                $file = array(
                    'name'  => array_shift(explode('?', basename($_POST['userfile'][$i]))),
                    'url'   => $_POST['userfile'][$i],
                    'rand'  => random_string(20)
                );
    if (function_exists('curl_init')) {
    
       $ch = curl_init();
    
       curl_setopt($ch, CURLOPT_URL, $file['url']);
    
       curl_setopt($ch, CURLOPT_HEADER, 0);
    
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
       curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
    
       $fcc = curl_exec($ch);
    
       curl_close($ch);
    } else {
    echo "cURL problem on the server";
    }
                if($file['name'] != ''){
                    $file_count++;
                    if($file_count <= 15){
                        if($i >= 1){
                            echo "<div class='cell_divider'></div><br>\n";
                        }
                        $extension = file_type($file['name']);
                        $filename  = $file['rand'].".".$extension;
                        $thumbnail = thumbnail_name($filename);
                        if(!preg_match("/(https|http|ftp):\/\/[^\"\s']+/", $file['url'])){
                            message("The file <b>{$file['name']}</b> contains a invalid URL.");
                        }elseif(!in_array($extension, $CONFIG['file_types'])){
                            message("The file <b>{$file['name']}</b> extension is not allowed.");
                        }elseif(!$fcc){
                            message("The file <b>{$file['name']}</b> is not readable or does not exists.");
                        }elseif(strlen($fcc) > $CONFIG['max_file_size']){
                            message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
                        }elseif(strlen($fcc) < 5){
                            message("The file <b>{$file}</b> contains no data.");
                        }elseif(file_exists(ROOT_PATH.$path.$filename) !== false){
                            message("The file <b>{$file['name']}</b> seems to already exists on this server.");
                        }elseif(!fwrite(fopen($path.$filename, 'x'), $fcc)){
                            message("File transfer failed for file <b>{$file['name']}</b>.");
                        }else{
                            if($CONFIG['is_user'] == true){
                                $DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
                            }else{
                                $DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
                            }
                            $DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
                            create_thumbnail($filename);
                            results_table();
                        }
                    }
                }
            }
        }
    
        function direct_upload(){
            global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
            for($i = 0; $i <= 15; $i++){
                $file = array(
                    'name'  => $_FILES['userfile']['name'][$i],
                    'size'  => $_FILES['userfile']['size'][$i],
                    'tmp'   => $_FILES['userfile']['tmp_name'][$i],
                    'error' => $_FILES['userfile']['error'][$i],
                    'rand'  => random_string(20)
                );
                if($file['error'] != 4 && $file['name'] != ''){
                    $file_count++;
                    if($file_count <= 15){
                        if($i >= 1){
                            echo "<div class='cell_divider'></div><br>\n";
                        }
                        $extension = file_type($file['name']);
                        $filename  = $file['rand'].".".$extension;
                        $thumbnail = thumbnail_name($filename);
                        if(!in_array($extension, $CONFIG['file_types'])){
                            message("The file {$file['name']}</b> extension is not allowed.");
                        }elseif($file['size'] > $CONFIG['max_file_size']){
                            message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
                        }elseif($file['error'] != 0){
                            $filerror = array(     
                                1 => "The file <b>{$file['name']}</b> exceeds the <a href=\"http://us2.php.net/manual/en/ini.core.php#ini.upload-max-filesize\">upload_max_filesize</a> directive in php.ini.",
                                2 => "The file <b>{$file['name']}</b> exceeds the <b><i>MAX_FILE_SIZE</i></b> directive that was specified in the HTML form.",
                                3 => "The file <b>{$file['name']}</b> was only partially uploaded.",
                                6 => "Missing a temporary folder.",
                                7 => "Failed to write file <b>{$file['name']}</b> to disk.",
                                8 => "File <b>{$file['name']}</b> upload stopped by extension."
                                    );
                            message($filerror[$file['error']]);
                        }elseif(file_exists(ROOT_PATH.$path.$filename)){
                            message("The file <b>{$file['name']}</b> seems to already exists on this server.");
                        }elseif(!move_uploaded_file($file['tmp'], ROOT_PATH.$path.$filename)){
                            message("File upload failed for file <b>{$file['name']}</b>.");
                        }else{
                            if($CONFIG['is_user'] == true){
                                $DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
                            }else{
                                $DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
                            }
                            $DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
                            create_thumbnail($filename);
                            results_table();
                        }
                    }
                }
            }
        }
    
        if($file_count == 0){
            message("Please go back and ".(($_POST['type'] != 'url_upload') ? 'select' : 'enter')." at least one file to upload.");
        }
    
        require_once('./page_footer.php');
    ?>
    PHP:
     
    stoli, Feb 14, 2008 IP
    www.Andro.ws likes this.
  3. ColorWP.com

    ColorWP.com Notable Member

    Messages:
    3,121
    Likes Received:
    100
    Best Answers:
    1
    Trophy Points:
    270
    #3
    Yes, it worked. You are great my friend. Rep applied...
     
    ColorWP.com, Feb 15, 2008 IP
  4. stoli

    stoli Peon

    Messages:
    69
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks. Glad to be able to help.
     
    stoli, Feb 15, 2008 IP
  5. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hy
    i'am Hungarian and I don't know this type of forum so i hope that i wrote in a suitable topic.

    So my problem that i want to write in the Public Gallery the number of upload images (and maybe the main page too). I am not a master php programmmer so if anybody can write down me the code?
    i am using the older version, my site: myphotoupload.extra.hu
     
    gery555, Aug 23, 2008 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi. I can help you. Message me and we can talk there. Should be simple and fast.
     
    NatalicWolf, Aug 23, 2008 IP
  7. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    where i message you (and punctually what) :confused:
    in PM?
     
    gery555, Aug 23, 2008 IP
  8. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    please, someone help!
     
    gery555, Aug 23, 2008 IP
  9. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hali

    i have the same question still!
    How I can write in the Public Gallery the number of upload images?

    Please help
    (only write me a PM or ask me to write him/her a PM who can and want to help me)
    thanks
     
    gery555, Aug 26, 2008 IP
  10. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hy again

    So i have another problem: I would like to write in admin panel (members section) the date of when was a member signed in last.
    --------------------------------------------------------------------------------------
    e.g. from Members menu
    name-----------joined------------e-mail....etc---------+----------last signed in
    gery----------2008 10 -------+----here i would like to write the last sign in date (or some one els)
    --------------------------------------------------------------------------------------


    I need only the code i can it put in
    thanks
    (I hope I was understandable)
     
    gery555, Dec 17, 2008 IP
  11. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    it's impossible to tell you without knowing what your database structure (table definitions) is like.
    and we need to see an example of a query being done to your database by your php
     
    rene7705, Dec 17, 2008 IP
  12. ColorWP.com

    ColorWP.com Notable Member

    Messages:
    3,121
    Likes Received:
    100
    Best Answers:
    1
    Trophy Points:
    270
    #12
    Well, I guess this is how it can be done: create a new table/field in the DB and edit the sign up file, so whenever a sign up is successful, it will add the current time to the field. Then in the admin panel have it extract this entry and show it.

    PS: The same thing can be done even with a simple .txt file and not the database.

    Create file time.txt on your server and give it write access. Here's is a simple piece of code for the signup page (I haven't tested those, so they might need fixing):
    <?php
    $myFile = "time.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $time = date("F j, Y, g:i a"); // see php.net/date
    fwrite($fh, $time);
    fclose($fh);
    ?>
    PHP:
    more about that: here

    The above code writes the current time in the file time.txt.

    In the admin panel you just use this simple code:
    <?php
    include("time.txt")
    ?>
    PHP:
    If that doesn't work try this:
    <?php
    $file = "time.txt";
    $fp=fopen($file,'r');
    $content=fread($fp,filesize($file));
    fclose($fp);
    echo "Last Signup: ";
    echo $content;
    ?>
    PHP:
    more about that: here
     
    ColorWP.com, Dec 18, 2008 IP
  13. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    that .txt method I do not know how I can ask it to operate, but the sql method is more better for me
    May be I can create new table, but I will stopped to write in and refreshes the time in the database

    (if I am ready the table I will ask the help - thx)

    -----------

    So i created a new field in "user_data", name: sign_time
    So can anybody tell me what should I modify in the sign up page?
    (the registration, the sign in form is in one file so I copy only the part of sign in):
    function login_form(){
    		global $BUTTON, $CONFIG;
    		echo "<form action='{$CONFIG['site_url']}users.php?act=login_go' method='post'>
    		<div class='tableborder'><table width='100%' class='row1' cellspacing='1' cellpadding='4' border='0' align='center'>
    		<tr><th colspan='2'>Add meg a felhaszn&aacute;l&oacute;neved és jelszavad a bejelentkezéshez.</th></tr>
    		<tr><td colspan='2'>&nbsp;</td></tr>
    		<tr><td colspan='2'><center>Ha m&aacute;r regisztr&aacute;lt tagunk vagy, akkor az al&aacute;bbi mez&otilde;ket kitöltve l&eacute;phetsz be!</center></td></tr>
    			<tr><td width='45%' align='right'>Felhaszn&aacute;l&oacute;n&eacute;v:</td><td><input type='text' name='user_name' size='25' value='{$UDATA['user_name']}'></td></tr>
    		<tr><td width='45%' align='right'>Jelsz&oacute;:</td><td><input type='password' name='user_password' size='25'></td></tr>
    		<tr align='center'><td colspan='2'><br><input type='image' src='{$BUTTON['login']}' alt='Bejelentkezés'></td></tr>
    		<tr><td width='45%'  colspan='2'>&nbsp;</td></tr>
    		<tr><td colspan='2'><center><b>M&eacute;g nem vagy tag? Regisztr&aacute;lj! <a href='users.php?act=register'>Kattints ide</a>!</b></center></td></tr>
    		<tr><td width='45%'  colspan='2'>&nbsp;</td></tr>
    		<tr><td colspan='2'><center>Elfelejtetted a jelsz&oacute;t? <a href='users.php?act=lost_password'>Kattints ide</a>!</center></td></tr>
    		<tr><td width='45%'  colspan='2'>&nbsp;</td></tr>
    		</table></div></form>";
    	}
    	
    	function do_login(){
    		global $DB, $CONFIG;	
    		$DB->query("SELECT * FROM `".SQL_USERS_TABLE."` WHERE `user_name` = '{$_POST['user_name']}'");
    		$data = $DB->fetch_row();
    		if(empty($_POST['user_name']) || empty($_POST['user_password'])){
    			message("Kérlek ellenőrizd, hogy minden mezőt kit&ouml;lt&ouml;ttél-e.");
    		}elseif($data['password'] != md5($_POST['user_password']) || $DB->get_num_rows() < 1){
    			message("A megadott felhaszn&aacute;l&oacute;név vagy jelsz&oacute; nem létezik.");
    		}else{
    			$key = random_string(200);
    			setcookie("mmh_user_cookie", "cookie_delete", time()-60000);
    			setcookie("mmh_user_cookie", "{$data['user_name']}.{$key}", $CONFIG['cookie_expire_time']);  
    			$DB->query("UPDATE `".SQL_USERS_TABLE."` SET `user_session` = '{$key}', `ip_address` = '{$_SERVER['REMOTE_ADDR']}' WHERE `user_name` = '{$_POST['user_name']}'");
    			message("Sikeresen bejelentkeztél a k&ouml;vetkező felhaszn&aacute;l&oacute;néven:  <b>{$data['user_name']}</b>.<br><br> Kattints <a href='index.php'>ide</a> képfelt&ouml;ltéshez", false);
    		}
    	}
    Code (markup):
    (I am and my site hungarian too, that's way there are hungarian sentences but if it is problem I can translate it if it is necessary)

    So if anybody can tell me the code what I need (only the code of time to write in somewhere than i can use it) I will thanks it!
    Help
    I did lots of changes in my site but it stopped me (myphotoupload.extra.hu)
     
    gery555, Dec 18, 2008 IP
  14. ColorWP.com

    ColorWP.com Notable Member

    Messages:
    3,121
    Likes Received:
    100
    Best Answers:
    1
    Trophy Points:
    270
    #14
    I have added the lines that will add the current time (assigned previously to $time) in the corresponding database field (sign_time in this case) for the user that is logging in:

    function login_form(){
    		global $BUTTON, $CONFIG;
    		echo "<form action='{$CONFIG['site_url']}users.php?act=login_go' method='post'>
    		<div class='tableborder'><table width='100%' class='row1' cellspacing='1' cellpadding='4' border='0' align='center'>
    		<tr><th colspan='2'>Add meg a felhaszn&aacute;l&oacute;neved es jelszavad a bejelentkezeshez.</th></tr>
    		<tr><td colspan='2'>&nbsp;</td></tr>
    		<tr><td colspan='2'><center>Ha m&aacute;r regisztr&aacute;lt tagunk vagy, akkor az al&aacute;bbi mez&otilde;ket kitoltve l&eacute;phetsz be!</center></td></tr>
    			<tr><td width='45%' align='right'>Felhaszn&aacute;l&oacute;n&eacute;v:</td><td><input type='text' name='user_name' size='25' value='{$UDATA['user_name']}'></td></tr>
    		<tr><td width='45%' align='right'>Jelsz&oacute;:</td><td><input type='password' name='user_password' size='25'></td></tr>
    		<tr align='center'><td colspan='2'><br><input type='image' src='{$BUTTON['login']}' alt='Bejelentkezes'></td></tr>
    		<tr><td width='45%'  colspan='2'>&nbsp;</td></tr>
    		<tr><td colspan='2'><center><b>M&eacute;g nem vagy tag? Regisztr&aacute;lj! <a href='users.php?act=register'>Kattints ide</a>!</b></center></td></tr>
    		<tr><td width='45%'  colspan='2'>&nbsp;</td></tr>
    		<tr><td colspan='2'><center>Elfelejtetted a jelsz&oacute;t? <a href='users.php?act=lost_password'>Kattints ide</a>!</center></td></tr>
    		<tr><td width='45%'  colspan='2'>&nbsp;</td></tr>
    		</table></div></form>";
    	}
    	
    	function do_login(){
    		global $DB, $CONFIG;	
    		$DB->query("SELECT * FROM `".SQL_USERS_TABLE."` WHERE `user_name` = '{$_POST['user_name']}'");
    		$data = $DB->fetch_row();
    		if(empty($_POST['user_name']) || empty($_POST['user_password'])){
    			message("Kerlek ellenorizd, hogy minden mezot kit&ouml;lt&ouml;ttel-e.");
    		}elseif($data['password'] != md5($_POST['user_password']) || $DB->get_num_rows() < 1){
    			message("A megadott felhaszn&aacute;l&oacute;nev vagy jelsz&oacute; nem letezik.");
    		}else{
    			$key = random_string(200);
    			setcookie("mmh_user_cookie", "cookie_delete", time()-60000);
    			setcookie("mmh_user_cookie", "{$data['user_name']}.{$key}", $CONFIG['cookie_expire_time']);  
    			$DB->query("UPDATE `".SQL_USERS_TABLE."` SET `user_session` = '{$key}', `ip_address` = '{$_SERVER['REMOTE_ADDR']}' WHERE `user_name` = '{$_POST['user_name']}'");
    
    // my editing starts here
    
    			$time = date("F j, Y, g:i a"); // see php.net/date
    			$DB->query("UPDATE `".SQL_USERS_TABLE."` SET `sign_time` = '$time' WHERE `user_name` = '{$_POST['user_name']}'");
    
    // my editing ends here
    
    			message("Sikeresen bejelentkeztel a k&ouml;vetkezo felhaszn&aacute;l&oacute;neven:  <b>{$data['user_name']}</b>.<br><br> Kattints <a href='index.php'>ide</a> kepfelt&ouml;lteshez", false);
    		}
    } // <-- btw, this line/bracket seems unneeded the way you posted it, but it may have an opening bracket above the two functions, that you didn't posted so leave it there
    PHP:
    Again, I wrote it without testing, so make sure you back up everything before trying it. Also, make sure you read those online tutorials about MYSQL Update and Insert commands, so you can do further updates yourself to the script, without the need of having to ask for help.

    Regards!

    PS: I would really appreciate reputation. :rolleyes:
     
    ColorWP.com, Dec 19, 2008 IP
  15. gery555

    gery555 Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Phu
    I am trying, I am trying

    ----------------

    yes, it's good
    its write in in the sql, I have to write in in the admin panel (I hope it will be succes)

    ---------------
    yes, it's operated well
    thanks a lot, thanks, thanks again
     
    gery555, Dec 20, 2008 IP
  16. ColorWP.com

    ColorWP.com Notable Member

    Messages:
    3,121
    Likes Received:
    100
    Best Answers:
    1
    Trophy Points:
    270
    #16
    I'm glad I was able to help. Anyway, to mention again - I don't mind any rep. To give me some, click the icon that looks like this ([​IMG]) in the top-right of my post. Thanks!

    I have opened this thread with a question that I have solved long time ago and I consider it can be closed by the mods, so it doesn't get filled with irrelevant and clustered questions.
     
    ColorWP.com, Dec 20, 2008 IP
    gery555 likes this.
Thread Status:
Not open for further replies.