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
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Revitalized posted:

So I gave up trying to start with node.js, and have turned to trying my hand at PHP since w3schools has a tutorial for it (which is easier for me to digest)

Anyways, for some reason I've confused myself at how to setup my computer to do php. I tried some simple stuff like printing Hello World but nothing shows. It's a blank page.

I ended up downloading a number of different php binaries (thread safe and non thread safe?) and I think an Apache server which I don't know how to work... and I'm not even sure what Netbeans might have added in addition. Basically somehow I've confused myself. Anyone have like a 1. 2. 3. step guide of what to do from a clean slate just to get me on my feet so I can start learning and practicing php?

Sorry for sounding like an idiot.

First off please don't use w3schools as a learning resource, there are a lot of problems with the site but their PHP stuff is particularly bad. Unfortunately although there are a lot of PHP guides and tutorials on the internet, a lot of them are out of date or just poor. I don't know a good one to link to, or I would.

If you've installed PHP then you can run PHP scripts from the command line by navigating to the directory where the script is and entering "php script_name.php". For example if your script is the standard "Hello World" that just echoes a string, then when running it from the command line you should see it print the string. If you install a web server I guess you may be able to interact with it as though it were a web site, but that's probably not needed for learning.

It is a matter of preference but personally I'd prefer my computer PHP files to be opened in a text editor - that's what I want to do with it more often than execute it.

Adbot
ADBOT LOVES YOU

Revitalized
Sep 13, 2007

A free custom title is a free custom title

Lipstick Apathy

Scaramouche posted:

I'm assuming Windows here; what I'd suggest is uninstalling all that stuff. I've had a dedicated server for quite a while, but if I recall WAMP wasn't that bad:
http://www.wampserver.com/en/

(Windows Apache MySQL PHP)

You can choose to add/remove things like MySQL if you feel you don't need that yet.

Okay thanks, I'll try this right now.

Hammerite posted:

First off please don't use w3schools as a learning resource, there are a lot of problems with the site but their PHP stuff is particularly bad. Unfortunately although there are a lot of PHP guides and tutorials on the internet, a lot of them are out of date or just poor. I don't know a good one to link to, or I would.


Well if anyone does come up with a good one that a beginner can use, I'll look into it. For now though, it'll have to get me started at least.

I was designing my own website and the first wall I came into was making a working login/registration screen, which I found out I need some server side scripting knowledge to do, so that's why I'm looking into PHP now.

Masked Pumpkin
May 10, 2008
I appreciate that this may start a derail, but if you're just getting into PHP, using a good editor like Notepad++ instead of plain old notepad can help a lot.

If you're just getting into PHP and have questions, I'd say that's exactly what this thread is for - good luck!

baquerd
Jul 2, 2007

by FactsAreUseless

Masked Pumpkin posted:

I appreciate that this may start a derail, but if you're just getting into PHP, using a good editor like Notepad++ instead of plain old notepad can help a lot.

If you're just getting into PHP and have questions, I'd say that's exactly what this thread is for - good luck!

Notepad++ is excellent. There are also PHP modules/plugins for common IDEs such as Eclipse and IntelliJ.

http://thinkvitamin.com/code/how-to-debug-in-php/

Ultimately, if you don't know how to use a debugger in whatever language you are programming in, you are crippled whether you realize it or not.

indulgenthipster
Mar 16, 2004
Make that a pour over

baquerd posted:

Notepad++ is excellent. There are also PHP modules/plugins for common IDEs such as Eclipse and IntelliJ.

