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
blitrig
Jul 2, 2003
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);

?>

Adbot
ADBOT LOVES YOU

Zorilla
Mar 23, 2005

GOING APE SPIT
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($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_HEADERfalse);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_USERPWDXML_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

blitrig
Jul 2, 2003

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

blitrig
Jul 2, 2003

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:
-<records type="array">
  -<record>
    <num>90210</num>
    <name>BeverlyHills</name>
</record>
</records>
Here's the empty XML tree:

code:
<records type="array"></records>
I dunno.

Zorilla
Mar 23, 2005

GOING APE SPIT
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.

blitrig
Jul 2, 2003

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.

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.

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

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
What's an effective way to use memcached to serve thumbnails and also have them be cached by the users browser?

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

:dukedog:

If this is Apache you can enable mod_expires.

I have an htaccess with something like this:

code:
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType application/x-javascript "access plus 172800 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType video/x-flv "access plus 2 seconds"
</IfModule>
Put it in the folder you want cached.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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?
php:
<?php
while ( ($target $source) === true ) {
    // do stuff
}
?>


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
}
?>
Some stuff on NULL and booleans: http://us3.php.net/NULL and http://us3.php.net/manual/en/language.types.boolean.php

Foreach: http://us3.php.net/manual/en/control-structures.foreach.php

Atom
Apr 6, 2005

by Y Kant Ozma Post

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.

Ferg
May 6, 2007

Lipstick Apathy

Atom posted:

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.

I believe isset( ) will also get the same effect.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

drcru posted:

If this is Apache you can enable mod_expires.

I have an htaccess with something like this:

code:
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType application/x-javascript "access plus 172800 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType video/x-flv "access plus 2 seconds"
</IfModule>
Put it in the folder you want cached.

Yes, but what about using memcached to serve them initially, and avoiding accessing the disk?

LP0 ON FIRE
Jan 25, 2006

beep boop
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?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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.

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?

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

LP0 ON FIRE
Jan 25, 2006

beep boop

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?

[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.

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.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



awdio posted:

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.

OK, but what does Flash get when you do $imageSourcesString=urlencode($imageSourcesString);?

LP0 ON FIRE
Jan 25, 2006

beep boop

Munkeymon posted:

OK, but what does Flash get when you do $imageSourcesString=urlencode($imageSourcesString);?

Same thing, still nothing.

blitrig
Jul 2, 2003

Zorilla posted:

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:


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:
<?php

$pagenum = 5;

[cURL magically goes through http://doopy/doo/doc.xml?page=(1-5) and puts them into array $blarg]

print_r($blarg);

?>
Been playing with loops and I can't figure it out. Probably because I'm retarded.

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

Grand_High_Took
Jul 9, 2002

Lawyers like to look pretty, too.
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
}
?>
Then in the next file:
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>";
}
?>
That gives us a printed value of $0.00 for the promo value string.

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>
?>
works just fine (except that it thinks that value of $my_order->promo_value is always 0). This seems to indicate that the values of $my_order->quantity and $unit_price are correct, so why does calculating ".1 * $unit_price * $this->quantity" give us a 0 when done from the Order constructor?

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!

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Grand_High_Took posted:

What the hell is going on here?

Please tell me what is up with this devilry, because this makes no sense to me at all. Many thanks!

Read this http://us2.php.net/variables.scope

LP0 ON FIRE
Jan 25, 2006

beep boop

awdio posted:

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.

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

Grand_High_Took
Jul 9, 2002

Lawyers like to look pretty, too.

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.

Standish
May 21, 2001

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:

$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.
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.

LP0 ON FIRE
Jan 25, 2006

beep boop

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.

LP0 ON FIRE
Jan 25, 2006

beep boop
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.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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.

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.

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

LP0 ON FIRE
Jan 25, 2006

beep boop

Lumpy posted:

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?

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

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

awdio posted:

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.

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.

LP0 ON FIRE
Jan 25, 2006

beep boop

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.
Sure

http://www.donnastangerphotography.com/dbFormat/indexTest.php?catNum=12

Little Brittle
Nov 1, 2004

Come visit me dawg
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.

LP0 ON FIRE
Jan 25, 2006

beep boop
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.

Ghotli
Dec 31, 2005

what am art?
art am what?
what.
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.

LP0 ON FIRE
Jan 25, 2006

beep boop

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:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<body>
<?php

$catNum=$_GET["catNum"];
echo $catNum;

//$catNum=12;

//connect and select db
include 'connect.php'; 
mysql_select_db("dataXXXXXX") or die(mysql_error());

$result = mysql_query("SELECT * FROM pictures WHERE catNum='$catNum' ORDER BY picOrder") or die(mysql_error());  

$filenames = array();

// Add the results to the arrays 
while($row = mysql_fetch_array( $result )) {
	array_push($filenames, "pictures/".$row['filename']);
} 


//create a string from the array with a pipe delimiter 
$imageSourcesString=implode("|",$filenames);

//echo "<td align='center' valign='middle' width='402'>".$imageSourcesString."</td>";

$descriptionString=0;

$pauseTime=200;
$fadeRate=8;

//$imageSourcesString="$imageSourcesString";

echo "<INPUT type = 'hidden' name = 'Page' value='&imageSourcesString=$imageSourcesString&pauseTime=$pauseTime&fadeRate=$fadeRate&sdd=$sdd'>";

echo $imageSourcesString;

?>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="400" height="222" id="flashPhotos" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flashPhotos.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#e5dec6" /><embed src="flashPhotos.swf" quality="high" bgcolor="#e5dec6" width="400" height="222" name="flashPhotos" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>



</body>
</html>
edit: FYI I changed some stuff around because I don't want people to know too much about the database, etc.

LP0 ON FIRE fucked around with this message at 01:34 on Jan 11, 2009

agscala
Jul 12, 2008

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:
http://forums.somethingawful.com/newreply.php?s=&action=newreply&threadid=2802621
I was curious what this part of the url is (the bolded section):
...?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?

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

:dukedog:

S is for a session key. Since you're logged in, you shouldn't see a session key.

Supervillin
Feb 6, 2005

Pillbug

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.

Zorilla
Mar 23, 2005

GOING APE SPIT

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?
That's exactly it. You'll see something like this every once in a while (epecially with search forms) when action="get" is used, which the browser knows to append all inputs as a query string when you hit the submit button. If a field gets left blank, they get added anyway as value=

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


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.

Battle Bott
May 6, 2007

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);
}?>
It seems to work, but viewing things like flash movies forces a browser download rather than viewing it in browser, and I don't know how it would handle very large files. (multi-hundered mb) Is this a horrible idea? Can it be implemented better? The whole idea behind this is to make the user experience transparent. Is there a better way?

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.

Adbot
ADBOT LOVES YOU

functional
Feb 12, 2008

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";
?>
make me skeptical of the security of your implementation.

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

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