Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe

Sab669 posted:

Interesting, thanks for the resource. I'm actually in class right now and these computers don't have a way to handle .gz files :( So I'll look at it when I get home, I suppose.

edit; just loaded up my virtual machine which has 7zip and I'm trying it from there. Definitely seems to be a problem with my host and not any of the code, as r1ch's says "Internal error, unable to move uploaded file. Please check permissions and disk space."

I do have read/write permissions on the tmp folder. bah. this is makin' me mad.

What are the permissions on the images folder? It seems like this is where it is having the issue.

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Both tmp and images have full read/write/execute privileges.

blargle
Apr 3, 2007
I'm a Java guy, so please bear with me. How do I get php to return the full aliased column name in a result set? I've got a large query with multiple joins, and each table in the join has a column named "id". Each "id" is aliased in the query as a.id, b.id, c.id, but $result->fetch_assoc only returns "id" instead of "a.id", "b.id", "c.id". It's stripping the table name off the columns, and since fetch_assoc returns a hashmap, I only get the last value.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

blargle posted:

I'm a Java guy, so please bear with me. How do I get php to return the full aliased column name in a result set? I've got a large query with multiple joins, and each table in the join has a column named "id". Each "id" is aliased in the query as a.id, b.id, c.id, but $result->fetch_assoc only returns "id" instead of "a.id", "b.id", "c.id". It's stripping the table name off the columns, and since fetch_assoc returns a hashmap, I only get the last value.

Is it possible to revise the query to alias all of these? Or, if the order is set, you can use mysql_fetch_array() or mysql_fetch_row() instead and use the numeric indices.

blargle
Apr 3, 2007
I'm not sure what you mean by "alias all of these", isn't that what I'm already doing (a.id, b.id, c.id)?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

blargle posted:

I'm not sure what you mean by "alias all of these", isn't that what I'm already doing (a.id, b.id, c.id)?

No, more like ... 'SELECT a.id AS a_id, b.id AS b_id, c.id AS c_id'.

Sab669
Sep 24, 2009

So I ticketted the support team for my hosting company about the apparent permission issue.

quote:

What's the location of the script? Also, are you mixing up paths? The /var/www/html that you see via FTP or the File Manager is not the same path PHP sees. You would want to prepend $_SERVER['SITE_ROOT'] per this article[1].

I'm not sure how stupid this mistake was on my part, but either way I'm just happy it's fixed.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

What's a safe way to detect if a file is an MP3?

McGlockenshire
Dec 16, 2005

GOLLOCKS!
If you're on a Unix, you can shell out to the "file" command and parse the result. Calling "file -b foo.mp3" should result in something like "Audio file with ID3 version 23.0 tag, MP3 encoding". "file -bi foo.mp3" should result in the MIME type "audio/mpeg"

Impotence
Nov 8, 2010
Lipstick Apathy
http://de3.php.net/manual/en/function.finfo-file.php

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

McGlockenshire posted:

If you're on a Unix, you can shell out to the "file" command and parse the result. Calling "file -b foo.mp3" should result in something like "Audio file with ID3 version 23.0 tag, MP3 encoding". "file -bi foo.mp3" should result in the MIME type "audio/mpeg"

Thanks, that sounds reasonable.

This doesn't seem safe:

php:
<?
$file_sanitized = escapeshellarg($file);

echo exec("file -bi $file_sanitized");
?>
Ideas?


Thanks for this too, next time I recompile PHP I'll consider adding this module.

Acer Pilot fucked around with this message at 23:20 on Sep 20, 2011

McGlockenshire
Dec 16, 2005

GOLLOCKS!

quote:

This doesn't seem safe:
php:
<?
$file_sanitized = escapeshellarg($file);

echo exec("file -bi $file_sanitized");?>
It depends. If you control the filename, then it's totally safe. If the user controls the filename, as long as you've either filtered out non-alphanumerics or are also using escapeshellcmd, then you should be OK.

Optimus Prime Ribs
Jul 25, 2007

Will doing something like this ever cause any issues:

php:
<?php
function foo()
{
    echo 'hello world';
}

function bar($param)
{
    echo 'you passed: '.$param;
}

$fooFunc foo;
$barFunc bar;

$fooFunc(42);
$barFunc(1234);
?>
Even though the function for $fooFunc does not take a parameter no errors or warnings are thrown (even if I explicitly call the function).
I'm asking because I have a function reference which sometimes will take a variable and sometimes won't.

So should I just pass variables and not worry, or should I do a check to make sure parameters are only passed to functions which are defined to take one?

Yay
Aug 4, 2007

Optimus Prime Ribs posted:

I'm asking because I have a function reference which sometimes will take a variable and sometimes won't.

So should I just pass variables and not worry, or should I do a check to make sure parameters are only passed to functions which are defined to take one?

Well, PHP supports default argument values, so you can have both:

php:
<?
function foo($bar=null) {
    if ($bar !== null) {
        return $bar;
    }
}?>
You could also do:
php:
<?
function bar() {
    if (func_num_args() > 0) {
        $args = func_get_args();
    }
}?>
This latter method demonstrates why your original code won't throw errors (though it may throw warnings/notices; I really can't remember)

