• info@stefanynewman.info
 MENU

Swapping images over time intervals with JavaScript


This articles assumes you know what these stuff are:

1. variables;
2. arrays;
3. setInverval function;
4. document.getElementById;

You have a picture cromwell.png and you want it to change to charles.png every 4 seconds, just for the
heck of it. This is your HTML:


<img src="cromwell.png" id="static_image" />

Now, let's write the JavaScript
First, we call a function that will tell the browser
to do the stuff we want after the page loads:

window.onload = function(){
// our JS here
}

Next put our images cromwell.png and charles.png
in an array:

var images = new Array('charles.png', 'cromwell.png');

Then we get the ID of the element that holds the original
picture and that we want to set to change every 4 seconds:

var static_image = document.getElementById('static_image');

We declare the count variable "image_number" that will basically count
the number of the ... Read More

Super simple URL rewrite tutorial with .htaccess


Note: This article assumes you have a basic understanding as to what .htaccess files are, how they work and how to create one. And that you know how to use regular expressions.

When we were green programmers, we would create a website with these files:


index.php about.php contact.php


And when our visitors wanted to access a certain web page within our website, we would provide them with links to these documents directly like this:

www.example.com/about.php


However, all this above turned out to be the wrong way for many reasons. First of all, referencing web pages with their full name is not very secure because an evil user would know (a where "about.php" is located, b) that it ... Read More

Scope of the variable


Admit it - we all love global variables! You can access them in any part of your script without having to worry about "Undefined variable" warning in PHP, Perl and other programming languages.

However, let me quote a sentence from the book "Learning Perl":

"As experienced programmers have learned (often the hard way),limiting the scope of a variable to a page of code, or even to a few lines of code, really speeds along the development and testing cycle. "

So basically, even tho we love global variables, they are a) a security issue (we were not advised to switch off register_globals directive from the php.ini file by chance) and b) debugging becomes a pain in the ass because then the problem might be in every single ... Read More

JS Quiz


I have recently created a JavaScript quiz for my history website that I uploaded on my GitHub account - here

I am quite proud of it, when you click the wrong answer, the area becomes red and gives you an explanation and what was the correct answer to the question. I have always loved to do quizzes, I am very happy I finally had the power to create my own ... Read More

Short manual for storing passwords in the DB


If we want to create a login system for our website, we must absolutely store two types of
data - a username and a password. We store them in the database of our choice (be it MySQL, SQLite, MariaBD, whatever really),
and when the user wants to log in, they input their username and password and a script we had written earlier takes care of comparing whether the username
password that our user has just entered matches those in the database. If they do, we start a session, and we usually assign it the value of the user's ID.
And the user is now logged in. Sounds easy, eh?

Our first problem comes with our database design. Let's say we are using MySQL and we want to store the ... Read More

Programming good-to-knows 3


"Keep everything up to date, and you'll increase your security ... Read More

Programming good-to-knows 2


Taken from the book ... Read MoreWeb Services Essentials... Read More

... Read More Today, the principal use of the World Wide Web is for interactive
access to documents and applications. In almost all cases, such access is by human users, typically working through Web browsers, audio players, or other interactive front-end systems.
The Web can grow significantly in power and scope if it is extended to support communication between applications,from one program to another.

- From the W3C XML ProtocolWorking Group Charter ... Read More

For Loop


Best description ever of a for loop from the book "Learning Perl 5th edition"

for (initialization; test; increment) {
body;
body;
}

Programming good-to-knows 1


Taken from the book "Learning Perl 5th edition"

"It's important to remember that you're always writing code for two readers: the computer that will run the code and the human being who has to keep the code working.
If the human can't understand what you've written, pretty soon the computer won't be doing the right thing either."

I repeat these words every time I get too lazy to ... Read More

AJAX comment system done!


I finally made an AJAX comment system for my website www.studyingthepast.com and now when users comment on articles, their comments will appear without page reload, but straight away! I really can't understand why is it called AJAX anyways, it's just JS all the way and the only different thing about it is the server connection object and its properties and methods. I should probably include a comment system for this blog as well with the comments showing straight away too.

AJAX heart


I created kind of like a "base" for any AJAX application I might be creating in the future and uploaded it to my GitHub account. https://github.com/Stefany93/ajax-heart

