Thursday, November 12, 2009

Sessions and computer clocks

We have recently had a situation where a user on one of our websites simply could not log in. All other computers worked except his and it was very frustrating to troubleshoot.

What I finally discovered was that he had recently changed his computer clock (to the wrong time). So the PHP session was working perfectly fine, just each time he logged in, the session compared the time to his computer and determined that his session had expired.

In conclusion, if you ever have a situation where you cannot log into a website (and you were able to do so before), please check that your computer clock is accurate as well as confirming your username and password.

Tuesday, August 18, 2009

OTF FEO website

Darkstar Media is pleased to announce the launch of the new OTF/FEO website (Ontario Teachers Federation www.otffeo.on.ca). We worked in partnership with The Exclusive Group (www.exclusivegroup.ca) to help plan and develop this website. Some of the features include a content management system for managing some of the content and RSS feeds in English and French. We are currently working on a booking system for online reservations for their campground. More info to follow.

Tuesday, June 9, 2009

SEO progress

Great news, the work I have put into my website over the last few months is starting to pay off.  My page ranking is now second if you search Toronto database development in google. Another search term which is working for me is Toronto CMS. I did all this without paying for advertising. I just used relevant copy and proper page titles and descriptions. if you need any tips, feel free to message me or contact me through my website http://www.darkstarmedia.net.

Monday, June 1, 2009

Pagination Upgrade

Hello,

Please refer to my older threads regarding pagination. I have now added a back and next button to the code.

 