Yay fucked around with this message at 20:20 on Sep 21, 2011

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Yay posted:

This latter method demonstrates why your original code won't throw errors (though it may throw warnings/notices; I really can't remember)

php:
<?
function foo() {}
function bar($baz) {}

foo('bar');  // No errors
bar();       // Throws a "missing argument" warning (in 5.3, at least)
?>

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Optimus Prime Ribs posted:

Will doing something like this ever cause any issues:
[snip]
Even though the function for $fooFunc does not take a parameter no errors or warnings are thrown (even if I explicitly call the function).
You don't have your error reporting level turned up high enough. Try error_reporting(-1); ini_set('display_errors', true);.

You'll see two warnings, one for the assignment of $fooFunc and another for the assignment of $barFunc. You should also see a warning to the call to bar with no params, as DaTroof pointed out.

Optimus Prime Ribs
Jul 25, 2007

Yay posted:

Well, PHP supports default argument values, so you can have both:

php:
<?
function foo($bar=null) {
    if ($bar !== null) {
        return $bar;
    }
}?>

Oh, I know I could do that. Just seemed redundant since some functions won't ever use the passed parameter.

McGlockenshire posted:

You don't have your error reporting level turned up high enough. Try error_reporting(-1); ini_set('display_errors', true);.

You'll see two warnings, one for the assignment of $fooFunc and another for the assignment of $barFunc. You should also see a warning to the call to bar with no params, as DaTroof pointed out.

I had a feeling that might have been the issue.
I'll go ahead and implement a check so that it doesn't happen anymore.

Thanks. :)

e:

Missed something in your post.
Is it not possible to create a reference to a function in PHP?

Optimus Prime Ribs fucked around with this message at 20:52 on Sep 21, 2011

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Optimus Prime Ribs posted:

Is it not possible to create a reference to a function in PHP?

Yes, but the variable needs to be a string representation of the function name:

php:
<?
$fooFunc = 'foo';
$barFunc = 'bar';
?>
Your version throws notices because foo and bar are undefined constants. PHP treats them as strings after reporting the errors.

Optimus Prime Ribs
Jul 25, 2007

DaTroof posted:

Yes, but the variable needs to be a string representation of the function name:

php:
<?
$fooFunc = 'foo';
$barFunc = 'bar';
?>
Your version throws notices because foo and bar are undefined constants. PHP treats them as strings after reporting the errors.

All right, that makes sense.
Would that mean that the code 'foo'() will call the function "foo"?

(not that I would ever need to do that; just making sure I understand)

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Optimus Prime Ribs posted:

All right, that makes sense.
Would that mean that the code 'foo'() will call the function "foo"?

(not that I would ever need to do that; just making sure I understand)

Hahaha, I wouldn't have been surprised if that worked, but apparently it doesn't. The string has to be in a variable, not a literal or a constant.

Optimus Prime Ribs
Jul 25, 2007

DaTroof posted:

Hahaha, I wouldn't have been surprised if that worked, but apparently it doesn't. The string has to be in a variable, not a literal or a constant.

PHP never stops being fun. :downs:

Thanks though.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
n/m, someone said that already

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

McGlockenshire posted:

It depends. If you control the filename, then it's totally safe. If the user controls the filename, as long as you've either filtered out non-alphanumerics or are also using escapeshellcmd, then you should be OK.

Thanks, this is what I'm using right now. I control the filename but you never know.

php:
<?
$file_sanitized = escapeshellarg($file);
$file_type = exec(escapeshellcmd("file -bi $file_sanitized"));
?>
Anybody have any other ideas to make this "safer?"

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

drcru posted:

Thanks, this is what I'm using right now. I control the filename but you never know.

