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
bt_escm
Jan 10, 2001

willjo3 posted:

I'm having a problem using the php mail() function. I've been googling and experimenting for two days trying to figure it out to no avail.

Basically, I'm unable to send an email using the mail() function. The interesting part is that our company website (which we bought from a third party) uses the function and it works just fine. To make matters even more fun, my code works on another webserver. I've checked the php.ini sections on mail, and there dont seem to be any relevant differences.

Here is the relevant part of the company website that works:
code:
while(list($SID, $Email) = mysql_fetch_array($sql2)) {
				$unsubscribe_link = "<a href='$siteurl/obituaries.php?op=unsubscribe&Email=$Email'>here</a>";
				if(ereg("\[Unsubscribe_Link\]", $mailbody)) $mailbody = ereg_replace("\[Unsubscribe_Link\]", $unsubscribe_link, $mailbody);
					if((@mail($Email, $subject, $mailbody, $mailheader))) {
						//echo "<font color=green>Emailed to $Email</font><br>";
					} else {
						//echo "<font color=red>Email failed to $Email</font><br>";
					}
				}
			}
Any suggestions?

what is the value of $mailheader in the original script?

Adbot
ADBOT LOVES YOU

dancavallaro
Sep 10, 2006
My title sucks

duz posted:

Anything you roll on your own will likely be easy to defeat, use reCAPTCHA instead. They provide sample code and libraries to help integrate it.

This looks great, but because of the way this comment module is designed, I really just want a script that generates a captcha image - that would be the easiest solution. Is there a such thing as any library or script that generates pretty tough captchas?

iamstinky
Feb 4, 2004

This is not as easy as it looks.

bt_escm posted:

I have to question where you're getting the data from that you would need to sort it in php?

It is a combination of physical file data and stuff from db, sortable by the user as needed. As some of it isn't db related I can't let the DB sort the data for me. But if you have any suggestions, feel free to offer them.

functional
Feb 12, 2008

dancavallaro posted:

This looks great, but because of the way this comment module is designed, I really just want a script that generates a captcha image - that would be the easiest solution. Is there a such thing as any library or script that generates pretty tough captchas?

http://www.google.com/search?q=php+captcha+generator

er0k
Nov 21, 2002

i like ham.

Tap posted:

I'm writing a script to validate URLs, and one part of the script validation is a check to see if the document exists (i.e. seeing if there's a response). Is there a faster function to use than get_headers? For me, get_headers is extremely slow and I'm going to be validating thousands of URLs.

Try using fsockopen() or the cURL functions

such a nice boy
Mar 22, 2002

willjo3 posted:

I'm having a problem using the php mail() function. I've been googling and experimenting for two days trying to figure it out to no avail.

Basically, I'm unable to send an email using the mail() function. The interesting part is that our company website (which we bought from a third party) uses the function and it works just fine. To make matters even more fun, my code works on another webserver. I've checked the php.ini sections on mail, and there dont seem to be any relevant differences.

Any suggestions?

If it's a linux box, make sure sendmail is set up correctly. Here's some more information about setting up PHP mail correctly:

http://email.about.com/cs/phpemailtips/qt/et031202.htm

Treytor
Feb 8, 2003

Enjoy, uh... refreshing time!
I have a file upload script based on this - http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2293&lngWId=8

but I need it to remove spaces in the file names before it uploads it to the server. How would this be done?

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

:dukedog:

Use some regex on it? I'm sure a regex genius will post how to do this in a few mins.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


drcru posted:

Use some regex on it? I'm sure a regex genius will post how to do this in a few mins.

str_replace actually. He got a hold of me via IM and got it worked out.

bt_escm
Jan 10, 2001

Treytor posted:

I have a file upload script based on this - http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2293&lngWId=8

but I need it to remove spaces in the file names before it uploads it to the server. How would this be done?

To just remove spaces use this
php:
<?

   $string = str_replace(' ','',$string);

?>
regex is kind of a waste when you know exactly what you want to remove.