<?php if ($totalRows_Recordset_paging > $number_per_page) {  


// this is my display
$i = 1;

// this is for the BACK button (next 5 lines)
if($whichpage == 1) { } else {
$previouspage = $whichpage - 1;
echo "<a href=brand_new.php?dept=" . $dept . "&whichpage=" . $previouspage . " class=pagelink><<></a>>";
}


while ($i <= $amountofpages):

if($whichpage == $i) {
echo "" . $i. "";

} else {
echo "<a href=brand_new.php?dept=" . $dept . "&whichpage=" . $i . " class=pagelink>" . $i. "</a>";
}



$i++;
endwhile;

// this is for the NEXT button  (next 5 lines)
if($whichpage == $amountofpages) { } else {
$nextpage = $whichpage + 1;
echo "<a href=brand_new.php?dept=" . $dept . "&whichpage=" . $nextpage . " class=pagelink>NEXT >></a>";
}


?>
    
   

Friday, May 8, 2009

mysql_pconnect Dreamweaver

I have recently troubleshooted a bug I have had for years. Dreamweaver by default uses mysql_pconnect when connecting to databases and this is considered bad practice for websites, (more info here http://ca3.php.net/function.mysql-pconnect ) Most servers only have a certain amount of connections and mysql_pconnect uses them all up and freezes database driven websites. The errors I would get were... Occasionally users would get a php error "Too Many Connections" when accessing a database driven page. The bug that drove me crazy for years was that my own computer would have too many connections open to the same web server and when I tried to test the PHP pages I built, they would freeze.. but it would not happen if I used another computer or tested the code on another website. And when I brought this problem to user forums, no one had a clue...
You should use mysql_connect and it is very easy to change in the connection code and does not break anything. You can simply open your connection file and change it (change mysql_pconnect to mysql_connect).


..or use this little trick I learned from the Abode support forum...

Locate the following file: C:\Program Files\Adobe\Adobe Dreamweaver CS4\configuration\Connections\PHP_MySQL\Connection_php_mysql.js. On a Mac, it should be in the same location in the Applications folder.

connParams.variables["$" + connParams.cname] = "mysql_pconnect(\"" + connParams.hostname + "\",\"" + connParams.username + "\",\"" + connParams.password + "\")";

Change it to this:

connParams.variables["$" + connParams.cname] = "mysql_connect(\"" + connParams.hostname + "\",\"" + connParams.username + "\",\"" + connParams.password + "\")";

Just to be clear the only thing that has changed is mysql_pconnect is now mysql_connect (removed the p).


In the same folder, you should find connection_includefile.edml. Open that, and change mysql_pconnect in line 12:

$@@cname@@ = mysql_pconnect($hostname_@@cname@@, $username_@@cname@@, $password_@@cname@@) or trigger_error(mysql_error(),E_USER_ERROR);


By doing the above steps, your dreamweaver will by default use mysql_connect.

Thursday, April 30, 2009

CSS page selected with PHP

Hello,

I developed a nice little php function for having a CSS hyperlink have a different style if you are on the hyperlinks page. You can also make this much more complex with features such as making the hyperlink inactive if you are on the page and of course more styling of the fonts

PHP function (put this on the page or in a PHP include file)

function WhichPage($thepage)
  {
// this gets the name of the php page you are presently on
$page = basename($_SERVER["PHP_SELF"]); 

if ($page == $thepage) {
// style for selected state 
  echo "menu_selected";
  
} else {
// default style 
 echo "menu"; 
}
}


CSS style (customize as you wish)

A.menu:ACTIVE, A.menu:FOCUS, A.menu:LINK, A.menu:VISITED {
color : #e87d1e;
font-family : Verdana, Helvetica, sans-serif;
}

A.menu:HOVER {
color : #54b948;
font-family : Verdana, Helvetica, sans-serif;
}


A.menu_selected:ACTIVE, A.menu_selected:FOCUS, A.menu_selected:LINK, A.menu_selected:VISITED {
color : #54b948;
font-family : Verdana, Helvetica, sans-serif;
}
A.menu_selected:HOVER {
font-family : Verdana, Helvetica, sans-serif;
color : #e87d1e;
}



HTML MENU (customize as you wish)

// HTML:  be sure to send the page name in the function, i use include files for my menu  (I have one file which controls the menu for every page in the website) so i need to specify here.
<a href="about_staff.php" class="<?php WhichPage("about_staff.php"); ?>"> Staff </a>

Thursday, April 23, 2009

Dreamweaver and md5

I started out my PHP programming years relying heavily on dreamweaver to do my database coding. At the beginning I was  restricted in my abilities to what dreamweaver was capable of doing, yet over the years  my abilities grew and I now only use it to do the repetitive grunt work.

One thing I could never figure out was how to create encrypted password security systems using dreamweaver and I just figured it out using md5 and it is a piece of cake. I am posting it because I could not find it on google and thought other people like me could be looking for the code. I am using Dreamweaver CS4 at this time, but I don’t think that will matter.

For this tutorial, simply use Dreamweaver to build your username/password insertion page and login page as normal and I will show what you need to modify to make it work.On to the code…


The code that inserts passwords into the database…..

$insertSQL = sprintf("INSERT INTO `admin` (admin_name, admin_pass, admin_level) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['admin_name'], "text"),
                       GetSQLValueString(md5($_POST['admin_pass']), "text"),
                       GetSQLValueString($_POST['admin_level'], "int"));

 

As you can see, I simply inserted md5 with a new bracket around it…. That’s it, it is inserted into DB as md5

 

The Login page

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=md5($_POST['password']);
  $MM_fldUserAuthorization = "admin_level";
  $MM_redirectLoginSuccess = "login_good.php";
  $MM_redirectLoginFailed = "login_bad.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_mine, $mine);
             
  $LoginRS__query=sprintf("SELECT admin_name, admin_pass, admin_level FROM `admin` WHERE admin_name=%s AND admin_pass=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  
  $LoginRS = mysql_query($LoginRS__query, $mine) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
   
    $loginStrGroup  = mysql_result($LoginRS,0,'admin_level');
   
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;           

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];           
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

this is a standard Dreamweaver generated login page, on this line   $password=$_POST['password']; , again I simply inserted  md5 and the bracket - $password=md5($_POST['password']);


Thats it, Dreamweaver and md5, piece of cake

Wednesday, April 22, 2009

Pagination Update

I found a bug in my pagination code, if I had an amount of results which was a multiple of the amount to display per page, i got an extra page link which had no results

So i am using the ceil function now instead on the round function, this fixes the problem

$amountofpages = ceil($totalRows_Recordset_paging / $number_per_page);

I also modified it to have a "selected" page state for the very first page.. this was done by adding.

$whichpage = $_GET['whichpage'];

full code below...
Also, im sorry but blogger wont let me write HTML code, so i used a very long way to display my link at the bottom

$id = $_GET['id']; // this is a variable unrelated to the paging, but used for the data display
$whichpage = $_GET['whichpage']; // this tells us which page we are on

// checking to see what page we are on and what results we should display
if(!$_GET['whichpage']) {
$thepage = 0; 
$thepage_final = 0;
} else {
$thepage = $_GET['whichpage'];
$thepage_final = $thepage - 1; 
}

$number_per_page = 6; // how many results we should display per page
$startnumber = $thepage_final * $number_per_page; // which number to start the new record display from

// recordset to display results
mysql_select_db($database_mine, $mine);
$query_Recordset_shoelist = "SELECT * FROM shoes WHERE shoes_cat = $id ORDER BY shoes_name ASC LIMIT $startnumber, $number_per_page";
$Recordset_shoelist = mysql_query($query_Recordset_shoelist, $mine) or die(mysql_error());
$totalRows_Recordset_shoelist = mysql_num_rows($Recordset_shoelist);

// recordset for paging
$query_Recordset_paging = "SELECT * FROM shoes WHERE shoes_cat = $id ORDER BY shoes_name ASC";
$Recordset_paging = mysql_query($query_Recordset_paging, $mine) or die(mysql_error());
$totalRows_Recordset_paging = mysql_num_rows($Recordset_paging);


// i round this up to have even amount of pages
$amountofpages = ceil($totalRows_Recordset_paging / $number_per_page);




// this is my display, inserted in the HTML wherever you want the page numbers to display 

$number_per_page) { ?>
PAGE:

// this is my display

$i = 1;
while ($i <= $amountofpages):

if($whichpage == $i) {
echo "" . $i. ""; 
} else {
echo "<" ' "a href=brand_list.php?id=" . $id . "&whichpage=" . $i . "&id2=" . $id2 . " class=pagelink>" . $i. "<" . "/" . "a>";
}


$i++;
endwhile;
?>


Thursday, April 2, 2009

New site: sonnygalea.com

Darkstar Media in partnership with Sonny Galea launches sonnygalea.com. This is a great site for a photographer with a complete CMS (content management system) which allows the client manage their own photo gallery.

View it here www.sonnygalea.com

Wednesday, April 1, 2009

New site: events.hemophilia.on.ca

Darkstar Media in partnership with Hemophilia Ontario launches events.hemophilia.on.ca. This website is used to collect donations for Hemophilia Ontario and more specifically for the Biking to Stop the Bleeding Event and the Annual Golf Tournaments.

View it here events.hemophilia.on.ca

Friday, March 6, 2009

I just joined linkedin.com

I just joined linkedin.com and was impressed on how many of my friends and collegues were already on the website. I will be following it closely to see if it will generate any business leads or increase traffic to my website. As soon as I joined and added my address book, 10 people were automatically added to my contacts and my inbox has been a steady stream of people joining my network.

Better too late than never for joining this website, there are so many social networking web sites, it is hard to decide which are worthwhile. So far, this one seems to be worth it.

Tuesday, February 17, 2009

SEO progress, week 1

One of the main reasons I have started this blog is to help increase search engine ranking and traffic to my website (www.darkstarmedia.net). I plan on tracking my progress and keeping all my readers up to date on our results. Last week I had an average of 7 visits per day and I suspect most of them were from me.

Many years ago I had could come up on the first page of yahoo and google with different combinations of Toronto, design, freelance, ect. Then about 4 years ago I switched my website to Flash and soon dropped off the map as far as search engines were concerned. Other factors could have been that I stopped adding my link into the websites I had built as I started to do more sub contract work, and websites for large corporate clients which wouldn’t allow my link in the footer.

So with that bit of history behind us I will explain what I have done in the past few weeks in my attempt to increase traffic. The first step was a website redesign using CSS (Cascading Style Sheets) and adding better meta tags. The website is now text based and search engine readable. I installed Google Analtycs to track my traffic sources and Google Webmaster tools to help refine my content and keywords. I added some web 2.0 features such as an RSS feed and this blog, from what I have learned the blog will be very beneficial to search-ability and page rankings.

I have never gotten business from random clients finding me on search engines, my business has grown from word of mouth and I have been quite satisfied with that. This is a long term experiment and when it is proven to be successful, it will be a service I will offer to clients. Please drop in and watch our progress.

Friday, February 13, 2009

Pagination Code

Welcome to the Darkstar Media Blog.

Here is a nifty piece of code I wrote last week for php pagination. What is "pagination" you might ask.  For me, it is a system of numbering pages for searching and displaying database results which are too much to display on one page. Basically, you break it up into multiple pages.


$id = $_GET['id']; // this is a variable unrelated to the paging, but used for the data display
$whichpage = $_GET['whichpage']; // this tells us which page we are on

// checking to see what page we are on and what results we should display
if(!$_GET['whichpage']) {
$thepage = 0; 
$thepage_final = 0;
} else {
$thepage = $_GET['whichpage'];
$thepage_final = $thepage - 1; 
}

$number_per_page = 6; // how many results we should display per page
$startnumber = $thepage_final * $number_per_page; // which number to start the new record display from

// recordset to display results
mysql_select_db($database_mine, $mine);
$query_Recordset_shoelist = "SELECT * FROM shoes WHERE shoes_cat = $id ORDER BY shoes_name ASC LIMIT $startnumber, $number_per_page";
$Recordset_shoelist = mysql_query($query_Recordset_shoelist, $mine) or die(mysql_error());
$totalRows_Recordset_shoelist = mysql_num_rows($Recordset_shoelist);

// recordset for paging
$query_Recordset_paging = "SELECT * FROM shoes WHERE shoes_cat = $id ORDER BY shoes_name ASC";
$Recordset_paging = mysql_query($query_Recordset_paging, $mine) or die(mysql_error());
$totalRows_Recordset_paging = mysql_num_rows($Recordset_paging);


// i round this up to have even amount of pages
$amountofpages = ceil($totalRows_Recordset_paging / $number_per_page);




// this is my display, inserted in the HTML wherever you want the page numbers to display 

$number_per_page) { ?>
PAGE:

// this is my display

$i = 1;
while ($i <= $amountofpages):

if($whichpage == $i) {
echo "" . $i. ""; 
} else {
echo "<" ' "a href=brand_list.php?id=" . $id . "&whichpage=" . $i . "&id2=" . $id2 . " class=pagelink>" . $i. "<" . "/" . "a>";
}


$i++;
endwhile;
?>


I hope this is commented well enough for someone to understand. The next post will hopefully be on art or something not so dry as PHP code.