php:
<?
$file_sanitized = escapeshellarg($file);
$file_type = exec(escapeshellcmd("file -bi $file_sanitized"));
?>
Anybody have any other ideas to make this "safer?"

I dunno if it needs to be safer, but if you want it to be more secure you can only allow certain characters in the file name and maybe a single period with a 3 digit extension. Then you can write a regular expression to test for this and fail if it doesn't conform to your rules.

Sticky Profits
Aug 12, 2011
What's the general consensus on DataMapper ORM for CodeIgniter? For one of the projects I'm working on I've ended up building my own ORM library for CI that's more lightweight and (I hope) more intuitive. Would it be worth releasing it to the general community or are people pretty happy with DataMapper?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I need curl help. Trying to navigate this website: http://iowahospitalcharges.com/Web/InpatientServices.aspx

It gets the cities automatically, and I am trying to get the Facilities dropdown to work. I'm using the following code (starting with Carroll as an example)

php:
<?
    // Initialize the CURL variables
    $rCurl = curl_init();
    $aPost = array('category' => 'Company', 'knownCategoryValues' => 'City:Carroll;');
    $sCookieFile = '/tmp/php_files/foo';
    @unlink($sCookieFile);

    // Get the info
    curl_setopt($rCurl, CURLOPT_POST, TRUE);
    curl_setopt($rCurl, CURLOPT_POSTFIELDS, $aPost);  
    curl_setopt($rCurl, CURLOPT_URL, 'http://iowahospitalcharges.com/WebService.asmx/GetFacilitiesForCity');
    curl_setopt($rCurl, CURLOPT_REFERER, 'http://iowahospitalcharges.com/Web/InpatientServices.aspx');
    curl_setopt($rCurl, CURLOPT_COOKIEFILE, $sCookieFile);
    curl_setopt($rCurl, CURLOPT_COOKIEJAR, $sCookieFile);
    curl_setopt($rCurl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:7.0) Gecko/20100101 Firefox/7.0');
    $sCurl = curl_exec($rCurl);
    curl_close($rCurl);
    echo $sCurl;
?>
And all I get is the error screen you get if you go to http://iowahospitalcharges.com/WebService.asmx/GetFacilitiesForCity directly. Why does this work when a browser makes the call but not curl? It's not relying on cookies, because I turned off cookies in the browser and it still worked. I think. I've duplicated everything I can from looking at Firebug's headers and I still get the error screen. Any ideas?

This is on PHP 5.1.6. (Though we may finally be getting 5.3 soon! :dance:)

Null Set
Nov 5, 2007

the dog represents disdain

Golbez posted:

curl stuff

Correct me if I'm wrong, but that's a web service. You should be able to make calls to the service using the PHP SoapClient class with http://iowahospitalcharges.com/WebService.asmx?WSDL as your wsdl. Should be much more reliable than curl (and easier).

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Null Set posted:

Correct me if I'm wrong, but that's a web service. You should be able to make calls to the service using the PHP SoapClient class with http://iowahospitalcharges.com/WebService.asmx?WSDL as your wsdl. Should be much more reliable than curl (and easier).

Looks promising, thanks, I'll try it tomorrow. But, still, shouldn't I be able to replicate the browser's POST call in curl?

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Some sites built using older ASP.NET techniques use Javascript page state postbacks and a horrible abomination of client and server-side session keeping. This can make it very difficult to automate access to them.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

McGlockenshire posted:

Some sites built using older ASP.NET techniques use Javascript page state postbacks and a horrible abomination of client and server-side session keeping. This can make it very difficult to automate access to them.

I turned off cookies and it still seemed to work... hm. And yeah, just looking at the Javascript, it's *way* too complex for what's going on here. You don't need to load five different scripts for a simple dropdown tree.

Golbez fucked around with this message at 14:30 on Sep 29, 2011

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

Golbez posted:

I turned off cookies and it still seemed to work... hm. And yeah, just looking at the Javascript, it's *way* too complex for what's going on here. You don't need to load five different scripts for a simple dropdown tree.

edit: eep, seems for some reason soap isn't compiled in? And it's not in yum? why RHEL, why

I have to do this poo poo all the time because some of our vendors can't be bothered to get a SOAP interface set up. There are a couple of extensions that firefox has to make your life easier. First get NoScript and visit the page to see if it works without javascript. You'll also want to install liveHTTPHeaders. Turn on capture in liveHTTPHeaders and then either post to the page normally (no javascript) or make it fire whatever AJAX call it does on the page that brings up the data you want.

