# I've made a whatsbetter.com style web page.

**URL:** https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217
**Category:** Miscellaneous and Personal Stuff I Must Share
**Created:** [September 7, 2009, 11:33pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217 "2009-09-07T23:33:16Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 7, 2009, 11:33pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/1 "2009-09-07T23:33:16Z")

</div>

Using PHP.

It is really just an experiment in learning PHP. The rating system isn’t the best.

Basically ever time you click on one of the images two things happen.

Two more random images are presented to you.

A record is created in a pairings table for the two previous images. The one that won gets its ‘won’ score incremented. The one that didn’t doesn’t.

I hope to build on it and improve the rating system (helpful suggestions are welcome) but I don’t forsee it becoming a full blown replacement for [whatsbetter.com](http://whatsbetter.com) (in its original form) as there are probably massive copy write issues involved.  
Silly arse: I forgot to include the link!  
[notails.com - photography - Isle of Man](http://notails.com/whatsbetter.php)

---

<div class="post-metadata">

### Author: ![Amp](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Amp](https://boards.straightdope.com/u/Amp)
#### Post date: [September 7, 2009, 11:36pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/2 "2009-09-07T23:36:17Z")

</div>

I don’t see any images. I can still vote though.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 7, 2009, 11:54pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/3 "2009-09-07T23:54:41Z")

</div>

> [@Amp](#):
>
> I don’t see any images. I can still vote though.

Damnit. I should test on multiple browsers. It works in firefox.

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [September 7, 2009, 11:56pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/4 "2009-09-07T23:56:48Z")

</div>

Clever coding.

Inevitable critique: you could do with using a PHP thumbnailing routine to shrink the images - they’re feckin huge. Also all your animated stuff seems to be distorted - mashed up aspect ratio all over the shop. Would be good to see the top 10 too.

ETA: worked in Chrome from the UK.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 12:03am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/5 "2009-09-08T00:03:27Z")

</div>

> [@jjimm](#):
>
> Clever coding.
> 
> Inevitable critique: you could do with using a PHP thumbnailing routine to shrink the images - they’re feckin huge. Also all your animated stuff seems to be distorted - mashed up aspect ratio all over the shop. Would be good to see the top 10 too.
> 
> ETA: worked in Chrome from the UK.

I’m frantically trying to ‘fix’ it in ie so it’s probably going to keep breaking in different ways on different browsers as I try to fix it.

At the moment I’m trying the ‘auto’ css property for height, but it’s having no effect.

When I built it in firefox the aspect ratio on images and gifs was maintained.

ETA: I’ll probably work out how to do the thumbnailing tomorrow.

---

<div class="post-metadata">

### Author: ![GuanoLad](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/guanolad/32/42_2.png) [@GuanoLad](https://boards.straightdope.com/u/GuanoLad)
#### Post date: [September 8, 2009, 12:07am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/6 "2009-09-08T00:07:17Z")

</div>

I don’t think “auto” works for height. It’s usually used for margin alignment.

If you specify only a single dimension, the other will automatically be in the correct ratio.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 12:16am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/7 "2009-09-08T00:16:16Z")

</div>

> [@GuanoLad](#):
>
> I don’t think “auto” works for height. It’s usually used for margin alignment.
> 
> If you specify only a single dimension, the other will automatically be in the correct ratio.

Apparently not in IE. That’s why it doesn’t work in IE.

---

<div class="post-metadata">

### Author: ![Amp](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Amp](https://boards.straightdope.com/u/Amp)
#### Post date: [September 8, 2009, 12:22am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/8 "2009-09-08T00:22:14Z")

</div>

> [@Lobsang](#):
>
> Damnit. I should test on multiple browsers. It works in firefox.

Sorry, forgot to tell you what browser I am using. IE 8.

---

<div class="post-metadata">

### Author: ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)
#### Post date: [September 8, 2009, 12:26am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/9 "2009-09-08T00:26:55Z")

</div>

Advice:

You should not use URL GET parameters to record the votes for the images. A GET should never alter data in any way, because they can be bookmarked, copied-and-pasted, and crawled by robots.

So the proper way to do this is with a POST. But since you’re not using form inputs, you have to cheat a little to make the image links execute a form POST. The way you do that is by using some hidden inputs and a bit of Javascript.

Something like:

```auto

<script type="text/javascript">
function vote( winner, loser ) { 
    document.getElementById('winner').value = winner;
    document.getElementById('loser').value = loser;
    document.getElementById('voteform').submit();
}
</script>

<form method="POST" id="voteform">
<input id="winner" value="" type="hidden" />
<input id="loser" value="" type="hidden" />

<a href="javascript:vote( 1, 2 )"><img src="img1.jpg" /></a>
<a href="javascript:vote( 2, 1 )"><img src="img2.jpg" /></a>
</form>

```

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 12:35am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/10 "2009-09-08T00:35:46Z")

</div>

> [@Amp](#):
>
> Sorry, forgot to tell you what browser I am using. IE 8.

Not your fault. Mine for not testing on multiple browsers. I should know better I’m the friggin website content manager for an international gambling website. 🙂

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 1:06am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/11 "2009-09-08T01:06:11Z")

</div>

> [@friedo](#):
>
> Advice:
> 
> You should not use URL GET parameters to record the votes for the images. A GET should never alter data in any way, because they can be bookmarked, copied-and-pasted, and crawled by robots.
> 
> So the proper way to do this is with a POST. But since you’re not using form inputs, you have to cheat a little to make the image links execute a form POST. The way you do that is by using some hidden inputs and a bit of Javascript.
> 
> Something like:
> 
> ```auto
> 
> <script type="text/javascript">
> function vote( winner, loser ) { 
> document.getElementById('winner').value = winner;
> document.getElementById('loser').value = loser;
> document.getElementById('voteform').submit();
> }
> </script>
> 
> <form method="POST" id="voteform">
> <input id="winner" value="" type="hidden" />
> <input id="loser" value="" type="hidden" />
> 
> <a href="javascript:vote( 1, 2 )"><img src="img1.jpg" /></a>
> <a href="javascript:vote( 2, 1 )"><img src="img2.jpg" /></a>
> </form>
> 
> ```

Thanks, will try and incorporate that tomorrow.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 1:19am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/12 "2009-09-08T01:19:01Z")

</div>

Anyone got any experience with phpthumb? I’m having trouble getting it to work. the main site isn’t very helpful. I have uploaded it to my website and changed my urls acordingly…

src="…/phpThumb.php?\<?=$file2?\>&w=200"

(where file2 evaluates to the real valid filename)

but it doesn’t work.

I’ve tried several different things. Some produce a picture but it’s a picture of an error message saying ‘forbidden value’ in phpthum-config.php)

I’ve tried moving the phpthumb files around…

I first put them in public\_html/phpthumb

then I moved them to the next folder down.

then I moved the files out of the ‘phpthumb’ folder into the root.

to no avail.

How the frigg do I use this thing?

---

<div class="post-metadata">

### Author: ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)
#### Post date: [September 8, 2009, 1:43am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/13 "2009-09-08T01:43:35Z")

</div>

I’m not familiar with it, but are you missing a bit of your query there? Shouldn’t it be file=\<?filevar?\>&w=200?

Also, what does your source spit out as the src when you load the page?

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [September 8, 2009, 6:53am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/14 "2009-09-08T06:53:23Z")

</div>

Until you get PHPthumb working, I can promise you that “img width=100% height = 100%” isn’t going to work. For a start the spaces meant that the height attribute aren’t going to be recognised. I’ve never seen a % used in an image either. Just leave out the height and width altogether and it will default to the image’s natural size.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 3:28pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/15 "2009-09-08T15:28:04Z")

</div>

> [@ZipperJJ](#):
>
> I’m not familiar with it, but are you missing a bit of your query there? Shouldn’t it be file=\<?filevar?\>&w=200?
> 
> Also, what does your source spit out as the src when you load the page?

I think I just misquoted my code, because here is the line…

\<table width = 70% \>\<tr\>\<td width= 50% \>\<a href=“whatsbetter.php?winner=\<?=$random1?\>&loser=\<?=$random2?\>”\>\<img width=100% height = 100% src=“../phpThumb.php?=file\<?=$file1?\>&w=200” \>\</a\>\</td\>\<td width= 50% \>\<a href=“whatsbetter.php?winner=\<?=$random2?\>&loser=\<?=$random1?\>”\>\<img width=100% height = 100% src=“../phpThumb.php?=file\<?=$file2?\>&w=200” \>\</a\>\</td\>\</tr\>\</table\>

this is what the php spits out…

\<table width = 70% \>\<tr\>\<td width= 50% \>\<a href=“whatsbetter.php?winner=5&loser=9”\>\<img width=100% height = 100% src=“../phpThumb.php?=fileimages/nomming.gif&w=200” \>\</a\>\</td\>\<td width= 50% \>\<a href=“whatsbetter.php?winner=9&loser=5”\>\<img width=100% height = 100% src=“../phpThumb.php?=fileimages/044\_405\_1164875529.jpg&w=200” \>\</a\>\</td\>\</tr\>\</table\>  
aaaaand therein I see the problem! BRB

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 3:44pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/16 "2009-09-08T15:44:16Z")

</div>

Right. I got it working. But anigifs don’t animate, and if anything the page loads slower.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 5:47pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/17 "2009-09-08T17:47:11Z")

