Anyone here good with PHP

Adam Munich, Sun Apr 10 2011, 02:54AM

I need some (probably minor) php help. Is anyone here good with PHP?
Re: Anyone here good with PHP
Adam Munich, Sun Apr 10 2011, 05:53PM

So, nobody here knows PHP?
Re: Anyone here good with PHP
Doubl3 Helix, Sun Apr 10 2011, 07:06PM

I've just started poking around with it as well. I guess if nobody else here offers up more help, maybe together we can figure it out? What kinds of problems are you having?
Re: Anyone here good with PHP
Nicko, Sun Apr 10 2011, 07:10PM

Grenadier wrote ...

I need some (probably minor) php help. Is anyone here good with PHP?
I've done a fair bit with it, though I'm rusty.

What do you need to know?

Re: Anyone here good with PHP
Adam Munich, Sun Apr 10 2011, 08:01PM

Well I decided to make a craigslist for electronics. Seeing as nobody else has tried to make one (except hackaday, but they did a poor job of it).

Link2

I ended up finding a nice PHP script online and I heavily modified the CSS and images to suit my likings. However the PHP script has a few issues:

*Large images >400kB will upload, yet thumbnails won't be made for them for some reason.
*There is no pagination, all the posts will show up on one page.
*There is no way to sort things by price; the only sorting going on is by date.
*Posts don't expire. They have timestamps but nothing deletes them after x amount of months, and that will clog up my server. The posts have timestamps so deletion might be easy to implement.

So... who thinks they can fix it? The last three should be easy fixes since all you are doing is re-arranging how the PHP displays the SQL database, but I know jack about PHP so I can't fix it.

I'm willing to give server access to those who think they can fix it (because if anyone decides to be a dick and change the password I could contact my server adnin and have him reset it)
Re: Anyone here good with PHP
Carbon_Rod, Sun Apr 10 2011, 09:21PM

PHP4 and PHP5 OO design are quite different.
Please post output from this code:
<?php phpinfo(); ?>

Note the maximum execution time, and memory limits.
Also remember the XSS attacks usually start with file uploads, and all images should be "watermarked" to check if it is really an image (trap an error flag, as content related to these IP are likely spam too).

I know about 28 different language lexicons (with countless dialects), and use PHP codeIgniter for quick remote server interfaces. SWiG wrappers are really handy for creating interfaces for C/C++ hardware drivers etc.

In my opinion, Craigslist is a horrible site as it is filled with too many scams, and still has no effective system of accountability.
=)

Cheers,
Rod
Re: Anyone here good with PHP
Adam Munich, Sun Apr 10 2011, 11:21PM

WAT.

I told you, I know absolutely nothing about PHP, it looks like swahili to me. Nonetheless I made that info page: Link2

And craigslist is a pretty good site IMO, it's often easy to tell who's a scammer. And with online money systems like google checkout and gaypal it's easy to get your money back if someone scams you.
Re: Anyone here good with PHP
Carbon_Rod, Mon Apr 11 2011, 02:58AM


Locate your php.ini file (like /etc/php5/apache2/php.ini) and edit the following configuration
(or override the defaults by placing a php.ini text file in a shared sever root web directory):

max_execution_time = 300
max_input_time = 60
upload_max_filesize = 8M
post_max_size = 16M
#and add or check if...
expose_php = Off
register_globals = Off
allow_url_fopen = Off

#Optional hide of Apache signature in /etc/apache2/apache2.conf
ServerTokens Prod
ServerSignature Off

Remember to restart your web server to propagate any changes:
sudo /etc/init.d/apache2 restart


Also, keep the number of concurrent file upload slots at 20 to reduce potential DoS issues.

Good luck,
Rod
Re: Anyone here good with PHP
Nicko, Mon Apr 11 2011, 07:37PM

Carbon_Rod wrote ...


Locate your php.ini file (like /etc/php5/apache2/php.ini) and edit the following configuration
(or override the defaults by placing a php.ini text file in a shared sever root web directory):
...
All good advice - more current than my PHP knowledge...
Re: Anyone here good with PHP
Adam Munich, Tue May 03 2011, 01:45AM

Well the person who was fixing it for me disappeared, so now I'm stuck again.

*Large images >400kB will upload, yet thumbnails won't be made for them for some reason.
The reason is line 174 of inc_thumbnail.php. It uncompresses the images and fills up the ram, 300kb image goes to 40MB, so that's no good.

*There is no pagination, all the posts will show up on one page.
Still not fixed.

*There is no way to sort things by price; the only sorting going on is by date.
This was fixed.

*Posts don't expire. They have timestamps but nothing deletes them after x amount of months, and that will clog up my server. The posts have timestamps so deletion might be easy to implement.
This was partialy fixed using a "scheduled task" php script, Link2 but it does not delete the post's associated image.


So, I'm still looking for some help and I'll give server access to those who think they can fix it. I really want to get this craigslist thing going, it could prove to be very useful.

Re: Anyone here good with PHP
Carbon_Rod, Tue May 03 2011, 04:39AM

Yep,
ironically on craigslist there are at least a dozen kids trying to get people to work for "shares" of a company. Now even if people ignore the fact that 50% of $0 is still $0, they are unlikely going to stick around very long with student-debt in this market. =P

Although not recommend for production environments, you could try it with:
allow_url_fopen=On
allow_url_include=On

Then read this:
Link2
Re: Anyone here good with PHP
Adam Munich, Tue May 03 2011, 05:24AM