If you want to use Eclipse I highly recommend Aptana (http://aptana.org). It comes with PHP and other web languages pre-installed so you do not have to worry about configuring anything once you install it.

sturgeon general
Jun 27, 2005

Smells like sushi.
Has anyone ever used FluentPDO?

I was working on a usage metrics tool that supports different report types and date ranges on an HTML POST form, then pulls that data from a SQL backend. One of the requested features involves joining on another table with user ids for aggregate usage reports on departments, employee areas, etc. Right now the code is kind of a mess where I'm checking POST variables and adding WHERE, GROUP BY, and JOIN ON clauses to the queries manually via variables, with empty strings as the default (uggggggh).

I bet 99% of PHP query builders are complete garbage but I wanted to check if this one was somewhat reasonable. It's basically a wrapper for PDO so it should be okay, right?

Sab669
Sep 24, 2009

I was so confused when I couldn't find the PHP thread, turns out I was on SHSC :downs:

Have any of you guys played with the google API at all? In the coming weeks I'll need to play around with it and see if I can implement just a simple page to get directions from Point A to Point B and I have very little experience with.. any API / web services. Would have no idea where to start in PHP.

e; Hm, now that I think about it I also remember a co-worker telling me the other day I guess you can actually use Google Spreadsheets as a database? A different sheet per table I guess?

Sab669 fucked around with this message at 00:55 on May 17, 2012

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is an okay introduction that'll hopefully get you over the hump of instantiating objects, making requests, etc.
https://developers.google.com/maps/articles/phpsqlajax

The two points thing I'm not sure of but this seems relevant:
http://stackoverflow.com/questions/2296087/using-php-and-google-maps-api-to-work-out-distance-between-2-post-codes-uk

EL BROMANCE
Jun 10, 2006

COWABUNGA DUDES!
🥷🐢😬



I'm trying to quickly throw together a quick voting page system for SA members during Eurovision, but having a bit of difficulty with the validation. Like most SA-based sites, I'm hoping to use a string of text on the profile screen to validate, but when I do a quick parse using the file_get_contents command, the forum rightfully doesn't think my server is logged in and won't pass the info across.

Is there a nice easy way to get my server to use my login so I can read the profiles? I'm guessing it could be done with a cookie, but not sure the easiest way to do it.

edit: have been trying with cURL all afternoon and getting no closer...

I'm not quite sure which URLs to use and where. I've grabbed some data using Tamper and the form itself is dead simple... the 'closest' I think I'm coming is the below, which then redirects to my web root, possibly due to the refresh in the login page.

php:
<?
    $curl_handle=curl_init();
    curl_setopt( $curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
    curl_setopt($curl_handle,CURLOPT_URL,'http://forums.somethingawful.com/account.php');
    curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl_handle,CURLOPT_COOKIEFILE,dirname( __FILE__ ).DIRECTORY_SEPARATOR."cookie.log");
    curl_setopt($curl_handle,CURLOPT_COOKIEJAR,dirname( __FILE__ ).DIRECTORY_SEPARATOR."cookie.log");
    curl_setopt($curl_handle,CURLOPT_REFERER,'http://forums.somethingawful.com/account.php');
    curl_setopt($curl_handle,CURLOPT_POST,true);
    curl_setopt($curl_handle,CURLOPT_POSTFIELDS,"action=login&username=The+pHo&password=XxxXxXxXXxxXxXx");
    curl_setopt($curl_handle,CURLOPT_FRESH_CONNECT,true);//No caching
    curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($curl_handle,CURLOPT_MAXREDIRS,1);
    $buffer=curl_exec($curl_handle);
    curl_close($curl_handle);
    echo $buffer;?>
I've tried changing the top URL to the index and the profile page for my username, and both indicate it's not logged in. Am I even approaching this in the correct way? I've changed the followlocation tag to false with no effect.

edit:

aaaaand got it, the code on this site worked. Might have to bookmark this for future use, as I'm bound to get caught up on the same thing again! http://www.phpcodester.com/2011/01/scraping-a-password-protected-website-with-curl/

EL BROMANCE fucked around with this message at 18:21 on May 17, 2012

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

:dukedog:

You could have also just used alluvion.

http://www.alluvion.org/authdb.txt

mooky
Jan 14, 2012
I'm trying to do a pass through download via php and curl.

I am presenting the user with a link to download a file that appears to be local. What I want to do is actually download the file from a different location and pass that seamlessly to the user. This keeps credentials required for the file download private from the user and it appears to come from my site. Something to note is that the files may range in size from 10mb to 1gb so I can't wait for the download to complete and then serve it to the user.

The purpose is to provide a seamless process without confusing the user by linking them to a different download location.

I've read how to download the file with Curl and save it locally, but I want it to be completely transparent.

Any ideas?

Doh004
Apr 22, 2007

Mmmmm Donuts...
Just do some URL rewriting. Have the request goto mydomain.com/fileIdOrWhatever/filename.exe which is just rewritten to goto myscript.php?id=fileIdOrWhatever and direct the request to the correct location.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah this sounds like a job for .htaccess

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
edit: nm, stupid question that had nothing to do with the problem

Golbez fucked around with this message at 15:44 on May 22, 2012

Aniki
Mar 21, 2001

Wouldn't fit...
I am working on extracting the XML data from a response string for a payment gateway. I can verify the response by searching for terms like 'Successful,' but when I try to use Simple XML to parse the response string, then I run into problems. I send our requests using curl and this is a typical response we would get from the gateway:

quote:

HTTP/1.1 200 OK Date: Mon, 21 May 2012 22:17:41 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 229 <Response><Code>000</Code><Message>Successful</Message><Value>30272720</Value></Response>

What I've noticed is that when the header data (i.e. anything before the <Response> tag is there, then I can't seem to extract the data from XML. If I take that same string and remove the header info, then I can get data from the XML:

php:
<?
$response = <<<XML
<Response><Code>000</Code><Message>Successful</Message><Value>30272691</Value></Response>
XML;

$xml = simplexml_load_string($response);
echo $xml->Value; // Prints out 30272691
?>
I asked the gateway to provide a code example of how to parse their XML response, but so far they keep sending me the wrong info. I'm not as comfortable working with XML as I am with handling CSV files, so I am hoping that there is something stupid that I am overlooking.

Aniki fucked around with this message at 19:47 on May 23, 2012

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
Set the CURLOPT_HEADER option to 0 so the response does not include headers, just the raw XML.

Aniki
Mar 21, 2001

Wouldn't fit...

musclecoder posted:

Set the CURLOPT_HEADER option to 0 so the response does not include headers, just the raw XML.

I tried doing that and I got the following response:

quote:

Warning: curl_setopt() [function.curl-setopt]: You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments in /home/.../gatewayTest.php on line 21

This is the function that I'm using to send the request:

php:
<?
function sendRequest($url, $queryString, $port) {
    // Checks to see if a port variable has been pass through
    if (empty($port)) {
        $port = "";
    } // End if if (empty($port))

    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    // If the port is not empty, then it will set the port to the user defined port, otherwise the port settings will not be changed.
    if ($port != "") {
        curl_setopt ($ch, CURLOPT_PORT , $port); // Added preferred PayPal port
    } // End if ($port != "")
    //curl_setopt($ch, CURLOPT_HTTPHEADER, curl_getinfo($ch));
    curl_setopt($ch, CURLOPT_HTTPHEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
    curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
    curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString); //adding POST data
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2); //verifies ssl certificate
    curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
    curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST

    $result = curl_exec($ch);
    //$headers = curl_getinfo($ch);
    $headers = "";
    curl_close($ch);

    return $result;
}
?>
Line 21 in that file would refer to this line:

curl_setopt($ch, CURLOPT_HTTPHEADER, 0);

And previously I had been using:

curl_setopt($ch, CURLOPT_HTTPHEADER, curl_getinfo($ch));

Even with the errors and the CURLOPT_HEADER option being set to 0, I get the following response:

quote:

HTTP/1.1 200 OK Date: Wed, 23 May 2012 19:10:27 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 209 <Response><Code>207</Code><Message>Missing or invalid amount</Message></Response>

Do you guys have any thoughts on what I could do differently when I am sending the curl request to get a response that is just XML?

Impotence
Nov 8, 2010
Lipstick Apathy

quote:

curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
try 0 for that?

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
Like the docs say, CURLOPT_HTTPHEADER takes an array of values. Not a scalar. http://us2.php.net/curl_setopt

Edit: Also what Biowarfare and I just said a second ago. Do that.

Aniki
Mar 21, 2001

Wouldn't fit...

Biowarfare posted:

try 0 for that?

Thank you, I can't believe that I missed that. Making that change did return an XML only response. I'll work on the XML handling now and see what kind of progress I can make. At least I have a clean XML response to work with now.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
poo poo like that is why using a well-tested HTTP wrapper is usually a wise choice.

Even PEAR's horribly out of date HTTP_Request2 is a better choice than having to wrangle curl every time.