However if you are looking to make the filename safe for your file system then you should use a regular expression to replace any non-aplhanumeric characters like this
php:
<?

$string = preg_replace('/[^A-Za-z0-9\\.\\-_]/','',$string);
?>
This will remove anything that isn't a-z,0-9, a period,a dash or an underscore.

bt_escm fucked around with this message at 22:26 on Jun 17, 2008

bt_escm
Jan 10, 2001

iamstinky posted:

It is a combination of physical file data and stuff from db, sortable by the user as needed. As some of it isn't db related I can't let the DB sort the data for me. But if you have any suggestions, feel free to offer them.

Ok, the solution posted earlier will work. It's just unusual to have to sort a large block of data in php like that.

Treytor
Feb 8, 2003

Enjoy, uh... refreshing time!

duz posted:

str_replace actually. He got a hold of me via IM and got it worked out.

Yes. Thanks again! Also thank you bt for your input as well!

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

:dukedog:

So I want to write a small/simple/safe search engine for our MySQL database. How would I start this off?

The fields I want to search are varchar(64) and longtext.

Any specific links or tutorials?

Bruno_me
Dec 11, 2005

whoa

drcru posted:

So I want to write a small/simple/safe search engine for our MySQL database. How would I start this off?

The fields I want to search are varchar(64) and longtext.

Any specific links or tutorials?

Assuming you're using MyISAM, and you don't have more than 500,000 or so rows to search through, Fulltext indexes are the way to go. You pretty much add the index and write a query like this:

code:
SELECT * FROM `table` WHERE MATCH(column[,2ndcolumn...]) AGAINST('search terms');

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

:dukedog:

Bruno_me posted:

Assuming you're using MyISAM, and you don't have more than 500,000 or so rows to search through, Fulltext indexes are the way to go. You pretty much add the index and write a query like this:

code:
SELECT * FROM `table` WHERE MATCH(column[,2ndcolumn...]) AGAINST('search terms');

That was pretty easy to setup and it was fun. Thanks.

if wishes were knishes
Mar 5, 2006

Hi I'm Buddy-dot-gif
I believe there is a quicker/easier/faster way to do this, but I can't recall it to save my life.

php:
<?php
    $row_id 0;
    while ($row_id <= $foo['total_rows']) {
        $segment 'media/album/' $foo[$row_id]['id'];
        echo anchor($segment$foo[$row_id]['name']);
    $row_id++;
    }
?>

Am I doing it right?

Merkmerk
Aug 14, 2006

by Y Kant Ozma Post
Hey guys, I have a question regarding a google spreadsheet query using php.

The query expression on Google Spreadsheet in PHP is like this:

quote:

$name = 'John';
$query->spreadsheetQuery = 'name='.$name;

What I want to do is to search every record including 'John' NOT exactly 'John'.

I know how I would do this using a simple SQL query but I don't know how I would do this using php and google spreadsheets because I am not very familiar with either.

Any help would be GREATLY appreciated.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


slipfish posted:

I believe there is a quicker/easier/faster way to do this, but I can't recall it to save my life.

php:
<?php
    $row_id 0;
    while ($row_id <= $foo['total_rows']) {
        $segment 'media/album/' $foo[$row_id]['id'];
        echo anchor($segment$foo[$row_id]['name']);
    $row_id++;
    }
?>

Am I doing it right?

You could use a for loop or possibly a foreach loop instead.

illamint
Jun 26, 2005

According to The Oxford English Dictionary, the word "snapshot" was originally a hunting term.
How do you guys deal with really long SQL queries in your PHP code? I'm dealing with some fairly complex cross-table queries for a new app and I'm oscillating between
code:
$query = "SELECT ... "
       . "FROM ... "
       . "ORDER BY ...";
and just having the whole query by itself in a string. I don't see anything really wrong with my first method, assuming that the interpreter will interpret the string literal as a whole and not instantiate 3 string objects, concatenate them, and return a whole new string object. Is this an OK way of doing it?

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender

illamint posted:

How do you guys deal with really long SQL queries in your PHP code?