Right now I am working on a comment system, that will allow the comment to appear when the user comments on a post, without the page having to be refreshed. Apparently you can do that with AJAX.
I guess I will create a separate page where the last inserted comment to the DB will be fetched and then my XMLHttpRequest object will connect to that page with the open() method and "bring" the comment back to the blog page thus abolishing the need the page to be reloaded when a user adds a comment. But that's just a draft ... Read More

The first programming language to learn


I believe that if someone wants to learn a web programming language, the best one to start with is HTML. Yes, I know it's a mark-up language language, not a programming one, it is the CORE of the web so it is basically the MOST IMPORTANT language of all! It's perfectly fine to start of with PHP or JS directly, but I am sure lots of people will get stuck since they wouldn't understand the core principles behind the web in general, or even if they succeed, it would be way more difficult than if they had started off with HTML ... Read More

How to increase all products' price in your OsCommerce store by 10 percent


Why would you want to do that? Maybe you are just greedy for more profit? Here is the MySQL query. Run it in the SQL console of your PHPmyAdmin control panel of your OsCommerce DB.

UPDATE products
SET products_price = products_price * ... Read More

Search for a certain column name in the entire MySQL DB


I was trying to locate a certain column name within my OsCommerce DB and I found this query by searching with google extremely useful for locating the name of the column in every table:

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('column1','column2')
AND TABLE_SCHEMA='DBname';

In my case, I replaced 'column1' with 'price_prefix' and 'DBname' with ... Read More

SEO


Stuff that search engine spiders won't read on your website:

1. Images

2. Flash Movies

3. JS

4. Frames (I know!)

5. Password-protected pages and directories ... Read More

A mandatory property for your container ID


When creating a website, 100% you would need a container ID inside a div element, to wrap up all of your content, otherwise it might look like spoiled broccoli. 99.9% of the time you would have floating elements in your page. By floating, I mean elements with the CSS property [b]float[/b].
So to avoid the container div to shrink in one tiny corner just because your navigation is set to float somewhere, add this property to your container div:

[b]overflow:hidden[/b]

That will remove the nasty effect float has to neutralize the width and the height of the wrapper of the floated ... Read More

Directory Listings


Turned out that direct access to the directories of a given website is a security risk, because an evil user will be able to see all of your files that you basically don't want them to see.
For example, if your website is www.example.com and you have a directory where you store all the images called "images", then the user could see all the images of your website by going to the www.example.com/images directory itself. Now, it looks like there is nothing wrong in that, but the laws of security are simple - "Never give your users access to stuff they don't actually need".
So it might seem harmless to allow your visitors to browse all of your images, but it isn't.

If your server is Apache ... Read More

Magic Quotes


Turned out that my hosting still had magic quotes enabled by default. And since I didn't have access to the php.ini file to change that directive, I just added this line in my .htaccess file:
"php_flag magic_quotes_gpc Off"

And it worked like ... Read More

PDO over mysql_* functions


I started using PDO in October last year - late, I know. A friend of mine recommended that I forget all about the mysql_* functions and start learning the newest technique for database communication. At first I was like "Yeah right, what could be better than the default PHP mysql library?"

Turned out, I couldn't be more wrong. PDO is simply amazing - I can't speak for mysqli, but from what I have heard, PDO is way better - it is almost 100% SQL injection free, no need to enclose the user input's variables with functions like "mysql_real_escape_string()" all the time and it has its own caching system. Plus, it is always getting updated.

PDO is way better than the standard mysql library ... Read More

JavaScript is bad for SEO


So I was reading a book about website optimization and stumbled upon the issue that search engines can't read Flash websites and Flash made content.
So far so good, but then I read that they can't index JavaScript written information either!
Of course, that seemed kind of obvious but I was nearly shocked.
They especially warned against JavaScript made navigation bars.
My poor JavaScript ... Read More

A Better Way To Store Passwords Using The CHAR Data Type


This article will explain better way to store passwords in a database.

Please note that we are talking about storing passwords, not stealing or anything. Lots people with no computer knowledge might get confused.
When storing short text into the database (DB) you can choose between two data types: VARCHAR and CHAR.
VARCHAR is slower but takes less space. CHAR is the opposite - it is faster but takes more space because when you define the text's length into
the CHAR data type it must be absolutely exactly same length of characters and since you are never sure how many characters a user's input might be
that makes the CHAR type the less likely choice. VARCHAR doesn't have this problem.
However, there is on exception where it is a ... Read More