Null Set
Nov 5, 2007

the dog represents disdain

McGlockenshire posted:

poo poo like that is why using a well-tested HTTP wrapper is usually a wise choice.

Even PEAR's horribly out of date HTTP_Request2 is a better choice than having to wrangle curl every time.

Personally I like pecl_http (docs), but it's admittedly not that helpful if you can't modify your php installation (so it's pretty much right out if you're on shared hosting).

Aniki
Mar 21, 2001

Wouldn't fit...

McGlockenshire posted:

poo poo like that is why using a well-tested HTTP wrapper is usually a wise choice.

Even PEAR's horribly out of date HTTP_Request2 is a better choice than having to wrangle curl every time.

Something like that may not be a bad idea. I'll need to look into HTTP_Request2 and pecl_http and see what I think of them.

I'm still having trouble dealing with the XML responses that I get from this gateway. It will return a response like this:

quote:

<Response><Code>207</Code><Message>Missing or invalid amount</Message></Response>

Which appears to be valid XML. If I take that response and manually store it in a string like this:

php:
<?
$response = sendRequest('https://...REMOVED.../SaveSingleTransaction', $gatewayString, "", "GATEWAY NAME");

$response = '<Response><Code>000</Code><Message>Successful</Message><Value>30272691</Value></Response>';
$xml = <<<XML
$response
XML;

$domResponse = new DOMDocument();
$domResponse->loadXML($response);

echo "<br /><br />SAVE XML :: " . $domResponse->saveXML() . "<br /><br />";
$domResponseElement = $domResponse->documentElement;

$i = 0;
 
foreach ($domResponseElement->childNodes AS $item) {
    print $i . " " . $item->nodeName . " = " . $item->nodeValue . "<br />";
    $i++;
}
?>
Then I'll get this response:

quote:

SAVE XML :: 000Successful30272691

0 Code = 000
1 Message = Successful
2 Value = 30272691

However, if I try directly loading the response into Dom Documents via loadXML($response), like this:

php:
<?
function sendRequest($url, $queryString, $port, $gateway) {
    // Checks to see if a port variable has been pass through
    if (empty($port)) {
        $port = "";
    } // End if if (empty($port))
    
    if (empty($gateway)) {
        $gateway = "";
    } // if (empty($gateway))

    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    // If the port is not empty, then it will set the port to the user defined port, otherwise the port settings will not be changed.
    if ($port != "") {
        curl_setopt ($ch, CURLOPT_PORT , $port); // Added preferred PayPal port
    } // End if ($port != "")
    curl_setopt($ch, CURLOPT_HTTPHEADER, curl_getinfo($ch));
    //curl_setopt($ch, CURLOPT_HTTPHEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    if ($gateway == 'GATEWAY NAME') :
        curl_setopt($ch, CURLOPT_HEADER, 0); // tells curl to exclude headers in the response
    else :
        curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in the response
    endif;
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
    curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
    curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString); //adding POST data
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2); //verifies ssl certificate
    curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
    curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
    
    $result = trim(curl_exec($ch));
    //$headers = curl_getinfo($ch);
    $headers = "";
    curl_close($ch);

    return $result;
}

$response = sendRequest('https://...REMOVED.../SaveSingleTransaction', $gatewayString, "", "GATEWAY NAME");

$domResponse = new DOMDocument();
$domResponse->loadXML($response);

echo "<br /><br />SAVE XML :: " . $domResponse->saveXML() . "<br /><br />";
$domResponseElement = $domResponse->documentElement;

$i = 0;
 
foreach ($domResponseElement->childNodes AS $item) {
    print $i . " " . $item->nodeName . " = " . $item->nodeValue . "<br />";
    $i++;
}
?>
Then I'll get this response where all of the data is returned as the same node value:

quote:

SAVE XML :: <Response><Code>207</Code><Message>Missing or invalid amount</Message></Response>

0 #text = 207Missing or invalid amount

When I look at the source for this line, "0 #text = 207Missing or invalid amount," I find that the XML tags are still there

quote:

