Jump to content

stuffradio

Members
  • Posts

    253
  • Joined

  • Last visited

Posts posted by stuffradio

  1. Nevermind guys, I figured it out. Programming hours at a time doesn't help much :P

     

    I was posting the username field as "user" but it's actually "username" so it was just going by the first result it came up with from the password field!

  2. I have a query like this:

     

       $query = $this->CI->db->get_where('userstable', array('user' => $this->username, 'pass' => md5($this->password)));
    

     

    This is a CodeIgniter query. Here is a translated query in standard MySQL

     

    mysql_query("SELECT * FROM `userstable` WHERE `user`='$username' AND `pass`='md5($pass)'");
    

     

    That's fine, you would expect it to select values where the user = username and pass = pass. Well, the problem is it's returning all users that are similar to the username. I have multiple test accounts that are like this: "stuff, stuffradio, stuf" etc. and it always logs me in as stuffradio. Any ideas what is wrong?

  3. Let me rephrase my question.

     

    In Javascript, if you use document.writeln() or document.write()... you can only have one line written. How can I use Javascript to output mutliple lines without breaking.

  4. I have a PHP string that I get from a database. What I need to do is echo this in Javascript. How can I do something like document.writeln or document.write something that has multiple lines?

  5. I found this socket server now that does have a loop, but whenever it receives a client message then it dies.

     

    Where in here can I keep it alive?

     

    <?php
    error_reporting(E_ALL);
    mysql_connect("localhost", "root", "admin");
    mysql_select_db("awc");
    // don't timeout
    set_time_limit (10000);
    
    // set some variables
    $host = "192.168.0.197";
    $port = 2100;
    
    // create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
    socket\n");
    
    // bind socket to port
    $result = socket_bind($socket, $host, $port) or die("Could not bind to
    socket\n");
    
    // start listening for connections
    $result = socket_listen($socket, 3) or die("Could not set up socket
    listener\n");
    
    echo "Waiting for connections...\n";
    
    // accept incoming connections
    // spawn another socket to handle communication
    $spawn = socket_accept($socket) or die("Could not accept incoming
    connection\n");
    
    echo "Received connection request\n";
    
    // write a welcome message to the client
    $welcome = "Roll up, roll up, to the greatest show on earth!\n? ";
    socket_write($spawn, $welcome, strlen ($welcome)) or die("Could not send
    connect string\n");
    
    // keep looping and looking for client input
    do
    {
    // read client input
    $input = socket_read($spawn, 1024, 1) or die("Could not read input\n");
    
    if (trim($input) != "")
    {
      echo "Received input: $input\n";
      mysql_query("INSERT INTO `socket` (socketdata) VALUES ('$input')");
      // if client requests session end
      if (trim($input) == "END")
      {
      	// close the child socket
      	// break out of loop
      	socket_close($spawn);
      	break;
      }
      // otherwise...
      else
      {
      	// reverse client input and send back
      	$output = strrev($input) . "\n";
      	socket_write($spawn, $output . "? ", strlen (($output)+2)) or die("Could
    not write output\n");
      	echo "Sent output: " . trim($output) . "\n";
      }
    }
    
    } while (true);
    
    // close primary socket
    socket_close($socket);
    echo "Socket terminated\n";
    ?>

  6. <?php
    mysql_connect("localhost", "root", "admin");
    mysql_select_db("awc");
    // set some variables
    $host = "192.168.0.197";
    $port = 2100;
    
    // don't timeout!
    set_time_limit(0);
    
    // create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
    socket\n");
    
    // bind socket to port
    $result = socket_bind($socket, $host, $port) or die("Could not bind to
    socket\n");
    
    // start listening for connections
    $result = socket_listen($socket, 3) or die("Could not set up socket
    listener\n");
    
    // accept incoming connections
    // spawn another socket to handle communication
    $spawn = socket_accept($socket) or die("Could not accept incoming
    connection\n");
    
    // read client input
    $input = socket_read($spawn, 1024) or die("Could not read input\n");
    
    // clean up input string
    $input = trim($input);
    
    // reverse client input and send back
    $output = strrev($input) . "\n";
    socket_write($spawn, $output, strlen ($output)) or die("Could not write
    output\n");
    
    
    mysql_query("INSERT INTO `socket` (socketdata) VALUES ('$input')");
    // close sockets
    socket_close($spawn);
    socket_close($socket);
    ?>
    

     

  7. Is there any way to keep a socket server alive? I have a socket server that runs fine, and does what I need it to... but when I close the window that has the socket server in it, it stops the server.

     

    How can I prevent this from happening?

  8. I'm not sure if it is the fault of imagejpeg though.

     

    This is my upload code:

     

    <?php
    define('MAX_FILE_SIZE', 9000);
    require_once("TextToImage.class.php");
    $img = new TextToImage();
    
    $target_path = $_SERVER['DOCUMENT_ROOT']."wordpress2-8/wp-content/uploads/";
    $topx = $_POST['xtopalignment'];
    
    $title = $_POST['titletext'];
    
    $target_path = $target_path . basename( $_FILES['file']['name']);
    $img->im = $_FILES['file']['name'];
    
    if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['file']['name']). 
        " has been uploaded";
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    //echo "Image: <img src=imagedisplay.php?text=" . $_POST[titletext] ."&file=".$_FILES["file"]["name"]. "&x=" . $topx . "&y=" . $topy ." border=0 />";
    echo $img->imagettfJustifytext($title, "arial.ttf", $topx);
    print_r($img->showAsJpg());
    imagedestroy($target_path);
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
    ?>

     

    This is the image creation code:

     

    <?php
    /**
    * Class for converting Text to Image.
    * Left Right Center align/justify of text in image.
    * Create an image from text and align them as you want.
    * @author Taslim Mazumder Sohel
    * @deprecated 1.0 - 2007/07/25
    * 
    */
    
    class TextToImage {
    
    var $im;
        private $L_R_C;
        
        /**
         * @name 				   : makeImageF
         * 
         * Function for create image from text with selected font.
         * 
         * @param String $text     : String to convert into the Image.
         * @param String $font     : Font name of the text. Kip font file in same folder.
         * @param int    $W        : Width of the Image.
         * @param int    $H        : Hight of the Image.
         * @param int	 $X        : x-coordinate of the text into the image.
         * @param int    $Y        : y-coordinate of the text into the image.
         * @param int    $fsize    : Font size of text.
         * @param array  $color	   : RGB color array for text color.
         * @param array  $bgcolor  : RGB color array for background.
         * 
         */
        public function imagettfJustifytext($text, $font="CENTURY.TTF", $Justify=2, $W=0, $H=0, $X=0, $Y=0, $fsize=12, $color=array(0x0,0x0,0x0), $bgcolor=array(0xFF,0xFF,0xFF)){
        	
        	$angle = 0;
        	$this->L_R_C = $Justify; 
        	$_bx = imageTTFBbox($fsize,0,$font,$text);
    
    	$W = ($W==0)?abs($_bx[2]-$_bx[0]):$W;	//If Height not initialized by programmer then it will detect and assign perfect height. 
    	$H = ($H==0)?abs($_bx[5]-$_bx[3]):$H;	//If Width not initialized by programmer then it will detect and assign perfect width. 
    
        	$this->im = @imagecreate($W, $H)
    	    or die("Cannot Initialize new GD image stream");
    	    
    	    
    	$background_color = imagecolorallocate($this->im, $bgcolor[0], $bgcolor[1], $bgcolor[2]);		//RGB color background.
    	$text_color = imagecolorallocate($this->im, $color[0], $color[1], $color[2]);			//RGB color text.
    
    	if($this->L_R_C == 0){ //Justify Left
    
    		imagettftext($this->im, $fsize, $angle, $X, $fsize, $text_color, $font, $text);
    
    	}elseif($this->L_R_C == 1){ //Justify Right
    		$s = split("[\n]+", $text);
        		$__H=0;
        		
        		foreach($s as $key=>$val){
        		
        			$_b = imageTTFBbox($fsize,0,$font,$val);
        			$_W = abs($_b[2]-$_b[0]); 
        			//Defining the X coordinate.
        			$_X = $W-$_W;
    			//Defining the Y coordinate.
    			$_H = abs($_b[5]-$_b[3]);  
    			$__H += $_H;  			
        			imagettftext($this->im, $fsize, $angle, $_X, $__H, $text_color, $font, $val);	
        			$__H += 6;
        			
        		}
        		
    	}
    	elseif($this->L_R_C == 2){ //Justify Center
        		
        		$s = split("[\n]+", $text);
        		$__H=0;
        		
        		foreach($s as $key=>$val){
        		
        			$_b = imageTTFBbox($fsize,0,$font,$val);
        			$_W = abs($_b[2]-$_b[0]); 
        			//Defining the X coordinate.
        			$_X = abs($W/2)-abs($_W/2);
    			//Defining the Y coordinate.
    			$_H = abs($_b[5]-$_b[3]);  
    			$__H += $_H;  			
        			imagettftext($this->im, $fsize, $angle, $_X, $__H, $text_color, $font, $val);	
        			$__H += 6;
        			
        		}
        		
        	}		
    
        }
        	
        /**
         * @name showAsPng
         * 
         * Function to show text as Png image.
         *  
         */ 
        public function showAsPng(){
    
    	header("Content-type: image/png");				
    	return imagepng($this->im);		
    }
        
        /**
         * @name saveAsPng
         * 
         * Function to save text as Png image.
         *  
         * @param String $filename 		: File name to save as.
         * @param String $location 		: Location to save image file.
         */ 
        public function saveAsPng($fileName, $location= null){		
    
    	$_fileName = $fileName.".png";
    	$_fileName = is_null($location)?$_fileName:$location.$_fileName;
    	return imagepng($this->im, $_fileName);		
    }
        
        /**
         * @name showAsJpg
         * 
         * Function to show text as JPG image.
         *  
         */ 
        public function showAsJpg(){
    
    	header("Content-type: image/jpeg");				
    	return imagejpeg($this->im);		
    }
        
        /**
         * @name saveAsJpg
         * 
         * Function to save text as JPG image.
         *   
         * @param String $filename 		: File name to save as.
         * @param String $location 		: Location to save image file.
         */ 
        public function saveAsJpg($fileName, $location= null){		
    
    	$_fileName = $fileName.".jpg";
    	$_fileName = is_null($location)?$_fileName:$location.$_fileName;
    	return imagejpeg($this->im, $_fileName);
    }
    
    /**
         * @name showAsGif
         * 
         * Function to show text as GIF image.
         *  
         */ 
    public function showAsGif(){
    
    	header("Content-type: image/gif");				
    	return imagegif($this->im);
    }
        
        /**
         * @name saveAsGif
         * 
         * Function to save text as GIF image.
         *   
         * @param String $filename 		: File name to save as.
         * @param String $location 		: Location to save image file.
         */ 
        public function saveAsGif($fileName, $location= null){		
    
    	$_fileName = $fileName.".gif";
    	$_fileName = is_null($location)?$_fileName:$location.$_fileName;
    	return imagegif($this->im, $_fileName);
    }
    
    }
    ?>
    

     

    I don't expect you to go through the image creation class, but I am trying to use showAsJpg() and the imagettfJustifytext() function because it has the alignment built in to it.

     

    The problem is, whatever is going on (the uploading of a file works) but it always outputs

     

    and I'm not sure why.

  9. Does anyone know the equation to find out how to center text that you will write in PHP?

     

    So if I have an image that is always around 270 x 400 and 290x400 what would I do for math equations for centering it near the top and near the bottom of the image?

     

    Also, I found this class: http://www.phpclasses.org/browse/file/20034.html

     

    Does anyone know any other classes that would do more like writing text effects in PHP GD? Like shadow effect, strike through the text effect, etc. etc.?

  10. I think I copied it from W3schools and edited it a bit to do what I need, where is the best and cleanest uploader do you think? Also, is it possible to do the image(insert file format here) function on the same page?

     

    Right now I need to use two php files, one for the image upload and one to display the image and write the text.

  11. I'm trying this Image uploader:

     

    <?php
    $target_path = $_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/";
    $topx = $_POST['topxstart'];
    $topy = $_POST['topystart'];
    $target_path = $target_path . basename( $_FILES['file']['name']); 
    $target_pathoriginal = $_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/" . basename( $_FILES['file']['name'] . 'original');
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 20000))
      {
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    echo "Image: <img src=imagedisplay.php?text=" . $_POST[titletext] ."&file=".$_FILES["file"]["name"]. "&x=" . $topx . "&y=" . $topy ." border=0 />";
        if (file_exists($_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        elseif (file_exists($_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/" . $_FILES["file"]["name"]. 'original'))
          {
      echo $_FILES["file"]["name"] . " already exists. ";
    } else {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          $target_path);
            move_uploaded_file($_FILES["file"]["tmp_name"],
          $target_pathoriginal);
          echo "Stored in: " . file_exists($_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/" . $_FILES["file"]["name"]);
          }
        }
      }
    else
      {
      echo "Invalid file";
      }
      ?>
    

     

    Some JPEG images I upload make the code output Invalid file. I'm not sure why it's invalid since the type of image is JPEG, 37 KB, 400 x 491 dimention. Any ideas why it would be invalid?

     

    Also, do you know of any class that would help with writing titles and captions on images and save the image to a path?

  12. Thanks for the reply, but it still doesn't work:

     

    <?php
    header ('Content-type: image/jpeg');
      $imag = $_GET['file'];
      $path = $_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/" . $imag;
      $im = imagecreatefromjpeg($path);
      $cor = imagecolorallocate($im, 0, 0, 0);
      $white = imagecolorallocate($im, 255, 255, 255);
      $text = $_GET['text'];
      $font = 'arial.ttf';
      imagettftext($im, 18, 0, 10, 5, $cor, $font, $text);
      imagejpeg($im);
    ?>

  13. Ok,

     

    so I have a php file that creates the image. In that file, I have it calling a script that is supposed to write text on the image, but that script that is supposed to write text on the image doesn't work.

     

    This is what gets outputted in the browser:

     

    Here is the code:

    <?php
      $imag = $_GET['file'];
      $path = $_SERVER['DOCUMENT_ROOT']."wp-2.7/wp-content/uploads/" . $imag;
      $im = imagecreatefromjpeg($path);
      $cor = imagecolorallocate($im, 0, 0, 0);
      $white = imagecolorallocate($im, 255, 255, 255);
      $text = $_GET['text'];
      header ('Content-type: image/jpeg');
      imagettftext($im, 18, 0, 10, 5, $cor, 'Arial', $text);
      imagejpeg($im);
    ?>

     

    Any idea what I'm doing wrong? I want to have text on the top of the image and on the bottom. I just need to know how to do this correctly though and I will figure out the positioning part.

  14. I converted this theme in to a wordpress theme. The theme works fine in FF but in IE 7 the navigation bar is black instead of red.

     

    http://carlwuensche.com/redtiger

     

    View it in IE 7 and FF to see the difference. I'm not a css expert and I didn't do this theme, can anyone give me any ideas on why it is having this conflict?

     

    Thanks!

  15. Can anyone help me find out how to check if a twitter username/password is correct upon form submit. I have code to do that in PHP already, but if the user/pass combo is incorrect I want the form to stay where it is so the user can correct the info instead of reloading the page.

     

    This is the code

    function followUser()
       {
    $apiUrl='http://twitter.com/friendships/create/'.$this->follower.'.xml';
    $curl_handle = curl_init();
    curl_setopt($curl_handle, CURLOPT_URL, "$apiUrl");
    curl_setopt($curl_handle, CURLOPT_POST, 1);
    curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username.':'.$this->password);
    //Attempt to send
    $buffer = curl_exec($curl_handle);
    $resultArray = curl_getinfo($buffer);
    
    if ($resultArray['http_code'] == 200):
    return true;
    else:
    return false;
    endif;
    curl_close($curl_handle);
    
    }   
    

     

    Any help with this would 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.