Once again, I am a complete n00b with php. I don't even know what is going on in that scheduled task...
Re: Anyone here good with PHP
Myke, Tue May 03 2011, 06:40AM

Because you are a n00b doesn't mean you can't learn. Link2

Everyone has to start somewhere. Start with something simple at first to get the feel of how things work and then work from there.
Re: Anyone here good with PHP
Adam Munich, Sun May 08 2011, 12:39AM

The thing is I need to see it in action to learn how to do it. I'm kinda figuring it out though, and the only thing that is left to do is fix the image upload issue.

However I can't seem to fix this problem; there is some blackspace above everything on the index page Link2 and I have no clue what is causing it. There is no space viewitem Link2 and postsomething Link2

wat do.

Edit: Turns out it was a simple css issue, my divs were all messed up. angry
Re: Anyone here good with PHP
Adam Munich, Tue May 17 2011, 06:13AM

Alright, so I finally have everything fixed! Link2

....except for the image issue. It needs a new image upload and thumbnail making system, and while I am learning a bit about php I still can't figure out how to implement one. I installed GD library but I'm not sure how to make it work with the database and stuff. Anyone want to take a shot at it? (please)
Re: Anyone here good with PHP
Carbon_Rod, Wed May 18 2011, 01:32AM

@Grenadier, test your CSS in IE6/IE7 before claiming victory over the bugs... ;-P

<?php
/* First create a sub path 'img' with a RGB jpeg file called 'some_full_size.jpg' */

/* Try this block of test code, and note the system file path is not a URL */

//get a cleaned file name from ...
$imageName=preg_replace( '/[^A-Za-z0-9]/i','_', 'some_full_size');
//create some file resource paths
$fileName=getcwd() . '/img/'.$imageName.'.jpg';
$iconFileName=getcwd() . '/img/'.$imageName. '.icon.jpg';
//width of final image
$iconWidth=120;

if(file_exists($fileName))
{
// load image and get image size
$img = imagecreatefromjpeg( fileName);
$width = imagesx( $img );
$height = imagesy( $img );

// calculate thumbnail size
$new_width = $iconWidth;
$new_height = floor( $height * ( $iconWidth / $width ) );

if($new_height > $iconWidth)
{
$new_height = $iconWidth;
}

// create a new blank image obj
$tmp_img = imagecreatetruecolor( $new_width, $new_height );

// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

// save thumbnail into a file
imagejpeg( $tmp_img, $iconFileName, 88 ); //88% image quality

//free the objs
imagedestroy($img);
imagedestroy($tmp_img);
}
$dhtml= '<img src="img/"'.$imageName.'.jpg" alt="'.$imageName.'"/>'.
'<img src="img/"'.$imageName.'.jpg.icon.jpg" alt="'.$imageName.' icon"/>';

echo $dhtml;

?>

Cheers,
Rod
Re: Anyone here good with PHP
Adam Munich, Thu May 19 2011, 12:32AM

Yay it works! I'm beginning to understand how the mysql database works, and all that is left to fix is to make sure that images get deleted when people delete the posts. I put this in action.php:



However it gives me this error;

Warning: unlink() expects parameter 1 to be string, resource given in /home/teravolt/public_html/junkbox/action.php on line 29

Warning: unlink() expects parameter 1 to be string, resource given in /home/teravolt/public_html/junkbox/action.php on line 31

How would I convert the resource to a string? I can't seem to find any information on the interwebs regarding how to do that.

Re: Anyone here good with PHP
Carbon_Rod, Thu May 19 2011, 01:32AM

mysql_query() returns a resource object, and not a string path name...
Link2

Re: Anyone here good with PHP
Adam Munich, Thu May 19 2011, 02:11AM

Is there a way to return a string from the mysql database?
Re: Anyone here good with PHP
Carbon_Rod, Thu May 19 2011, 02:34AM

imageurl = mysql_query(" ..foo.. LIMIT 0,1"); //grab only one record

while ($row = mysql_fetch_assoc($result)) { //process each returned result
$strTempName = preg_replace( '/[^0-0a-zA-Z\-\+\_]/i','',$row['imgURLThumb'] ); //get image name
unlink( getcwd() . '/img/' . $strTempName . '.jpg'); //force clean file path and name
}


You should read the samples on the posted link...
Re: Anyone here good with PHP
Adam Munich, Thu May 19 2011, 04:02AM

I had no clue what was going on there ^^ so I came up with this:

if ($action == "delete")
   { 
   	   $sql = "SELECT imgURL FROM md_postings WHERE confirmPassword='$confirmPassword'";
   	   $result = mysql_fetch_array(mysql_query($sql)) or die();
       foreach($img as $var)
         {
		   $img = $var;
		   unlink($img);		
	     }
  	   
  	   $sql = "SELECT imgURLThumb FROM md_postings WHERE confirmPassword='$confirmPassword'";
   	   $result = mysql_fetch_array(mysql_query($sql)) or die();
       foreach($img as $var)
         {
	       $img = $var;
		   unlink($img);		
         }

Seems to work. smile
Re: Anyone here good with PHP
Platinum, Mon Jun 06 2011, 07:38AM

I am, I can code, very good at:

VB.NET

PHP

Javascript

And I own multiple mybb forums, PM me.
Re: Anyone here good with PHP
Adam Munich, Mon Jun 06 2011, 06:20PM

Actually I got it sorted out myself,

Link2

Need to put that translate button in the right place though...