Posts Tagged ‘PHP’

Php copy .. failed to open stream: Permission denied in …

November 6, 2009 1 comment

Ever faced this problem when you’re trying to copy files using php? Well, as the error above said, you’re having a permission problem to access the source and/or destination file. I’ll describe two possible ways to overcome this problem:

1)If this problem happened on your local pc, you’ll just have to right click on the folder where the file resides, click Properties, and make sure the Read Only Attributes is not checked. Try running the code again.
2)If this problem happened on your internet(hosting) server, you’ll have to set the permission of the folder. If you’re using CPanel, go to File Manager, and browse to the parent directory of the folder, check (tick) the folder name, and click on the ‘Change Permissions’ button. Try enabling the folder’s Read, Write, and Execute for World and Group. Try running the code again.

For security reasons, after you’re sure that the code works, don’t forgot to tweak the permission settings so that only the minimal permission is granted. Sure you don’t want anyone out there to overwrite your files, don’t you?

Hope this post helps somebody out there!

Categories: PHP, Programming Tags:

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: , ,

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

April 1, 2008 12 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.]