|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general-digest-help
lists.php.net
Date: Tue Oct 02 2007 - 08:34:23 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 2 Oct 2007 13:34:23 -0000 Issue 5050
Topics (messages 262629 through 262636):
multiple curl and web service
262629 by: H u g o H i r a m
Re: an apology
262630 by: Robert Cummings
262636 by: Daniel Brown
I need an opion!!! Thanks!
262631 by: Sebastian Dieser
262633 by: Chris
Re: counting with leading zeros
262632 by: Martin Alterisio
Re: languages and PHP
262634 by: Colin Guthrie
262635 by: Per Jessen
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
Hi,
I am having this problem, I am retrieving some data from a MySQL DB, and
using it to post a cURL, what I am calling is a web service, and I have
3 options to do it: SOAP, GET and POST, I am not very familiar with
SOAP, so I am using POST, in response I get a XML on each call to the
web service.
If I call only one curl and web service each time, then everything works
just perfect, but if I try to make multiple calls then I get weird
results, I get some responses OK (an XML), but others are empty responses.
The first three responses are always empty, I don't get any errors,
instead only those empty responses (no XML).
Ok, I'm posting the code right here:
$sql_aero = "SELECT
code
FROM
airports
ORDER BY
id ASC
limit 0, 10";
$result_aero = mysql_query($sql_aero);
$num_results_aero = mysql_num_rows($result_aero);
if (!empty($num_results_aero)) {
$i = 0;
$mh = curl_multi_init();
while($row_aero = mysql_fetch_array($result_aero)) {
$aero = $row_aero["code"];
$ws =
"www.webservicex.com/airport.asmx/getAirportInformationByAirportCode";
$post = "airportCode=$aero";
print "$i = $aero, $post<br>";
$conn[$i] = curl_init($ws);
curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($conn[$i], CURLOPT_POSTFIELDS, $post);
curl_multi_add_handle ($mh, $conn[$i]);
$i++;
}
}
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
for ($j=0; $j<$i; $j++) {
if (($err = curl_error($conn[$j])) == '') {
$res[$j] = curl_multi_getcontent($conn[$j]);
print "$j<br>$newstr[$j]";
}
else {
print "Curl error on handle $j: $err\n";
}
curl_multi_remove_handle($mh, $conn[$j]);
curl_close($conn[$j]);
}
curl_multi_close($mh);
As you won't have the DB, if want to try the code, use this array with
the proper change to the code:
$airports = ['LAX', 'ATL', 'JFK', 'SAN', 'CDG', 'MAD', 'BCN', 'GDL',
'TIJ', 'SYD'];
I am working on Localhost: Windows, Apache 2.2.3, PHP 5.1.6 and MySQL 5.0.24
here's the original code:
http://www.php.net/manual/en/function.curl-multi-exec.php
Regards!
hugo Hiram.
---
attached mail follows:
On Mon, 2007-10-01 at 19:44 -0400, brian wrote:
> List,
>
> I apologise for dragging that crap out for all to see. Unfortunately,
> the piling on was bothering me a great deal and i dealt with it badly.
> (Juvenile comments about "cock size" excepted, Jack. I'm not at all
> insecure about that. Thanks for the concern, though.)
>
> I feel that my responses here have been completely misunderstood and it
> simply irritates me to no end. But that's no excuse for dragging this
> crap out here. FWIW, i *did* try to take this off-list but a very public
> brawl seemed to be the desired course. That's not what i wanted.
>
> Having said that, i can't simply let it drop without sending this out to
> everyone who has witnessed this car wreck. I also apologise for the
> language i've used. It was innapropriate for a public list.
>
> No, i was *not* hoping anyone would jump in to save me. My one and only
> goal was to clarify my point to those who (i felt) had twisted my
> comments completely out of context. Sorry, but i *really* hate that.
>
> Rob, i still don't feel that my initial reply deserves an apology. An
> explanation, a clarification, for sure. But i thought that my later
> posts explained clearly enough that that was not my intent at all. I
> think that your refusal to accept my explanation has been unfortunate,
> to say the least.
Ummm, I'm not looking for an apology. Whatever gave you that impression.
I thought this thread had already died. Time to move on already.
> Email lists (like blogs, IRC, and the like) lend themselves to creating
> just these sorts of misunderstandings. We should all be aware of this
> and take responsibility for ensuring that any ill-communications are
> clarified. I thought i was doing so yet continued to receive abuse.
> Thus, i lashed out in turn.
>
> I will, though, apologise for calling you a dickhead. I should have
> ignored your barbs, however inappropriate and unfounded i felt they
> were. Out in meatspace, we'd likely get along very well.
Oh don't worry about me, I don't take much on the net personally. I sort
of see email quips along the lines of "your momma" jokes. Most of us
have pretty thick skin around here.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................
attached mail follows:
On 10/1/07, Robert Cummings <robert
interjinn.com> wrote:
> ....Most of us have pretty thick skin around here.
Yeah, especially Rob.
Wait.... skin or skull? Ah, well.... ;-P
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Give a man a fish, he'll eat for a day. Then you'll find out he was
allergic and is hospitalized. See? No good deed goes unpunished....
attached mail follows:
Hi, we have been using the following codes on our site for a year and I wanted to know if these codes are just spaghetti or its actual usable code. I know it can be bettered a lot I just need opinions if the codes can be used a while more until we reprogram everything as a complete CMS system.
Thanks a lot! my superiors want to know because there is another coder that says these codes are just spaghetti.
There is more codes but i am able to access the database fine and everything else. Of course the codes can be bettered but i dont believe its just spaghetti!!!!! I used these codes because there was no need to reinvent the wheel. I apreciate your help!
--------------------------------------------------
file name: SystemComponent.php
--------------------------------------------------
------------------------------------
file name: dbconnector.php
link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
register_shutdown_function(array(&$this, 'close'));
}
//*** Function: query, Purpose: Execute a database query ***
function query($query) {
$this->theQuery = $query;
return mysql_query($query, $this->link);
}
//*** Function: getQuery, Purpose: Returns the last database query, for debugging ***
function getQuery() {
return $this->theQuery;
}
//*** Function: getNumRows, Purpose: Return row count, MySQL version ***
function getNumRows($result){
return mysql_num_rows($result);
}
//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {
return mysql_fetch_array($result);
}
//*** Function: close, Purpose: Close the connection ***
function close() {
mysql_close($this->link);
}
}
?>
---------------------------------------------
File Name: Sentry.php
userdata);
session_destroy();
return true;
}
//======================================================================================
// Log in, and either redirect to goodRedirect or badRedirect depending on success
function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = ''){
// Include database and validation classes, and create objects
require_once('DbConnector.php');
require_once('Validator.php');
$validate = new Validator();
$loginConnector = new DbConnector();
// If user is already logged in then check credentials
if ($_SESSION['user'] && $_SESSION['pass']){
// Validate session data
if (!$validate->validateTextOnly($_SESSION['user'])){return false;}
if (!$validate->validateTextOnly($_SESSION['pass'])){return false;}
$getUser = $loginConnector->query("SELECT * FROM rusers WHERE user = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."' AND thegroup <= ".$group.' AND enabled = 1');
if ($loginConnector->getNumRows($getUser)> 0){
// Existing user ok, continue
if ($goodRedirect != '') {
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
}
return true;
}else{
// Existing user not ok, logout
$this->logout();
return false;
}
// User isn't logged in, check credentials
}else{
// Validate input
if (!$validate->validateTextOnly($user)){return false;}
if (!$validate->validateTextOnly($pass)){return false;}
// Look up user in DB
$getUser = $loginConnector->query("SELECT * FROM rusers WHERE user = '$user' AND pass = PASSWORD('$pass') AND thegroup <= $group AND enabled = 1");
$this->userdata = $loginConnector->fetchArray($getUser);
if ($loginConnector->getNumRows($getUser)> 0){
// Login OK, store session details
// Log in
$_SESSION["user"] = $user;
$_SESSION["pass"] = $this->userdata['pass'];
$_SESSION["thegroup"] = $this->userdata['thegroup'];
if ($goodRedirect) {
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
}
return true;
}else{
// Login BAD
unset($this->userdata);
if ($badRedirect) {
header("Location: ".$badRedirect) ;
}
return false;
}
}
}
}
?>
-----------------------------------------
filename: validator.php
errors[] = $description;
return false;
}
}
// Validate text only
function validateTextOnly($theinput,$description = ''){
$result = ereg ("^[A-Za-z0-9\ ]+$", $theinput );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}
}
// Validate text only, no spaces allowed
function validateTextOnlyNoSpaces($theinput,$description = ''){
$result = ereg ("^[A-Za-z0-9]+$", $theinput );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}
}
// Validate email address
function validateEmail($themail,$description = ''){
$result = ereg ("^[^
]+
[^
]+\.[^
\.]+$", $themail );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}
}
// Validate numbers only
function validateNumber($theinput,$description = ''){
if (is_numeric($theinput)) {
return true; // The value is numeric, return true
}else{
$this->errors[] = $description; // Value not numeric! Add error description to list of errors
return false; // Return false
}
}
// Validate date
function validateDate($thedate,$description = ''){
if (strtotime($thedate) === -1 || $thedate == '') {
$this->errors[] = $description;
return false;
}else{
return true;
}
}
// Check whether any errors have been found (i.e. validation has returned false)
// since the object was created
function foundErrors() {
if (count($this->errors)> 0){
return true;
}else{
return false;
}
}
// Return a string containing a list of errors found,
// Seperated by a given deliminator
function listErrors($delim = ' '){
return implode($delim,$this->errors);
}
// Manually add something to the list of errors
function addError($description){
$this->errors[] = $description;
}
}
?>
-------------------------------------------------
filename viewing.php
This is an example of viewing the information it works fine.
query('SELECT * FROM vendors WHERE ID = '.$HTTP_GET_VARS['id']);
// Get an array containing the resulting record
$row = $connector->fetchArray($result);
?>
No Photo!";
}
else {
$photo = $row['photo'];
echo '';
}?>
Address: '.$row['address']; ?>
Telephone: '.$row['tel']; ?>
Office: '.$row['office']; ?>
Email:
_________________________________________________________________
Connect to the next generation of MSN Messenger
http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
attached mail follows:
Sebastian Dieser wrote:
> Hi, we have been using the following codes on our site for a year and I wanted to know if these codes are just spaghetti or its actual usable code. I know it can be bettered a lot I just need opinions if the codes can be used a while more until we reprogram everything as a complete CMS system.
>
> Thanks a lot! my superiors want to know because there is another coder that says these codes are just spaghetti.
>
> There is more codes but i am able to access the database fine and everything else. Of course the codes can be bettered but i dont believe its just spaghetti!!!!! I used these codes because there was no need to reinvent the wheel. I apreciate your help!
I hope you have indenting in your code and it's just the email that came
through badly.
I wouldn't say it's spaghetti code but it could do with a clean-up.
--------
if ($loginConnector->getNumRows($getUser)> 0){
// Login OK, store session details
// Log in
$_SESSION["user"] = $user;
$_SESSION["pass"] = $this->userdata['pass'];
$_SESSION["thegroup"] = $this->userdata['thegroup'];
if ($goodRedirect) {
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
}
return true;
}else{
--------
If you're returning out of the function there why do you need an else?
PHP will automatically skip that block if it's not going to process that
code path.
--------
// If user is already logged in then check credentials
if ($_SESSION['user'] && $_SESSION['pass']){
--------
...
reverse that:
if (!isset($_SESSION['user']) || !isset($_SESSION['pass'])) {
return false;
}
You remove a huge if block which isn't needed.
--------
query('SELECT * FROM vendors WHERE ID = '.$HTTP_GET_VARS['id']);
--------
Go to this website and read everything you can find:
http://phpsec.org/projects/guide/
You have sql injection here that needs attention (and if it's here I'm
sure there could be other spots too).
Also HTTP_GET_VARS is old, change it to the newer $_GET['id'] syntax.
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
// glob returns an ordered list (rtfm: man glob)
// relies on the use of the operator ++ to generate string sequences.
function lastFileInSequence($path, $prefix, $first, $suffix) {
return array_pop(glob($path . "/" . $prefix . str_repeat('?',
strlen($first)) . $suffix));
}
function nextFileInSequence($path, $prefix, $first, $suffix) {
if ($lastFile = basename(lastFileInSequence($path, $prefix, $first,
$suffix), $suffix)) {
return ++$lastFile . $suffix;
} else {
return $prefix . $first . $suffix;
}
}
$nextImage = $path . "/" . nextFileInSequence($path, "foo_", "01", ".jpg");
2007/9/26, brian <phplist
subtropolix.org>:
>
> I have a directory that contains many images (no, not pr0n,
> unfortunately) and i'm working on an admin script for adding to it. I've
> got something that works alright but i'm wondering if there's a Better
> Way.
>
> Each image is named like: foo_01.jpg, foo_02.jpg, bar_01.jpg, and so on.
> When adding a new image it should be assigned the next number in the
> series (the prefix is known). Thus, given the prefix 'bar' i do
> something like:
>
> function getNextImage($path, $prefix)
> {
> $pattern = "/^${prefix}_([0-9]{2})\.[a-z]{3}$/";
>
> $filenames = glob("${path}${prefix}*");
>
> if (is_array($filenames) && sizeof($filenames))
> {
> sort($filenames);
>
> /* eg. 'foo_32.jpg'
> */
> $last = basename(array_pop($filenames));
>
> /* pull the number from the filename
> */
> $count = intval(preg_replace($pattern, '$1', $last));
>
> /* increment, format with leading zero again if necessary,
> * and return it
> */
> return sprintf('%02d', ++$count)
> }
> else
> {
> return '01';
> }
> }
>
> Note that there almost certainly will never be more than 99 images to a
> series. In any case, i don't care about there being more than one
> leading zero. One is what i want.
>
> brian
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
attached mail follows:
tedd wrote:
> Isn't UTF-8 the big fish here?
>
> Sure there' UTF-16 and larger, but everything else is a subset of UTF-8,
> is it not?
>
> So, what's the problem if you get a character defined by ISO -- it's
> still within the UTF-8 super-group, right?
Individual characters are sometimes OK, but it's the sequence of
characters that could be invalid.
UTF-8 works by using special bits at the MSB end of the byte to say, "I
can't represent this character in one byte, I need to use 2 bytes (or 3
bytes)" (and maybe also 4? can't remember of the top of my head).
In a multi-byte sequence the MSB end of all the bytes must follow a
pre-defined scheme. If they do not they are syntactically invalid UTF-8.
So it's more than just individual characters, the order of them is
important.
Hope that explains it (although probably a bad explanation as I'm very
tired right now!).
Col
attached mail follows:
Colin Guthrie wrote:
> UTF-8 works by using special bits at the MSB end of the byte to say,
> "I can't represent this character in one byte, I need to use 2 bytes
> (or 3 bytes)" (and maybe also 4? can't remember of the top of my
> head).
Yep, a UTF8 character is 1 to 4 bytes.
/Per Jessen, ZĂ¼rich
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]