</div>

> [@friedo](#):
>
> Advice:
> 
> You should not use URL GET parameters to record the votes for the images. A GET should never alter data in any way, because they can be bookmarked, copied-and-pasted, and crawled by robots.
> 
> So the proper way to do this is with a POST. But since you’re not using form inputs, you have to cheat a little to make the image links execute a form POST. The way you do that is by using some hidden inputs and a bit of Javascript.
> 
> Something like:
> 
> ```auto
> 
> <script type="text/javascript">
> function vote( winner, loser ) { 
> document.getElementById('winner').value = winner;
> document.getElementById('loser').value = loser;
> document.getElementById('voteform').submit();
> }
> </script>
> 
> <form method="POST" id="voteform">
> <input id="winner" value="" type="hidden" />
> <input id="loser" value="" type="hidden" />
> 
> <a href="javascript:vote( 1, 2 )"><img src="img1.jpg" /></a>
> <a href="javascript:vote( 2, 1 )"><img src="img2.jpg" /></a>
> </form>
> 
> ```

Incorporated! Thanks very much for the code/help 🙂

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 8, 2009, 8:22pm UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/18 "2009-09-08T20:22:25Z")

</div>

There was a bug. Have now fixed.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 9, 2009, 1:25am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/19 "2009-09-09T01:25:36Z")

