|
Disclaimer: I'm a complete PHP (and everything else) newb, and have recently found out that I can only learn by doing. This is my first little project, so my code is probably horribly inefficient and my question is probably stupid. What I'm trying to do is to write a script that will go out, grab two xml files from a certain site with cURL, put specific elements from the xml files into two arrays, and then return the common array values with array_intersect(). The URL formats are like this: http://doopy/doo/<xmlfile>.xml?page=<pagenum> Now, I've figured out how to make it work so that I can specify the <xmlfile> portions with an html form (as you can see from the code below). The <pagenum> part is what's killing me. Right now the variable is set at 1 in the script, but I'd like to be able to have it automatically get a variable range of <pagenum>s, and have cURL grab all of them. The problem is, different <xmlfile>s have different <pagenum>s. For instance, the first one might have a range of 1-3, while the second might have a range of 1-7. If you try and get <pagenum> 4 in the first <xmlfile>, it returns an empty document tree and the whole script barfs. I can't figure out how to have it go through each <pagenum> until it hits the empty tree, and just get data from the preceding files. On top of that, I don't know how to use cURL to fetch all the pages once I figure out how to deal with the <pagenum> range issue mentioned above. Thanks for your help, I hope this makes sense. Like I said, this is the first time I've really done anything with PHP. php:<? //URL #1 $xmlfile1 = $_POST['xmlfile1']; $page1 = 1; $url1 = array('http://doopy/doo/', $xmlfile1,'.xml?page=', $page1,); $imploded1 = implode($url1); //URL #2 $xmlfile2 = $_POST['xmlfile2']; $page2 = 1; $url2 = array('http://doopy/doo/', $xmlfile2, '.xml?page=', $page2,); $imploded2 = implode($url2); // Use cURL to get XML #1 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $imploded1); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $xml1 = curl_exec($ch); curl_close($ch); //User cURL to get XML #2 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $imploded2); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $xml2 = curl_exec($ch); curl_close($ch); ?>
|
# ? Jan 6, 2009 21:24 |
|
|
# ? May 16, 2024 05:08 |
|
Is the page number also being inputted by the user with the HTML form? If you're just trying to pull all pages, I think it would look something like this: php:<?php // config.php define("XML_LOCATION", "http://doopy/doo/"); define("XML_USERNAME", "user"); define("XML_PASSWORD", "password"); ?> php:<?php // functions.php function get_page($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, XML_USERNAME.":".XML_PASSWORD); $xml = curl_exec($ch); curl_close($ch); return $xml; } ?> php:<?php // index.php require_once("config.php"); require_once("functions.php"); $i = 1; while ( $xml1[$i] = get_page(XML_LOCATION.$_POST["xml_file1"]."?page=".$i) ) { $i++; } $i = 1; while ( $xml2[$i] = get_page(XML_LOCATION.$_POST["xml_file2"]."?page=".$i) ) { $i++; } ?> This might be wrong though. I'm doubtful that assigning the output of get_page() to $xml1 or $xml2 will return false if there's no data. The idea is that the while loop will end once that happens. Since I don't really know for sure, can somebody more knowledgeable say how you would evaluate whether a variable assignment has succeeded or not based on whether or not $source is null? Would something like this work? php:<?php while ( ($target = $source) === true ) { // do stuff } ?> Zorilla fucked around with this message at 22:10 on Jan 6, 2009 |
# ? Jan 6, 2009 21:43 |
|
Zorilla posted:Is the page number also being inputted by the user with the HTML form? No. I was hoping to somehow have the script magically try every page number until it hit one without any data. Edit: and then have cURL put all the data into one string at curl_exec. Edit 2: Oooh, nifty. Thanks. I'll give that a shot. blitrig fucked around with this message at 21:49 on Jan 6, 2009 |
# ? Jan 6, 2009 21:46 |
|
Zorilla posted:This might be wrong though. I'm doubtful that assigning the output of get_page() to $xml1 or $xml2 will return false if there's no data. The idea is that the while loop will end once that happens. The loop doesn't end. Here's what the populated XML tree looks like: code:
code:
|
# ? Jan 6, 2009 22:16 |
|
Oh, I was assuming the results would be totally null if you specified a page that didn't exist. Do you have any control over the site that does the XML results or is that totally out of your hands? Ideally, you'd be able to specify a page range (or all pages) at the server side instead of having to cURL one page at a time. You may have to use a DOMDocument object to figure out whether <records> has children instead. I'm not sure how the one-page-at-a-time loop would look at first glance with this.
|
# ? Jan 6, 2009 22:22 |
|
Zorilla posted:Oh, I was assuming the results would be totally null if you specified a page that didn't exist. Do you have any control over the site that does the XML results or is that totally out of your hands? Ideally, you'd be able to specify a page range (or all pages) at the server side instead of having to cURL one page at a time. I actually don't have any control over the site. <xmlfile> can be one of thousands of options, all with differing numbers of pages. Haven't ever done anything with DOM stuff. I'll start looking into it. Edit: Wow. I just found out that one of the XML files has close to 2000 pages. That might make things interesting (and slow). Glurg. Edit2: The site only allows fetching a certain number of records within the XML document per request, hence the page numbers. blitrig fucked around with this message at 22:44 on Jan 6, 2009 |
# ? Jan 6, 2009 22:29 |
What's an effective way to use memcached to serve thumbnails and also have them be cached by the users browser?
|
|
# ? Jan 7, 2009 02:46 |
|
If this is Apache you can enable mod_expires. I have an htaccess with something like this: code:
|
# ? Jan 7, 2009 03:50 |
|
Zorilla posted:
NULL is evaluated to FALSE, but your context there is a bit odd. The assignment of "something" to $target will be TRUE, even if it's NULL because there's no $source left. My guess (not knowing exactly what you are trying there) is you want foreach php:<? foreach ($source as $value) { // do stuff } ?> Foreach: http://us3.php.net/manual/en/control-structures.foreach.php
|
# ? Jan 7, 2009 06:38 |
|
Zorilla posted:Since I don't really know for sure, can somebody more knowledgeable say how you would evaluate whether a variable assignment has succeeded or not based on whether or not $source is null? Would something like this work? Since assignment returns the assigned value, wouldn't is_null($target = $source) work? I have no idea why you'd want to do this however.
|
# ? Jan 7, 2009 19:36 |
|
Atom posted:Since assignment returns the assigned value, wouldn't is_null($target = $source) work? I believe isset( ) will also get the same effect.
|
# ? Jan 7, 2009 19:38 |
drcru posted:If this is Apache you can enable mod_expires. Yes, but what about using memcached to serve them initially, and avoiding accessing the disk?
|
|
# ? Jan 7, 2009 19:48 |
|
This is a mixed php/Actionscript 2/MySQL question. PHP is echoing back a variable queried from MySQL just fine, called $imageSourcesString. When gets the variable with loadVariables, it returns empty in Flash. If I redefine $imageSourcesString in php as $imageSourcesString="test"; its sent to Flash just fine. Why can the original variable echo in php, but not be sent to Flash? I've tried adding quotes, characters around the original, etc. Say if I redefine it as $imageSourcesString="A".$imageSourcesString."A"; in Flash it shows up as "AA". I can see that $imageSourcesString echos in php perfectly alright as the image names. What the hell? Is $imageSourcesString not a proper string for Flash or something coming from MySQL?
|
# ? Jan 7, 2009 21:11 |
|
awdio posted:This is a mixed php/Actionscript 2/MySQL question. PHP is echoing back a variable queried from MySQL just fine, called $imageSourcesString. When gets the variable with loadVariables, it returns empty in Flash. If I redefine $imageSourcesString in php as $imageSourcesString="test"; its sent to Flash just fine. It needs to be a URLecoded string... your problem seems odd though. Are you trying to output the string $myVar=A[$myvar's value]A as a result? [EDIT] looks like you *can* use an "$" as the first char of a variable name in AS2, but I'm guessing the URLencoding is hosing it up still. Lumpy fucked around with this message at 22:15 on Jan 7, 2009 |
# ? Jan 7, 2009 22:07 |
|
Lumpy posted:It needs to be a URLecoded string... your problem seems odd though. Are you trying to output the string $myVar=A[$myvar's value]A as a result? Using echo $imageSourcesString in php shows result. In Flash, it shows nothing. Doing this however after its defined: (I'm redefining the variable) $imageSourcesString="test text"; Shows this in Flash: test text Say if my variable $imageSourcesString equaled "123456789" as a result from the database. If I redefine it as: $imageSourcesString="A".$imageSourcesString."A"; In php it shows "A123456789A" In Flash it shows "AA" I was starting to think it had to do with register_globals being enabled. I'm currently using php 4 and after trying to change it to off, GoDaddy notified me I won't be able to do this unless I'm using php 5, which doesn't seem right. I swear I changed that setting before in php 4 on another server. Maybe its just the way GoDaddy does things. This is really blowing my mind though and I'm starting to think it has to do with some weird thing occurring with register_globals.
|
# ? Jan 7, 2009 23:11 |
|
awdio posted:Using echo $imageSourcesString in php shows result. OK, but what does Flash get when you do $imageSourcesString=urlencode($imageSourcesString);?
|
# ? Jan 8, 2009 00:06 |
|
Munkeymon posted:OK, but what does Flash get when you do $imageSourcesString=urlencode($imageSourcesString);? Same thing, still nothing.
|
# ? Jan 8, 2009 00:18 |
|
Zorilla posted:Is the page number also being inputted by the user with the HTML form? Okay, let's say that we don't have to loop through all the pages until we hit an empty XML doc. If I set the number of pages to a variable ($pagenum), how do I tell cURL to fetch all those pages and put them into a single array? Like: code:
Edit: Nevermind. Figured it out (finally), thanks to this page: http://www.ibuildings.nl/blog/archives/811-Multithreading-in-PHP-with-CURL.html blitrig fucked around with this message at 02:21 on Jan 8, 2009 |
# ? Jan 8, 2009 00:57 |
|
What the hell is going on here? I've got a script that contains a global var called $unit_price, and defines a class called Order. A later script that includes the first one can apparently refer to the global $unit_price var, but the Order class appears unable to do so (or at least, thinks its value is always 0). Here's the code from the first file: php:<? $unit_price = 29.99; class Order { // a bunch of public vars are declared, none are $unit_price function Order(){ //misc stuff is done, none of which refers to $unit_price //10% off for flyer respondants if($this->promo=="flyer21"){ $this->promo_isvalid=true; $this->promo_value= .1 * $unit_price * $this->quantity; } //some other stuff, also not about $unit_price } ?> php:<? if($my_order->promo_isvalid){ $promovaluestring = number_format($my_order->promo_value, 2); echo "<tr><td width='10%'></td> <td width='80%'>Promotional code: " . $my_order->promo . "</td> <td width='10%' id='total' align='right'>-$" . $promovaluestring . "</td> </tr>"; } ?> However, later in that same file: php:<? echo "<tr> <td width='10%' align='center'></td> <td width='80%'><strong>Total</strong></td> <td width='9%' id='total' align='right'><strong>$"; $total = $my_order->quantity * $unit_price + $my_order->shipping_price - $my_order->promo_value; echo $total . "</strong></td> </tr> ?> Incidentally, it's not that quantity is wrong in the constructor; testing with a promo value equal to "3 * $this->quantity" works just fine -- it's just that it thinks $unit_price is 0 when inside the Order constructor. Please tell me what is up with this devilry, because this makes no sense to me at all. Many thanks!
|
# ? Jan 8, 2009 01:36 |
Grand_High_Took posted:What the hell is going on here? Read this http://us2.php.net/variables.scope
|
|
# ? Jan 8, 2009 02:17 |
|
awdio posted:Using echo $imageSourcesString in php shows result. I finally figured out what was causing the problem, but I don't know WHY it happens. I had a variable defined with a get: $catNum=$_GET['catNum']; If I simply make that variable a number and not the get my other variable from the database gets sent to Flash. Why?? $catNum=3; Edit: Basically, if I have that variable $catNum defined with the get $_GET['catNum'], $imageSourcesString does not pass to Flash! If I make $catNum equal say, "3", everything works. But I NEED the get for $catNum. LP0 ON FIRE fucked around with this message at 04:52 on Jan 8, 2009 |
# ? Jan 8, 2009 03:10 |
|
fletcher posted:Read this http://us2.php.net/variables.scope Thanks - now I feel like that was a pretty dumb question. Not having run into this particular issue before, I just assumed the scope handling was like in C. Thanks for the help.
|
# ? Jan 8, 2009 03:42 |
|
awdio posted:I finally figured out what was causing the problem, but I don't know WHY it happens. I had a variable defined with a get:
|
# ? Jan 8, 2009 12:56 |
|
Standish posted:Looks like Flash is not supplying the "catNum" parameter in its GET query string for some reason, try running wireshark to see exactly what's going over the wire. But why would it need to? Flash is NOT getting the variable $catNum. It's getting $imageSourcesString. I'd try WireShark, but I don't think there's a non-Intel Mac version.
|
# ? Jan 8, 2009 18:48 |
|
I guess the question I should be asking is: How do you pass a variable with GET from one page to another (or even the same page) and have Flash load that variable in? I'm just passing it with the same page, but I've also tried passing it to another page. PHP gets it. Flash does not. If I just make a non-POST or non-GET variable it passes to Flash fine. If you think this normally should be done, try it out, because I'm starting to think it can't be done.. Edit: Its as if Flash is being loaded before the POST or GET vars.
|
# ? Jan 9, 2009 07:09 |
|
awdio posted:I guess the question I should be asking is: How do you pass a variable with GET from one page to another (or even the same page) and have Flash load that variable in? I'm just passing it with the same page, but I've also tried passing it to another page. PHP gets it. Flash does not. If I just make a non-POST or non-GET variable it passes to Flash fine. I'm confused now. Are you loading a page: blah.php?var=value And you want the flash that is embedded on the page to know that var = value? Or you are using flash to send a request to a script after your page loads, and the return from the script is var=value and flash is unable to pick that up? awdio posted:I'd try WireShark, but I don't think there's a non-Intel Mac version. open up terminal and use tcpdump Lumpy fucked around with this message at 22:09 on Jan 9, 2009 |
# ? Jan 9, 2009 22:05 |
|
Lumpy posted:I'm confused now. Works like this: I click on a URL that goes back to itself with a variable attached like so: http://pageurl.com/index.php?catNum=9 So when the page reloads, php sees that catNum is set, then does a mySQL query based on the catNum to form a variable to send to Flash - a list of images with a delimiter that Flash breaks down. The variable is called $imageSourcesString and is put into a hidden text field that Flash picks up with loadVariables. For some reason this isn't working BUT if I ignore the GET on the page reload and just set $catNum to a number everything else works fine. i.e. $catNum=12 instead of $catNum=$_GET["catNum"] Interestingly enough its not getting stuck until the Flash stage of things. PHP can still pick up the results of the image string based on the GET. LP0 ON FIRE fucked around with this message at 22:27 on Jan 9, 2009 |
# ? Jan 9, 2009 22:15 |
|
awdio posted:Works like this: Can you give us a real URL. I think I know what your poblem is, but I can't be sure unless I see WTF.
|
# ? Jan 9, 2009 22:38 |
|
Lumpy posted:Can you give us a real URL. I think I know what your poblem is, but I can't be sure unless I see WTF. http://www.donnastangerphotography.com/dbFormat/indexTest.php?catNum=12
|
# ? Jan 9, 2009 22:50 |
|
Are there any good tutorials or samples online for eAccelerator? I want to use it, but it's hard to find real world sample code, and the API documentation is pretty bare. I want to dig in to granular caching and learn more about its user data caching.
|
# ? Jan 10, 2009 11:09 |
|
I've been trying so many things. I even tried putting the URL into a variable and using explode to get the value after the equals sign, echoed the value to make sure php got it, and it still breaks Flash. I also tried making javascript function that fills in a div with the Flash code after a timed interval but it behaves exactly the same.
|
# ? Jan 11, 2009 00:30 |
|
Have you tried a small proof of concept completely separate from the code you've been working with? If all you need is for flash to receive the value of a php variable you can mock up this situation in very few lines of code. This should help isolate the problem. My guess is there's a problem with your code that you're overlooking because you have been debugging for too long. Step back, relax, and write a simple proof of concept. This will help you see if it works on that server/browser at all or if it's a specific problem with your code.
|
# ? Jan 11, 2009 01:00 |
|
Ghotli posted:Have you tried a small proof of concept completely separate from the code you've been working with? If all you need is for flash to receive the value of a php variable you can mock up this situation in very few lines of code. This should help isolate the problem. My guess is there's a problem with your code that you're overlooking because you have been debugging for too long. Step back, relax, and write a simple proof of concept. This will help you see if it works on that server/browser at all or if it's a specific problem with your code. Yes. And I can get a php variable into Flash. Its the GET variable in a mysql query is what causes things to get hung up. If I define the variable without the GET, it does not happen. I can echo back the correct results of the php query, the Flash just does not get anything from the result of the query. Read above for details. Also if people want a more direct way of looking at this, here's the php/html: code:
LP0 ON FIRE fucked around with this message at 01:34 on Jan 11, 2009 |
# ? Jan 11, 2009 01:24 |
|
I'm just starting out in PHP (and I'm a beginner in OOP in general) but I chose to make a forum since it'll be a good learning experience. Anyways, I was looking around SA to see what their forum structure was when I looked at the URLs for making a new thread or a new post. To reply to this thread, the URL is: code:
...?s=&action=newreply... Is this sending out 3 GET values, the first one named 's' and has no value? And just for clarification, it is sending at least 2 GETs: action and threadid, correct? Why would you need to clarify what the action is (newreply) when it's being sent to newreply.php? Isn't that just duplication of data? What's the use in sending an action if it's being sent to a specific page anyways?
|
# ? Jan 11, 2009 06:32 |
|
S is for a session key. Since you're logged in, you shouldn't see a session key.
|
# ? Jan 11, 2009 07:42 |
|
agscala posted:Why would you need to clarify what the action is (newreply) when it's being sent to newreply.php? Isn't that just duplication of data? What's the use in sending an action if it's being sent to a specific page anyways? Post preview is also newreply.php, since you haven't yet posted your new reply. There might be other actions handled by that page as well.
|
# ? Jan 11, 2009 09:18 |
|
agscala posted:Is this sending out 3 GET values, the first one named 's' and has no value? And just for clarification, it is sending at least 2 GETs: action and threadid, correct?
|
# ? Jan 11, 2009 20:48 |
|
drcru posted:S is for a session key. Since you're logged in, you shouldn't see a session key. You're not seeing a session key because it's in your cookies.
|
# ? Jan 11, 2009 23:22 |
|
I made a transparent hit counter deal for files, you go to url.com/files/image.jpg and htaccess intercepts that and bounces you over to a php script, url.com/filesupersystem/dl.php?file=image.jpg which goes and logs the ip time and referrer, then sends you the data from a non web accessible directory, making it impossible to leach without me knowing. Here is the (stripped down) code I'm using:php:<? $fullfile="mydirectory/$file"; if(file_exists ($fullfile)) { logstuff(); $mime=mime_content_type($fullfile); header('Content-type: $mime'); readfile($fullfile); }?> Is there a statistics package that I can just plug my gathered information into, which will then show me pretty pictures of my data? Simpler is preferred, I want to be able to spiff it up with ajax later. Might be a bit big for the megathread, but felt too small for a thread of it's own.
|
# ? Jan 12, 2009 04:02 |
|
|
# ? May 16, 2024 05:08 |
|
Battle Bott posted:It seems to work, but viewing things like flash movies forces a browser download rather than viewing it in browser... As I recall you can decide which of these behaviors you want by manipulating the header field. quote:and I don't know how it would handle very large files. (multi-hundered mb) I did this with <10 meg files and never had a problem. When I was implementing it I came across a remark, I believe on the PHP website, which claimed it was faster to read the file in chunks than to use readfile. I never noticed a difference, but then I never used really big files. quote:Is this a horrible idea? Can it be implemented better? It's fine on moderately sized sites. I can't comment for or against on very high traffic sites. I'm worried about your code, though. Lines like these: php:<? #url.com/filesupersystem/dl.php?file=image.jpg $fullfile="mydirectory/$file"; ?> Anyway, do you have a legitimate reason to be concerned about leeching? functional fucked around with this message at 04:20 on Jan 12, 2009 |
# ? Jan 12, 2009 04:07 |