Archive for the ‘Websites’ Category

h1

Redirecting using php

August 15, 2008

I was looking around today for ways to redirect the browser window, and I found a few interesting ones that may come in handy.

There is the standard way of sending the Header with a new location. This will immediately redirect the browser, meaning the redirect page is never seen. This can be a useful way for preventing unauthorized users from getting to a page you don’t want them to view (you should definately use die() or exit() to kill the script though, in case the redirect fails, and so that no data will be changed).
Header('Location:');

Note that Headers MUST be sent before any other data. Meaning that if you want to send headers it needs to be before any html or output (echo, printf ect).

The different, and more interesting, way that I discovered today is using Header to do a delayed redirect.
Header('refresh: 5, url="page.php"');

The number is the number of seconds before the refresh, and the url is the page you want to redirect to. This method will allow people view the content of the page before they are automatically redirected (to a download, away from a ‘Submission complete’ page ect).

h1

Div Containers with Floats: clearing

July 6, 2008

If you have ever tried to format a website using floating objects then you have no doubt run into a problem when a ‘container’ div doesn’t stretch to hold the floats. Instead, it has no height at all, pulling any objects below it up into your floated objects and messing up borders.

The popular (though messy) way to fix this is to add a
<div style="clear:both;"></div>to the bottom of the containers code. This gives the container some non-floated content (below the floated objects) and thus expands the size to the correct dimensions.

The main problem with this (from my point of view) is that it looks awfully messy, especially if you are creating a template. Having a bunch of empty divs lying around just seems like poor form.

Anyway, today I found a better solution – a much more thorough explanation of the issue (with pictures), the solution and why it works can be found at www.quirksmode.org.

Basically though, including:
overflow:hidden;
or
overflow:auto;
in the css for the container will force the container to expand to the correct size. You can also use ‘overflow:scroll’ but this will give you scroll bars in the container (which looks bad most of the time). (Using ‘hidden’ seems to be the best option because ‘auto’ can also cause scroll bars to appear in some browsers)

One line of CSS seems preferable to extraneous divs sitting around in the HTML.

h1

Obscuring email addresses from spammers

July 5, 2008

Today (and yesterday and the day before) I was working to upgrade a website’s defenses against spam-bots (web-spiders, bots, ect) which crawl the internets looking for email addresses to scoop up and add to their mailing lists.  Apparently people still don’t know they can buy viagra online (???).

Anyway, I ended up doing quite a bit of research into protecting my site, and those who entrust their emails to me, from spammers.  The site also suddenly began having a problem with bots filling out the ‘contact’ form and submitting it… repeatedly (like once every 2 minutes). Needless to say, this was very annoying. I came up with some solutions (most of these are modified from elsewhere) and some good websites with information about protecting your site.
Read the rest of this entry ?

Follow

Get every new post delivered to your Inbox.