In this case, the facilities appear to be returned by an AJAX call to
http://iowahospitalcharges.com/WebService.asmx/GetFacilitiesForCity

with what looks like JSON data being passed?
{"knownCategoryValues":"City:Carroll;","category":"Company"}
After you're sending it the right data, you just have to parse what you get back.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Doctor rear end in a top hat posted:

I have to do this poo poo all the time because some of our vendors can't be bothered to get a SOAP interface set up. There are a couple of extensions that firefox has to make your life easier. First get NoScript and visit the page to see if it works without javascript. You'll also want to install liveHTTPHeaders. Turn on capture in liveHTTPHeaders and then either post to the page normally (no javascript) or make it fire whatever AJAX call it does on the page that brings up the data you want.

In this case, the facilities appear to be returned by an AJAX call to
http://iowahospitalcharges.com/WebService.asmx/GetFacilitiesForCity

with what looks like JSON data being passed?
{"knownCategoryValues":"City:Carroll;","category":"Company"}
After you're sending it the right data, you just have to parse what you get back.

You managed to quote me before I took that out; php-soap was there, but only showing up in sudo yum. :)

And I was using Firebug to find out that data, and trying to use curl to send it back, I thought. But all I get is the error screen. Maybe the problem is that I'm sending each variable in a POST instead of one JSON object. Either way, SOAP appears to be the way to go on this.

Edit: Soap's been working, I managed to get the facility list... and then the site went down, only showing the error message. Surely it's not because of me? :ohdear:

Golbez fucked around with this message at 15:46 on Sep 29, 2011

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
It came back up... and then it dropped again while I was testing things. Could it be that PHP is clogging their connection pool? Is there any way to get around that? I'm even throttling the connections with sleep(5) after each one.

Null Set
Nov 5, 2007

the dog represents disdain

Golbez posted:

It came back up... and then it dropped again while I was testing things. Could it be that PHP is clogging their connection pool? Is there any way to get around that? I'm even throttling the connections with sleep(5) after each one.

Can you post your code? How many requests are you sending at once?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Null Set posted:

Can you post your code? How many requests are you sending at once?

One. I think. I have one $oSoap = new SoapClient($wsdl) and I simply reuse that variable.

Null Set
Nov 5, 2007

the dog represents disdain

Golbez posted:

One. I think. I have one $oSoap = new SoapClient($wsdl) and I simply reuse that variable.

That line retrieves the WSDL (the web service definition xml file). How are you actually sending your requests for data to the remote service?

Should be something like $oSoap->butts(array($key1=>$value1));

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Null Set posted:

That line retrieves the WSDL (the web service definition xml file). How are you actually sending your requests for data to the remote service?

Should be something like $oSoap->butts(array($key1=>$value1));

Right. $oCities = $oSoap->GetCities($oSearch), then foreaching that to get each facility; getting all categories, foreaching that to get all subcategories; etc.

If I'm the one killing their server by running a few hundred requests, each throttled by 3 seconds, then, really, that's not my fault.

Null Set
Nov 5, 2007

the dog represents disdain

Golbez posted:

Right. $oCities = $oSoap->GetCities($oSearch), then foreaching that to get each facility; getting all categories, foreaching that to get all subcategories; etc.

If I'm the one killing their server by running a few hundred requests, each throttled by 3 seconds, then, really, that's not my fault.

Yeah, that sounds like they have some sort of throttling on their end.

Is this a script you only need to run once to grab all this data? Or is it something that's going to have to be run repeatedly? If it only needs to be run once, you could just track how far you get, then resume from there.

Or you could contact them and see if they can add a service that you can call once to get the exact information you need, instead of making repeated calls.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Null Set posted:

Yeah, that sounds like they have some sort of throttling on their end.

Is this a script you only need to run once to grab all this data? Or is it something that's going to have to be run repeatedly? If it only needs to be run once, you could just track how far you get, then resume from there.

Or you could contact them and see if they can add a service that you can call once to get the exact information you need, instead of making repeated calls.

Throttling would make sense. The whole thing shutting down and displaying an error message to everyone - not just me - is very nonsensical.

Thankfully, this is indeed a list that can be pulled a little at a time and stored.

Adbot
ADBOT LOVES YOU

mewse
May 2, 2006

I was trying to teach myself cakephp but a post in this thread caused me to start investigating Symfony2, and it seems a lot better.

Is netbeans a good IDE for php/symfony2? I'm fine with just using vi but idk what's out there

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply