Jump to content

doni49

Members
  • Posts

    515
  • Joined

  • Last visited

Everything posted by doni49

  1. I'm trying to set up a captcha for my email contact page. GD IS enabled on my server.  The following was copy/pasted from PHPInfo(). [quote] gd GD Support enabled GD Version bundled (2.0.28 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.1.4 GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XPM Support enabled XBM Support enabled [/quote] The following is from my script file: [code] <?php //captcha.php $RandomStr = md5(microtime());// md5 to generate the random string $ResultStr = substr($RandomStr,0,5);//trim 5 digit $NewImage =imagecreatefromjpeg("/home2/donirela/includes/captcha/captcha.gif");//image create by existing image and as back ground $LineColor = imagecolorallocate($NewImage,233,239,239);//line color $TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image imagestring($NewImage, 5, 20, 10, $ResultStr, $TextColor);// Draw a random string horizontally $captcha_key = $ResultStr;// carry the data through session header("Content-type: image/gif");// out out the image imagejpeg($NewImage);//Output image to browser ?> [/code] I even went so far as to place an 'echo' statement in the captcha php file (the first line after [b]"<?php"[/b].  But the echo statement never happens and I don't get [b]ANY[/b] error messages. This is my attempt to show the image: [code] <img src="captcha.php"> [/code]
  2. On the page that displays "Johnny's" profile, you can have a line that checks to see if Johnny this is Johnny or a visitor. If it IS Johnny, echo a link to the browser that takes him to "editProfile".  Of course, "editProfile" would also check to see if it actually IS Johnny as well.
  3. NO you can't "raise a [b]letter[/b]".  But a raise a [b]variable[/b]--YES. $x = 2; $y = 4; $a = $y + $x;  //$a will equal 6 $a = $y * $x;  //$a will equal 8 $a = pow($x, 2); //$a will equal 4  ->  (2 squared) $a = pow($y, -2); //$a will equal 2 -> (square root of 4)
  4. Pedro, it may very well exist--but the server's having trouble FINDING it.  Is the file in the same directory? i.e. if the file containing the links is http://www.mydomain.com/myfile.html, then is gbook in the root of the site?
  5. BTW  Here's a link to the PP integration center.  Forums where all they do is discuss integrating PP into your site. https://www.paypal.com/IntegrationCenter/ic_pdnHome.html
  6. With each purchase, you send the purchase info to paypal.  The IPN sends back the info that you passed to paypal. This should include song number, title, artist etc.  Your IPN handling script can then add the transaction info to your database and/or send you an email message. Once you have the transaction data, you can handle it as you please.
  7. Access the variables and functions within the class using "->". Example: [code] //myClass.inc class myClass{   var $testVar;   function testFunc(){     return $this->testVar;   } } //test.php include("myClass.inc"); $mc = new myClass; $mc->testVar = "Hello there!"; echo $mc->testFunc();  //this will output "Hello there" to the screen [/code] Some further reading: [url=http://us3.php.net/class]http://us3.php.net/class[/url] [url=http://codewalkers.com/tutorials/54/1.html]http://codewalkers.com/tutorials/54/1.html[/url]
  8. Please start a new thread for this new topic.
  9. There are a couple of issues. 1) your function doesn't use the table name that you're passing to it--so you don't really need to pass it. 2) all variables created in the function are LOCAL to the function--meaning they can't be accessed from outside of the function.  You need to return any functions that you want to use. I haven't tested this--I've only taken your code and modified it to what I'm pretty sure it needs to be.  At the very least it'll get you started. [code] <?php function dblistvalues(){//  $inTable){ $db_name="db_name";// Database name $db_host="localhost"; $db_user="db_user"; $db_password="db_password"; //$table="$inTable"; // Table name  <==table isn't used in the function so I'm hiding it. $connection=mysql_connect($db_host,$db_user,$db_password) or die("I Couldn't connect"); $db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database"); return $db; } ?> [/code] Now we'll use the function. [code] <?php           $table = "orders";           $connection = dblistvalues();//set "connection" variable to the value returned by the function.           if($connection){                     $sql="select * from $table order by ID";                     $result=mysql_query($sql,$connection) or die(mysql_error());                     while($row=mysql_fetch_array($result)) {                     }           } ?> [/code]
  10. Been there done that.  No problem.
  11. I'm assuming that the code you've already posted really does what you want and I haven't checked. You said that the following does display all the values that you want to add up: [code]foreach( range(1, $tapes) as $number)  { $no = 'tape'.$number; echo $_GET[$no]; } [/code] Change that to: [code] $total = 0; foreach( range(1, $tapes) as $number)  { $no = 'tape'.$number; echo $_GET[$no]; $total += $_GET[$no];    //  <=this line basically says "take the variable 'total' and add the current number to it, changing the value of the total varialbe". } [/code]
  12. Can you explain what you're looking for a little more clearly?  And show any code you've tried--maybe that'll help me understand what you're after.
  13. OK.  I think I've got it.  I added the following methods:     Next     Previous     Current     IndexOf     sort     sortr I tried to post the code here, but the page just kept timing out.  I'm guessing there's a limit to the message size.  I think it could prove useful for more than just me so I'm gonna submit it for inclusion in the code library.  Does anyone know how to do that?  I thought there'd be some kind of "Submit Code" link in the code library area but I didn't see one.
  14. Ok, I just figured out WHY it wasn't working.  I wasn't appending the response value.  So once the while loop ended the response variable was empty.
  15. This is all that gets sent to the browser when I load this script (I did View Source): [code]Resource id #2<br>False[/code]
  16. I have a web hosting account with CPanel access.  I'm trying to create a script that will login to cpanel, perform certain actions and then read the output that CPanel creates as a result of my actions.  This script DOES perform the action that it's supposed to do but doesn't receive any of the output. I've got 2 debugging lines in the code (noted for reference below).  They indicate that Socket does have the resource value but response is empty. Thanks. [code] <?php $cpuser = "myUsername"; // Username used to login to CPanel $cppass = "myPassword"; // Password used to login to CPanel $domain = "mydomain.com"; // Domain name where CPanel is run $skin = "mySkin"; // Set to cPanel skin you use (script won't work if it doesn't match) // Info required for cPanel access if ($secure) {   $url = "ssl://".$domain;   $port = 2083; } else {   $url = $domain;   $port = 2082; } $socket = fsockopen($url,$port); if (!$socket) { echo "Failed to open socket connection... Bailing out!\n"; exit; } // Encode authentication string $authstr = $cpuser.":".$cppass; $pass = base64_encode($authstr); // Make POST to cPanel //The "URL" variable used below DOES get set properly--I've tested and confirmed that.  I just don't want to display that publicly. fputs($socket,$url . " HTTP/1.0\r\n"); fputs($socket,"Host: $domain\r\n"); fputs($socket,"Authorization: Basic $pass\r\n"); fputs($socket,"Connection: Close\r\n"); fputs($socket,"\r\n"); if($socket){echo $socket . "<br>";}//                <====== This line shows "Resource id #2" // Grab response even if we don't do anything with it. while (!feof($socket)) {   $response = fgets($socket,4096);   if ($debug) {echo $response;} } if($response){echo "True";}else{echo "False";}//      <====== This line shows False echo nl2br($response); fclose($socket); ?> [/code]
  17. I like the idea of next/prev & sort sounds do-able too.  But I'm not sure of the need for "get_items".  It seems to me that $obj_array = $cars->get_items() would do the same as $obj_array = $cars->items. Thanks for the input, anyone or anything else? This has been a great learning experience for me as I think I have a decent grasp on classes and objects as a result of this.  Eventually if this gets to be good enough, I figured that I'd submit it for the code library here.  But I think that's a bit down the road.
  18. ANYONE out there have any thoughts for improvements?
  19. I'd take it a step further and instead of using the for loop, use array_slice and implode--this should help speed it up a bit: [code] $text="all the words"; $text2=explode(" ", $text); //get the first 200 words $front = array_slice($text2, 0, 199); $part1 = implode(" ", $front); //get the remainder $back = array_slice($text2, 200); $part2 = implode(" ", $back); [/code] Of course this doesn't deal with cases where there is LESS than 200 words.  Also, it could split strings that you would NOT want spit for example a name.  What happens if "word" number 200 is Bill and "word" number 201 is Smith?  Is that going to be a problem? Hope this helps.
  20. I've been trying to get into using classes and objects.  I think I understand them fairly well and decided that I'd see if I could come up with a useful generic use class.  As I look at the power of classes and OOP, I can see the need for using lots of arrays of objects (a car dealership might use a class to define the cars in their inventory and they'd want to have an array of "Car" objects for example). So I decided to test myself.  I created a "Collection" class that includes methods to add, insert and remove items to and from the array.  I did this thinking that it would be a major PITA to have to write the code to do them every time.  Plus it was a great learning experience! I'd like to get the thoughts of those of you who've been using OOP/PHP for a while now and see if you can make any suggestions as to how this can be improved.  As well as are there any other properties/methods you think I should add?  A usage example follows below. Anyone care to critique it?  Thanks!  I've tested it in PHP 5.x (not sure of the sub-version). [code] class collection{ var $count=0; var $items = array(); private $type; function collection($type){ $this->type = $type; } private function buildObject($args, $index, $isIndex){ $newItem = "new " . $this->type ."("; if($isIndex AND count($args) > 0){ $args = array_slice($args,1); } //echo "<br />Index 2:  " . $index; if(count($args)>1){ $k = ""; $i = 1; foreach ($args as $a){ $k .= "'" . $a . "'"; if($i < count($args)){ $k .= ", "; } $i += 1; } $newItem = $newItem . $k; }elseif(count($args)== 1){ $newItem = $newItem . $args[0]; } if ($index < 0){$index = $this->count;} $newItem .= ");"; eval('$this->items[' . $index . '] = ' . $newItem); } function removeItem($index){ if ($index < 0){ die ('"Remove" Index must be positive.'); }elseif($index >= $this->count){ die('"Remove" Index must be less than the number of items.'); }else{ if ($index==0){ $this->items = array_slice($this->items, 1); }elseif (count($this->items) == $index){ $this->items = array_slice($this->items, 0, $index-1); }else{ $front = array_slice($this->items,0,$index - 1); $back = array_slice($this->items, $index + 1); $this->items = array_merge($front, $back); } $this->count = $this->count - 1; } } //add an item to the end of the "items" array. //all arguments are passed to the item's constructor if any. //all items are optional function addItem(){ $args = func_get_args(); if(count($args) > 0){ $this->buildObject($args,$this->count, FALSE); }else{ $this->buildObject(FALSE,$this->count, FALSE); } $this->count += 1; } //insert an item into the "items" array at the location specified by "index". //Index MUST be the first argument to the function.  All remaining arguments are //optional and will be passed to the item's constructor if any. function insertItem(){ $args = func_get_args(); $index = $args[0]; array_shift($args); if ($index < 0){ die ('"Insert" Index must be positive.'); }else{ if ($index < $this->count){ if($index > 0){ //if index is greater than zero but less than the //number of items in the "items" array, then //seperate items into two arrays and then rebuild //"items" array. $front = array_slice($this->items, 0, $index); $back = array_slice($this->items, $index); $this->items = array_merge($front,array(""),$back); }else{ //if index is equal to zero, then add space for the new item. $this->items = array_merge(array(""),$this->items); $index = 0; } }else{ //if index is equal to the number of items in the "items" array, //then put this new item at the end of the array. $index = $this->count; } $args = func_get_args(); if(count($args)> 0){ $this->buildObject($args, $index, TRUE); }else{ $this->buildObject(FALSE, $index, TRUE); } $this->count += 1; } } } [/code] Usage Example: [code] class car{   var model;   var make;   var color;   function car($make, $model, $color){     $this->model=$model;     $this->make=$make;     $this->color=$color;   } } $cars = new collection("car"); $cars->add("Chevrolet", "Blazer", "Green"); $cars->add("Ford","Mustang","Blue"); [/code]
  21. Thanks.  I kinda figured that.  But I wasn't sure if there was a better way to do it. I have one other Q about this.  Is there a limit to the amount of data that can be passed via session?  Either the session overall or the single session variable that contains this particular object.
  22. I DID do a search but a bunch of other junk came up.  I guess I'm not using a good search parameter, but I'm drawing a blank one what WOULD be a good search.  I'm trying to find out how to pass an object (a class that i created) from one page to another. Do I set a session variable equal the variable that the object is assigned to?  Will the whole object be available in the next page?  Is that the best way to do it or is there a better way (more efficient use of memory)? I've got a small example class below of course my REAL class will be much larger and more complicated which is why I'm asking about memory usage. [code] <?php class myClass{     var $test1=1;     var $test2=2;     var $test3;     function myClass(){         $this->test3 = $this->test1 + $this->test2;     } } $tstvar = new myClass; ?> [/code] I'm thinking that the following would make the entire object available on the next page, but I'm not sure it's the best use of memory.  Is there a better way of doing it? [code] $_SESSION['tstvar']=$tstvar; [/code] TIA!
  23. CPanel DOES have a way to backup the entire site--but it's not automated.  I was looking for some way to automate it because although my host DOES do backups, they're not as frequent as I'd like. I found the following script to activate CPanel's backup.  I now have a cron job set up that activates it for me.  So I expect to be able to take care of the FTP without a problem. [code] <?php // PHP script to allow periodic cPanel backups automatically. // Based on script posted by max.hedroom in cpanel.net forums //  This script contains passwords.  KEEP ACCESS TO THIS FILE SECURE! // ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED ********* // Info required for cPanel access $cpuser = "username"; // Username used to login to CPanel $cppass = "password"; // Password used to login to CPanel $domain = "example.com"; // Domain name where CPanel is run $skin = "monsoon"; // Set to cPanel skin you use (script won't work if it doesn't match) // Info required for FTP host $ftpuser = "ftpusername"; // Username for FTP account $ftppass = "ftppassword"; // Password for FTP account $ftphost = "ftp.example.com"; // Full hostname or IP address for FTP host $ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive) // Notification information $notifyemail = "[email protected]"; // Email address to send results // Secure or non-secure mode $secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP // Set to 1 to have web page result appear in your cron log $debug = 0; // *********** NO CONFIGURATION ITEMS BELOW THIS LINE ********* if ($secure) {   $url = "ssl://".$domain;   $port = 2083; } else {   $url = $domain;   $port = 2082; } $socket = fsockopen($url,$port); if (!$socket) { echo "Failed to open socket connection... Bailing out!\n"; exit; } // Encode authentication string $authstr = $cpuser.":".$cppass; $pass = base64_encode($authstr); $params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&submit=Generate Backup"; // Make POST to cPanel fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n"); fputs($socket,"Host: $domain\r\n"); fputs($socket,"Authorization: Basic $pass\r\n"); fputs($socket,"Connection: Close\r\n"); fputs($socket,"\r\n"); // Grab response even if we don't do anything with it. while (!feof($socket)) {   $response = fgets($socket,4096);   if ($debug) echo $response; } fclose($socket); ?> [/code]
  24. I'm not sure if this is it, but it IS something at least seems out of place. It says "For Win32 [b]only[/b]" and "For Unix [b]only[/b].  But neither line is commented out. Are you on Win32?  Or are you on Unix?  Are you using SMTP to send?  Or sendmail?  If using SMTP, have you specified your username and PW? Also, what does the code look like that you're using to send the message?  Maybe there's something wrong with THAT?
  25. Hello all, I have a web hosting account with CPanel access on a Linux/Apache server.  My server has PHP 5.x (not sure of the exact version at the moment--but if's imporatant, I'll go get it for you). I'd like to write a PHP script that will backup everything on my server as a windows zip file and transfer it via FTP to an off site location.  I want to backup my databases, email forwarders (I don't have any pop accounts set up), email auto-responders, etc--ALL settings/data/files. Can someone point me in the right direction?  Either to an existing script that will help me get started or at least help me figure out how to make sure I get the right files.  I've read articles on writing zip files and I've seen articles on FTP transfer.  But I'm unsure what files I should back up--if I need to restore settings, can I just overwrite the old files? Thanks.
×
×
  • 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.