do this:
php:
<?
$query = "SELECT ...
          FROM ...
          ORDER BY ...
          ";
?>
It is sooooo much nicer than string concatenation.

Edit: Also, a pro-tip: When putting comma-separated things onto separate lines, put the commas at the start and line them up. That way you can easily see when a comma is missing, which is harder to do when commas go at the end. Plus, it's easier to add new lines to the end and not miss putting the comma in. Example:

php:
<?
$sql = "CREATE TABLE foo
            ( bar integer
            , baz string
            , wiz float
            , waz integer
            , PRIMARY KEY (bar)
            )
        ";
?>

minato fucked around with this message at 18:40 on Jun 19, 2008

such a nice boy
Mar 22, 2002

illamint posted:

I don't see anything really wrong with my first method, assuming that the interpreter will interpret the string literal as a whole and not instantiate 3 string objects, concatenate them, and return a whole new string object. Is this an OK way of doing it?

Even if it internally does that, why does it matter? Go for readability. Split it into as many pieces as necessary.

edit: drat, minato beat me and his answer is better.

Treytor
Feb 8, 2003

Enjoy, uh... refreshing time!
Could a PHP script be used to ping a server, and redirect to two different pages depending on whether the pinged server responds or not?

such a nice boy
Mar 22, 2002

Treytor posted:

Could a PHP script be used to ping a server, and redirect to two different pages depending on whether the pinged server responds or not?

Certainly.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Treytor posted:

Could a PHP script be used to ping a server, and redirect to two different pages depending on whether the pinged server responds or not?

PEAR Ping

Redirect with this

Un-l337-Pork
Sep 9, 2001

Oooh yeah...


slipfish posted:

I believe there is a quicker/easier/faster way to do this, but I can't recall it to save my life.

php:
<?php
    $row_id 0;
    while ($row_id <= $foo['total_rows']) {
        $segment 'media/album/' $foo[$row_id]['id'];
        echo anchor($segment$foo[$row_id]['name']);
    $row_id++;
    }
?>


As suggested above, maybe:

php:
<?php
   foreach($foo as $bar) {
      $segment 'media/album/'.$bar['id']
      echo ancher($segment,$bar['name']);
   }
?>

I think using the while version might be faster, though. So, it's a trade-off of slightly nicer code vs a couple of milliseconds of performance (or more maybe if you have some big array).

Un-l337-Pork fucked around with this message at 19:12 on Jun 19, 2008

blunt
Jul 7, 2005

I've been having a problem where the following is throwing out a syntax error and i for the life of me can't find the problem

