Archive for the ‘Technology’ Category

php session/cookies failed on certain page

August 18, 2008 Leave a comment

Ever faced a situation where your supposed to be authenticated-by-session or cookie failed? it works initially, but on certain page, it fails.. and you don’t know what went wrong because you cold swear that the exact same piece of code works on the previous page but not on another page..!

Well, most probably here’s how your php authentication code look like, where you included it in every part of your php page, either using session or cookie. The example below uses session:

if ($_POST){

include (“dbconf.php”);    //the php file that contains the database settings
// query for a user/pass match
$result = mysql_query(“select status from login
where user='” . $_SESSION[‘user’] . “‘ and pass='” . $_SESSION[‘pass’] . “‘ “) or die (mysql_error());

Then the code above works for first page, second page… but on the 3rd page it returns an error. Or sometimes the session/cookie suddenly disappeared, and it returns invalid username/password! Let me tell you two thing:

1) The page before the session/cookie fails have a Submit button with the method set as POST.
2) Now let me tell you where it went wrong. See the line if ($_POST){ above? THAT’s WHERE it went wrong. Instead of writing only $_POST, you should write something like ($_POST[‘username’] || $_POST[‘password’]) or whatever your username and password box named in the previous page. Because if you wrote only $_POST, and a page has a Submit button with method POST, the line if ($_POST) will trigger and passes the now empty $_POST[“USER”] to $_SESSION[‘user’] since there are no input box named as USER or PASSWORD in the page (and even if they do, most probably it’s not meant for password authentication), and of course, the sql query below it will return an error since it now queries using an empty or wrong $_SESSION[‘user’] and $_SESSION[‘pass’]!

I faced the above problem because I tend to copy paste codes from supposed-to-be session tutorial. IMHO, it’s a bad practise to write a tutorial which can complicate matters in the future, although probably they only meant to simplify things.

In summary, here’s how your session authentication should look like:


if ($_POST[‘username’] || $_POST[‘password’])

Hope this post helps someone out there!

PHP “Cannot send session cache limiter – headers already sent” error

July 22, 2008 6 comments

I faced with this problem today, and Mr Google helped me to this site which helped me figure out how to solve the problem. Basically what the site says is “Make sure to check for and remove any spaces or carriage returns directly before or after your opening and closing php tags.” So for me, my problem is caused by this line:


<html><head><title>My Page</title></head>





and to fix it, I simply put both the include lines at the uppermost, which becomes like this:





<html><head><title>My Page</title></head>    <–see now the html code is brought down


Alhamdulillah, thank God the problem is solved just by doing this. Anyway this problem only surfaced when I uploaded my php code to my internet server. The same code doesn’t give any problem on my localhost server. Which I think I can conclude that the error will only appear on certain PHP/apache version.

Categories: Technology Tags: , ,

FileSystemObject in Visual Basic 6.0

April 11, 2008 5 comments

When you tried to declare Dim fso as FileSystemObject in your code and you get an error, most probably the only thing you need to do is go to Project > References. At the list of the available references, scroll down to ‘Microsoft Scripting Runtime (scrrun.dll)’ make sure it is checked (right symbol at the checkbox), and click OK.

Your code should be able to use FileSystemObject by now.

Again, hope it helps somebody.

Categories: Technology

Automatically minimize and hide form in VB.Net

April 4, 2008 13 comments

(Or minimize and hide form during startup..)

As per the title above.. perhaps for whatever reason, you’re trying to do it. Cause there was a time I need to do it.

Just add this line to your form_load

Me.WindowState = FormWindowState.Minimized

What it does is, everytime your form loads, it will be minimized and hidden. For me, the only way to see the form, is to click on the ‘Show’ button on the system tray. Because I even set the form’s ShowInTaskbar property to false.

Hope it helps somebody.

Fatal Error: Call to undefined function mysql_connect() – PHP5 doesn’t support MySQL by default??!!

April 1, 2008 11 comments

This is a follow-up of the post below. I boot up my computer today and tried logging into my PHP site. Nothing appears. Uh, uh. What could be the problem this time? Yesterday it was OK.

So I checked the Apache error log, and found this: “PHP Fatal error: Call to undefined function mysql_connect()”. What the….

Googled the problem, and it turns out that PHP 5 does not enable MySQL support by default. Uh uh.. what are they thinking? Why do they don’t automatically enable it like the previous PHP version? Do they think they own PHP? Uh uh.. oh well yes they do.. [Anyway here’s the link to the reasons why they decide not to enable and bundle MySQL by default].

So here’s what I did to remedy the problem, hope it will be of help to anyone out there.

  1. Tried adding the MySQL function through PHP’s Windows Add/Remove programs, but it seems the PHP installer doesn’t have this feature. So it seems the easiest is to uninstall PHP, and reinstall PHP back with the MySQL feature.
  2. So I run PHP installer, and choose to install all MySQL related function/libraries.
  3. Don’t forget to point Apache’s configuration file correctly (httpd.conf) when asked. Mine resides in “I:\Program Files\Apache Software Foundation\Apache2.2\conf”
  4. Complete the installation and restart your computer as suggested by the installer. That’s it.

Alhamdulillah, thank God. My PHP + MySQL + Apache works perfectly well now.

The only thing I hate is, usually all this kind of ‘small’ but annoying and important stuff tends to take a long time to be fixed. (I mean all the installing and uninstalling and restarting the computer part…)

Speed Up My PC 3.5 broke PHP?

March 31, 2008 2 comments

My PHP + Apache + MySQL program was working perfectly well, until I installed and run Speed Up My PC 3.5 which is supposed to, well, speed up my pc..

I then run my PHP site which has session enabled, but unfortunately it returns an error. Dang! Must be the Speed Up My software, since right before I installed that software, my site was running smoothly.

So I ended up uninstalling the software. And to make things sure, I also uninstalled and completely reinstalled PHP and Apache. I choose to install the newer PHP 5, as previously I was using PHP 4. And then my site starts working perfectly again…

*Some time ago I used a quite similar ‘optimization’ software, but it also ended up giving problems to my developed applications.. it seems that all this ‘optimization’ software is not for us programmers at all.

I posted my experience here, just in case somebody else faced similar problem.

p/s: For some reason, my site works OK only at this time. After I restarted my computer, problems came out again..[Please refer to the post just above this for detailed post about it.]