<br><br>0 #text = <response><code>207</code><message>Missing or invalid amount</message></response><br></body></html>

So as far as I can tell, when I try to load the response, is being interpretted as a string and not XML data. I've tried adding this, '<?xml version="1.0" encoding="utf-8"?>', to beginning of the response string, it just yields an error that I am tryig to get the property of a non-object.

Do you guys think the problem is being caused by the XML or is there a different way that I can handle or caste the response string so that it can actually be imported into Dom Document as an XML string?

mooky
Jan 14, 2012

mooky posted:

I'm trying to do a pass through download via php and curl.

I am presenting the user with a link to download a file that appears to be local. What I want to do is actually download the file from a different location and pass that seamlessly to the user. This keeps credentials required for the file download private from the user and it appears to come from my site. Something to note is that the files may range in size from 10mb to 1gb so I can't wait for the download to complete and then serve it to the user.

The purpose is to provide a seamless process without confusing the user by linking them to a different download location.

I've read how to download the file with Curl and save it locally, but I want it to be completely transparent.

Any ideas?

Doh004 posted:

Just do some URL rewriting. Have the request goto mydomain.com/fileIdOrWhatever/filename.exe which is just rewritten to goto myscript.php?id=fileIdOrWhatever and direct the request to the correct location.

Unfortunately that won't work. A direct link to the file requires a username and password. I can authenticate via curl headers but I don't want to use PHP resources to download and serve the file to the user. I only want to use PHP + curl to pass through authentication and transparently serve this file as though it is coming from the page the user is on.

Example:

http://iammooky.com/somescript.php?fileid=1
would actually serve a file from here:
https://someotherresource.com/authorized/download.cgi?file=1

The user doesn't need to know where the file is coming from although it isn't a big secret. I just can't link the user to the file download or it will require a username and password.

mooky
Jan 14, 2012
I think this is a better example of what I want to do...

Use PHP + curl to retrieve remote file
Use PHP Stream functions to stream file to user without saving the file locally.
Avoid PHP memory limit and max execution time issues
Keep the file source hidden from the user

I have no idea how to use the php stream functions, I'm hoping someone has done this and can share some tips.

Sab669
Sep 24, 2009

quote:

[29-May-2012 18:41:44] PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in \model\cartItems.php on line 5

edit; I guess if I move the properties after the constructor it seems fine?

Sab669 fucked around with this message at 17:55 on May 29, 2012

Superdawg
Jan 28, 2009
Don't you need to prepend those with var?

var $unitPrice;
var $quanity;
...

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

Sab669 posted:

So I'm pretty amateur at PHP, especially with object oriented PHP... no idea why this isn't working...

code:
class cartItems
{
  $unitPrice;
  $quantity;
  $productID;
  $totalPrice;
  $name;

