PHP - Moved: Curl Tutorial
This topic has been moved to Miscellaneous.
http://www.phpfreaks.com/forums/index.php?topic=330907.0 Similar TutorialsThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=308352.0 This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=334310.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=351363.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=130332.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343600.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348851.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=334229.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=332907.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316360.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=351535.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321530.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342211.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=347977.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=343083.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=334867.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=334273.0 good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. I have a need to create a form that will get info from a mysql table, show that info, two fields one of which I want to be a checkbox that will need to update the table with either a 0 or a 1. I will later use that info. I have searched all over and haven't found what I am looking for. I can find tutorials for creating checkboxes but nothing what I need / want
Hello Php Freaks I am following this tutorial how to make a login for my website, the only trouble is that... It dosen't seem to work, so i wanna know if its only me who cant make it work... and if it is why XD... Tutorial can be found he http://www.knowledgesutra.com/forums/topic/7887-php-simple-login-tutorial/ Now when i get started it starts saying error at line 6: if ($_GET["op"] == "login") It says that when im about to login right above the login. Now when i put in data i get error on line 19: $r = mysql_query($q); That one, and i have no idea how to fix it. Anyone please ? I followed the tutorial at http://www.devshed.com/c/a/PHP/Building-An-Extensible-Form-Validator-Class/ because I wanted to have an easier way to build and maintain form validation. I completed the tutorial, but the form does not register the form as being filled out. Here is the class code (FormValidator.class.inc) <?php //FormValidator.class.inc //class to perform form validation class FormValidator { //---------------private variables------------------ var $_errorList; //the _ prefix is used to distinguish private variables from public variables //---------------methods (private)------------------ //functio to get the value of a variable (field) function _getValue($field) { global ${$field}; //makes the field entry a global variable return ${$field}; } //---------------methods (public)------------------- //it is a good idea to run resetErrorList() whenever the class is first initialized //PHP makes it possible to automatically execute a specific function when a new instance of a class is spawned. This function is referred to as a "constructor" and must have the same name as the class. //reset error list function FormValidator() { $this->resetErrorList(); } //begin basic validation routines //check whether input is empty //the isEmpty public method is called with 2 arguments, one for the form variable and one for the error message //the method internally calls the _getValue method and then trim()s the result to check if it is empty // if the variable is empty, a new element is added class variable $_errorList (an array) to represent the error. This new element is itself a three-element associative array, with the keys "field", "value" and "msg", representing the form variable name, the current value of that variable, and the corresponding error message // if the variable is not empty, it will pass the test and return true // this function, along with _getValue, allows the user to get both the field name and the field value //the $this prefix provides a convenient way to access variables and functions which are "local" to the class. function isEmpty($field, $msg) { $value = $this->_getValue($field); if (trim($value) == "") { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } else { return true; } } //check whether input is a string function isString($field, $msg) { $value = $this->_getValue($field); if(!is_string($value)) { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } else { return true; } } //check whether input is a number function isNumber($field, $msg) { $value = $this->_getValue($field); if(!is_numeric($value)) { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } else { return true; } } //check whether input is an integer function isInteger($field, $msg) { $value = $this->_getValue($field); if(!is_integer($value)) { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } else { return true; } } //check whether input is a float function isFloat($field, $msg) { $value = $this->_getValue($field); if(!is_float($value)) { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } else { return true; } } //check whether input is within a valid numeric range function isWithinRange($field, $msg, $min, $max) { $value = $this->_getValue($field); if(!is_numeric($value) || $value < $min || $value > $max) { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } else { return true; } } //check whether the input is alphanumeric function isAlpha($field, $msg) { $value = $this->_getValue($field); $pattern = "/^[a-zA-Z]+$/"; if (preg_match($pattern, $value)) { return true; } else { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } } //check whether input is a valid email address function isEmailAddress($field, $msg) { $value = $this->_getValue($field); $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/ "; if (preg_match($pattern, $value)) { return true; } else { $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg); return false; } } //end basic validation routines----- //return the list of current errors function getErrorList() { return $this->_errorList; } //check whether any errors have occured in validation //this method checks the size of the $_errorList array; if the size is greater than one, it implies that one or more errors have occured during validation //it returns a Boolean value function isError() { if(sizeof($this->_errorList) > 0) { return true; } else { return false; } } //reset the error list to a blank array function resetErrorList() { $this->_errorList = array(); } }//end FormValidator class ?> -------Here is the form (simpleform.html) <html> <head> <basefont face="Arial"> </head> <body> <form action="processor.php" method="POST"> <b>Name:</b> <br> <input type="text" name="name" size="15"> <p> <b>Age:</b> <br> <input type="text" name="age" size="2" maxlength="2"> <p> <b>Sex:</b> <br> <input type="Radio" name="sex" value="m">Male <input type="Radio" name="sex" value="f">Female <p> <b>Favourite sandwich type:</b> <br> <select name="stype"> <option value="">-select one-</option> <option value="1">Thin crust</option> <option value="2">Thick crust</option> <option value="3">Toasted</option> </select> <p> <b>Favourite sandwich filling:</b> <br> <input type="Checkbox" name="sfill[]" value="BLT">Bacon, lettuce tomato <input type="Checkbox" name="sfill[]" value="EC">Egg and cheese <input type="Checkbox" name="sfill[]" value="PBJ">Peanut butter and jelly <p> <input type="Submit" name="submit" value="Save"> </form> </body> </html> ------and here is processor.php <?php //include class include("FormValidator.class.inc"); // instantiate object $fv = new FormValidator(); //perform validation $fv->isEmpty("name", "Please enter a name"); $fv->isNumber("age", "Please enter a valid age"); $fv->isWithinRange("age", "Please enter an age within the numeric range 1-99", 1, 99); $fv->isEmpty("sex", "Please enter your sex"); $fv->isEmpty("stype", "Please select one of the listed sandwich types"); $fv->isEmpty("sfill", "Please select one or more of the listed sandwich fillings"); if($fv->isError()) { $errors = $fv->getErrorList(); echo "<b>The operation could not be performed because one or more error(s) occurred.</b> <p> Please resubmit the form after making the following changes:"; echo "<ul>"; foreach($errors as $e) { echo "<li>" . $e['msg'] . "</li>"; } echo "</ul>"; } else { //do something useful with the data echo "Data OK"; } ?> |