php:
<?
$check = mysql_query("SELECT 'id', 'fname', 'lname', 'active', 'type' FROM 'users' WHERE 'email' = $email AND 'pass' = $pass") or die(mysql_error());
?>
I've tried just about every variation of ' placement, spaces and anything else i can think of but im sure its stupidly simple :(

Standish
May 21, 2001

blunt posted:

I've been having a problem where the following is throwing out a syntax error and i for the life of me can't find the problem

php:
<?
$check = mysql_query("SELECT 'id', 'fname', 'lname', 'active', 'type' FROM 'users' WHERE 'email' = $email AND 'pass' = $pass") 
    or die(mysql_error());
?>
I've tried just about every variation of ' placement, spaces and anything else i can think of but im sure its stupidly simple :(

Single quotes go around string literals, not around column names:
php:
<?
$check = mysql_query("SELECT id, fname, lname, active, type FROM users WHERE email = '$email' AND pass = '$pass'") 
    or die(mysql_error());
?>

blunt
Jul 7, 2005

Standish posted:

Single quotes go around string literals, not around column names:
php:
<?
$check = mysql_query("SELECT id, fname, lname, active, type FROM users WHERE email = '$email' AND pass = '$pass'") 
    or die(mysql_error());
?>

:psypop: I could swear to god i'd tried that but low and behold it works perfectly. Much appreciated :)

Treytor
Feb 8, 2003

Enjoy, uh... refreshing time!

fletcher posted:

PEAR Ping

Redirect with this

Thanks for this, but I am having problems getting PEAR to work with my web host, I think they may be blocking some functions required by PEAR to operate...

Is there any other option (preferably without requiring a framework?)

I found this script here: http://www.greenbird.info/xantus-webdevelopment/ping

Which seems to work on their site, but when I upload it and test on my own server, I'm getting a reported ping response from all servers, including the fake one...

Treytor fucked around with this message at 08:58 on Jun 22, 2008

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
I need to read 8-bit alpha channels from PNGs.

GD only supports 7-bit alpha channels, and the documentation says something to the effect of "why would you ever want to properly read PNGs 7-bits are plenty for an alpha channel :downs:" so I don't think they're going to add it any time soon.

Now, I have two choices that I'm aware of.

I can use ImageMagick (I'm assuming), but it's poorly(read: not) documented. So I don't even know if this is an option.

I can also parse the file data myself. This is the route I went, but again, I'm having trouble finding adequate documentation.
The official documentation is excellent in explaining how to read header data, separating chunks, etc.
As soon as it gets to reading IDAT information, however, it mentions decompressing it, and that's pretty much it.

My understanding from the documentation is that the data is formatted like this:
code:
[Filter method for scanline 1][R for pixel 1][G for pixel 1][B for pixel 1][A for pixel 1][R for pixel 2]...
[Filter method for scanline 2]...
But tests I've done on very small PNGs I've created myself have been completely different. Not in a recognizable pattern, either.


So, I guess I'm asking for a hint on any of the above. Maybe I've missed a hidden 8-bit alpha in GD, or an explanation of the png data format, or even a recommendation to try and puzzle out ImageMagick. Something like that.

gibbed
Apr 10, 2006

ante posted:

I need to read 8-bit alpha channels from PNGs.

GD only supports 7-bit alpha channels, and the documentation says something to the effect of "why would you ever want to properly read PNGs 7-bits are plenty for an alpha channel :downs:" so I don't think they're going to add it any time soon.

Now, I have two choices that I'm aware of.

I can use ImageMagick (I'm assuming), but it's poorly(read: not) documented. So I don't even know if this is an option.

I can also parse the file data myself. This is the route I went, but again, I'm having trouble finding adequate documentation.
The official documentation is excellent in explaining how to read header data, separating chunks, etc.
As soon as it gets to reading IDAT information, however, it mentions decompressing it, and that's pretty much it.

My understanding from the documentation is that the data is formatted like this:
code:
[Filter method for scanline 1][R for pixel 1][G for pixel 1][B for pixel 1][A for pixel 1][R for pixel 2]...
[Filter method for scanline 2]...
But tests I've done on very small PNGs I've created myself have been completely different. Not in a recognizable pattern, either.


So, I guess I'm asking for a hint on any of the above. Maybe I've missed a hidden 8-bit alpha in GD, or an explanation of the png data format, or even a recommendation to try and puzzle out ImageMagick. Something like that.
Are you on a host that will install extensions for you? Or have the capability to? There is an awesome extension called Imagick which provides an API to ImageMagick (and it's faster).

http://www.php.net/imagick

Here's a crappy example:
php:
<?
$image = new Imagick('image.png');
$width = $image->getImageWidth();
$height = $image->getImageHeight();

$iterator = $image->getPixelIterator();

foreach ($iterator as $y => $pixels)
{
    foreach ($pixels as $x => $pixel)
    {
        $color = $pixel->getColor(true);
        // color is an array like array('r' => ..., 'g' => ..., 'b' => ..., 'a' => ...)
        // passing true to getColor() returns them in floats,
        // so to get the 'real' value you just multiply the values by 255.
    }
        
    $iterator->syncIterator();
}?>
I currently use this for pulling out raw image data instead of rolling my own PNG code for reading Spore images.

It's crude but it works.


To answer your question about the PNG format:

All IDAT blocks are joined together as one block of data, this data is compressed with zlib, after you decompress it, you'll get an amount of data depending on the image settings in the IHDR. Your understanding of this data format is correct, each scan line has a filter type associated with it, this filter type determins how the data for that scanline is stored.

http://www.cs.toronto.edu/~cosmin/pngtech/optipng.html

Skip down to "2.2 The PNG delta filters".

gibbed fucked around with this message at 11:37 on Jun 22, 2008

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

gibbed posted:

To answer your question about the PNG format:

All IDAT blocks are joined together as one block of data, this data is compressed with zlib, after you decompress it, you'll get an amount of data depending on the image settings in the IHDR. Your understanding of this data format is correct, each scan line has a filter type associated with it, this filter type determins how the data for that scanline is stored.

http://www.cs.toronto.edu/~cosmin/pngtech/optipng.html

Skip down to "2.2 The PNG delta filters".
The problem I was having was that all of the stuff I've read is that that's how it works, but the decompressed data didn't seem to follow that format. Even without filters and on very small images, to ease reading.

Anyway. Looks like I won't need it if I use Imagick. Thanks. That's exactly what I was looking for.

passionate dongs
May 23, 2001

Snitchin' is Bitchin'
Really dumb question:

I'm outputting the results of a mysql query into a page and loading it into a javascript array. Right now it is essentially like this:

code:
var myArray = [ 
<? while(mysql results) {
  echo("{name: $result},");
} ?>
];
problem is, that there is always one stray comma at the end of the last entry into the array, which makes sense. Outside of writing some really bad code, I am fairly certain there has to be an easy way to output "a, b, c, d, e" instead of "a, b, c, d, e, "

The code works in IE/Firefox/Safari, but of course it produces javascript errors. What is an easy way to say "on the last record truncate the comma" ?

MrEnigma
Aug 30, 2004

Moo!

passionate dongs posted:

Really dumb question:

I'm outputting the results of a mysql query into a page and loading it into a javascript array. Right now it is essentially like this:

code:
var myArray = [ 
<? while(mysql results) {
  echo("{name: $result},");
} ?>
];
problem is, that there is always one stray comma at the end of the last entry into the array, which makes sense. Outside of writing some really bad code, I am fairly certain there has to be an easy way to output "a, b, c, d, e" instead of "a, b, c, d, e, "

The code works in IE/Firefox/Safari, but of course it produces javascript errors. What is an easy way to say "on the last record truncate the comma" ?

You could always do something like this (as long as it's an array):

code:
echo implode(' ,' $array);

passionate dongs
May 23, 2001

Snitchin' is Bitchin'

MrEnigma posted:

You could always do something like this (as long as it's an array):

code:
echo implode(' ,' $array);

this helped a lot and now I feel stupid, thanks!

Frocer
Feb 11, 2004
Big Slick
Does anyone have or know how to write a script that can grab popular IM online status? e.g. AIM, MSN, Yahoo, etc.

I figured out how to grab user's online status for AIM, but couldn't find anything for MSN, Yahoo, or others... any tips would be greatly appreciated!

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Treytor posted:

Thanks for this, but I am having problems getting PEAR to work with my web host, I think they may be blocking some functions required by PEAR to operate...

Email your host and ask them to fix this. If they don't, find a new web host.

MrEnigma
Aug 30, 2004

Moo!

fletcher posted:

Email your host and ask them to fix this. If they don't, find a new web host.

You usually can just manually include the PEAR files in your script if you can't run the actual pear software, basically the same thing. A lot of hosts won't use the extension, but it doesn't stop you from using the code.

such a nice boy
Mar 22, 2002

blunt posted:

:psypop: I could swear to god i'd tried that but low and behold it works perfectly. Much appreciated :)

Use a DB abstraction layer fer god's sake. You're just making life harder for yourself if you don't.

Adbot
ADBOT LOVES YOU

Safety Shaun
Oct 20, 2004
the INTERNET!!!1
I was using ip2c (free IP to country database) for a while until it broke. Even the new version keeps breaking, I pasted the errors on pastebin.

Has anybody experienced this too, or any idea why?

The PHP files DO point to the database files correctly, which confused me.

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