  public function __construct($UP, $Q, $PID, $N)
  {
    $this->setUnitPrice($UP);
	$this->setQuantity($Q);
	$this->setProductID($PID);
	$this->setTotalPrice();
	$this->setName($N);
  }
Then obviously I have all of my various methods after the constructor. When I try to run an application that requires this class, I get this error:

I'm pretty sure you can't just declare class properties with a $variable, you need to have a visibility keyword: public, private, or protected. So the third line above would then become private $unitPrice, for example. As for which to use, good question, I'm not qualified to say which, but setting them all to public would have the least ramifications on your code, at least as it is now.

More information: http://us.php.net/manual/en/language.oop5.properties.php

Sab669
Sep 24, 2009

Superdawg posted:

Don't you need to prepend those with var?

var $unitPrice;
var $quanity;
...

I had looked at the this page quickly and it didn't say so, but yea as the above guy mentioned I also needed to declare the scope.

I'm just doing something quick and dirty, mostly as a proof of concept so that's why I hadn't bothered. I figured it just defaulted to public and for the time being that's perfectly fine. I know they should rarely be public in the real world, though.

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

Superdawg posted:

Don't you need to prepend those with var?

var $unitPrice;
var $quanity;
...

var is kept around only for backwards compatibility, declaring with the scope is preferred. It is not technically deprecated though.

Aniki
Mar 21, 2001

Wouldn't fit...
I sort of figured out the XML issue that I was having. I seem to turn the XML string into a proper object with SimpleXML or DOMDocument. If I created a string with the same output as the response then it would work, but for some reason I couldn't turn the response into an object. I ended up using the following function to successfully parse the response:

php:
<?php 
/** 
 * Convert XML to an Array 
 * 
 * @param string  $XML 
 * @return array 
 */ 
function XMLtoArray($XML) 
{ 
    $xml_parser xml_parser_create(); 
    xml_parse_into_struct($xml_parser$XML$vals); 
    xml_parser_free($xml_parser); 
    // wyznaczamy tablice z powtarzajacymi sie tagami na tym samym poziomie 
    $_tmp=''; 
    foreach ($vals as $xml_elem) { 
        $x_tag=$xml_elem['tag']; 
        $x_level=$xml_elem['level']; 
        $x_type=$xml_elem['type']; 
        if ($x_level!=&& $x_type == 'close') { 
            if (isset($multi_key[$x_tag][$x_level])) 
                $multi_key[$x_tag][$x_level]=1; 
            else 
                $multi_key[$x_tag][$x_level]=0; 
        } 
        if ($x_level!=&& $x_type == 'complete') { 
            if ($_tmp==$x_tag) 
                $multi_key[$x_tag][$x_level]=1; 
            $_tmp=$x_tag; 
        } 
    } 
    // jedziemy po tablicy 
    foreach ($vals as $xml_elem) { 
        $x_tag=$xml_elem['tag']; 
        $x_level=$xml_elem['level']; 
        $x_type=$xml_elem['type']; 
        if ($x_type == 'open') 
            $level[$x_level] = $x_tag; 
        $start_level 1; 
        $php_stmt '$xml_array'; 
        if ($x_type=='close' && $x_level!=1) 
            $multi_key[$x_tag][$x_level]++; 
        while ($start_level $x_level) { 
            $php_stmt .= '[$level['.$start_level.']]'; 
            if (isset($multi_key[$level[$start_level]][$start_level]) && $multi_key[$level[$start_level]][$start_level]) 
                $php_stmt .= '['.($multi_key[$level[$start_level]][$start_level]-1).']'; 
            $start_level++; 
        } 
        $add=''; 
        if (isset($multi_key[$x_tag][$x_level]) && $multi_key[$x_tag][$x_level] && ($x_type=='open' || $x_type=='complete')) { 
            if (!isset($multi_key2[$x_tag][$x_level])) 
                $multi_key2[$x_tag][$x_level]=0; 
            else 
                $multi_key2[$x_tag][$x_level]++; 
            $add='['.$multi_key2[$x_tag][$x_level].']'; 
        } 
        if (isset($xml_elem['value']) && trim($xml_elem['value'])!='' && !array_key_exists('attributes'$xml_elem)) { 
            if ($x_type == 'open') 
                $php_stmt_main=$php_stmt.'[$x_type]'.$add.'[\'content\'] = $xml_elem[\'value\'];'; 
            else 
                $php_stmt_main=$php_stmt.'[$x_tag]'.$add.' = $xml_elem[\'value\'];'; 
            eval($php_stmt_main); 
        } 
        if (array_key_exists('attributes'$xml_elem)) { 
            if (isset($xml_elem['value'])) { 
                $php_stmt_main=$php_stmt.'[$x_tag]'.$add.'[\'content\'] = $xml_elem[\'value\'];'; 
                eval($php_stmt_main); 
            } 
            foreach ($xml_elem['attributes'] as $key=>$value) { 
                $php_stmt_att=$php_stmt.'[$x_tag]'.$add.'[$key] = $value;'; 
                eval($php_stmt_att); 
            } 
        } 
    } 
    return $xml_array; 
} 

http://stackoverflow.com/questions/3630866/php-parse-xml-string

Luckily, the response I get is relatively simple and only related to one transaction at a time, so it will work for this application. I'm just happy to get this stupid thing working without resorting to work arounds like searching the string or parsing it using regular expressions.

revmoo
May 25, 2006

#basta

Golbez posted:

I'm pretty sure you can't just declare class properties with a $variable, you need to have a visibility keyword: public, private, or protected. So the third line above would then become private $unitPrice, for example. As for which to use, good question, I'm not qualified to say which, but setting them all to public would have the least ramifications on your code, at least as it is now.

More information: http://us.php.net/manual/en/language.oop5.properties.php

Public means it can be called from outside the class, e.g. $classobj->method(). Private means that only the class itself can call it from within, and protected means only classes that extend the class may use it.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
Does anyone have any experience with VIP Authentication and PHP? It's a SOAP API, but I hate SOAP and was hoping a Class might already exist.

https://www-secure.symantec.com/connect/sites/default/files/VIPTestDrive.zip

DarkLotus fucked around with this message at 23:47 on May 29, 2012

Null Set
Nov 5, 2007

the dog represents disdain
Has anyone else had this problem with Xdebug? Whenever I set a breakpoint after I've done a PDO fetch from a result set, Xdebug will crash and disconnect.

I know it's specifically the fetch, since I've tried breakpoints elsewhere, and they're fine. But once I've passed the point in execution where I've done the fetch and I want to see the output in the debugger, no dice.

It will hang while waiting to load, then after about 5 seconds "Process finished with exit code -1073741819".

This is on PHP 5.4.

Doh004
Apr 22, 2007

Mmmmm Donuts...
I'm looking to apply to a pretty large company whose main platform is PHP and MySQL. I've been doing LAMP development for about 8 or so years through high school and college, but never professionally. I've spent the past year working for a company doing C# work, so I have experience in the field.

I haven't really kept up with the latest or greatest things going on with the newer versions of PHP (really only dabled with OOP in PHP) and anything I did previously is pretty out of date. Is there anything you guys would suggest I read up on?

I'm not looking to learn about any PHP frameworks as this place runs everything custom (frameworks are too slow), but any extensions that are pretty neat? I'd love to not seem outdated when I go talk to them. Thanks :)

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
PDO - PHP Data Objects - the PHP database abstraction library to use.

DateTime - Useful and extensive date and time library.

Process Control - The closest thing PHP will have to actual threads.

SPL - Standard PHP Library - Bunch of useful classes in here.

Iterators

Exceptions

Interface

Be wary of a company that won't use a framework because they're to slow. The big ones are often much more tested than something built in how. Make sure they don't have NIH syndrome too much and there's a reason they built their own framework.

burnt_offerings
May 9, 2012

I think if you have 8 years of real PHP experience, professional or otherwise, you're in pretty good shape. If the interpreter gives you deprecation warnings, just check out the replacement methods on php.net.

If you're procedural by nature, as I am, then OO can take a little while to wrap your head around if you're new to it all. But if you have a mind for programming, you'll figure it out pretty easily. Syntax isn't really all that different. You just kinda think about things a little differently.

geonetix
Mar 6, 2011


Make sure you understand the basics and caveats of PHP5, the way PHP implements and uses OOP and how that differs from other systems (like C#), and know all or most of the default security problems (like how to prevent SQL injection, path traversal, cross site request forgery and cross site scripting), you should be fine. Even if you use a framework, you'll run into problems related to these often and you need to know how to deal with them.

Personally, I don't code too much PHP (or any at all lately), but the company I work for does and these things come up often. Even if you only call these basics by name, you're already one large step ahead of the pack.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Thanks for the advice guys. Hopefully it pans out :)

Adbot
ADBOT LOVES YOU

alucinor
May 21, 2003



Taco Defender
.htaccess question:

Another website has screwed up a potentially high-traffic link to my site. They've accidentally(?) appended a tracking code onto the URL so users who click their link to us end up at http://example.com/?&tokenid=fbb7e521-21da-4db2-97eb instead of at our homepage, http://example.com. So they end up at a page not found error instead of at our homepage.

I figured the easiest fix would be to use RedirectMatch in my .htaccess file to point users accessing that URL to the correct homepage:
code:
RedirectMatch ^?&tokenid=fbb7e521-21da-4db2-97eb http://example.com
However, it doesn't work. Through googling I found and tried a couple of different methods (escaping the special characters, using Rewrite Rule to remove the query string, using Rewrite Rule instead), none of which worked for me. Any guidance or tips on what I'm overlooking?

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