</div>

Another question for you fine expert people…

I have some upload code which I will add tomorrow. I find input sanitization to be a dark art so I have difficulty understanding the waffle about it. I have had the idea to ‘sanitize’ my uploader by adding the following to the filename input… “readonly=true”. It seems to work. I can pick a file but I can’t in any way edit the contents of the box.

My question is, could some unscrupulous person inject SQL by actually creating a file with a carefully designed filename (and also another file with the ‘valid’ filename so that the upload doesn’t break) such that he or she (probably he) could sucessfully inject sql into my database?

And another question… If I don’t place much value on the database or contents thereof does it really matter? Could an SQL injection do anything more than just mess with my DB?  
And finally. Here’s my code. Much of it is someone else’s (downloaded off the internet). So you can peruse it and see if anything stands out as being wrong…

```php

<?
if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";
$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "images/" . $imagename;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
$con = mysql_connect("localhost",<details removed from nosey or naughty people>);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("notailsc_pairs", $con);

mysql_query("INSERT INTO pending (filename) VALUES ( '$newimage' )");

echo "INSERT INTO pending (filename) VALUES ( '$newimage' )";

mysql_close($con);

}

}

?>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p><input type="file" name="image_file" readonly=true size="20"></p>
<p><input type="submit" value="Upload Image" name="action"></p>
</form>

<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>
";
}
}
?>

```

afterthought: As you may guess from the code, I have made this a ‘moderated’ upload. In other words the data goes into a table called ‘pending’ which I will check manually, and either approve or delete.

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 11, 2009, 1:00am UTC](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217/20 "2009-09-11T01:00:10Z")

</div>

I’ve added the uploader. (it’s a small texted link underneath the main pictures)

[Next page](https://boards.straightdope.com/t/ive-made-a-whatsbetter-com-style-web-page/509217.md?page=2)
