| Subcribe via RSS

nested include/require not working php5.2

February 13th, 2008 | 1 Comment | Posted in php by dreamluverz


Suddenly happened to my scripts, some includes are not working after reconfiguring the server. According to this site w/c encountered the same issue nested includes don’t work in php5.2

I am not able to use includes or requires in nested files using php 5.2.3
(osx)

Including or Requiring files directly works.

Including files, that also have includes in them, does not.

Say you have this…

-TopDirectory
–index.php (contains include(”includes/top.php”); )
–includes (folder)
—config.php (contains echo “crap”; )
—top.php (contains include(”config.php”); )

When you load the index.php file you would expect the word “crap” to show,
but it does not. I think the getcwd is staying specific to the top folder,
so the path stays the same throughout.

This does not happen in 5.1.6

Is there a fix for this or is it PHP causing the problem?


Mike Yrabedra B^)>

Tags: , , , , , ,

differences of $_SERVER[’PHP_SELF’] - $_SERVER[’SCRIPT_NAME’] - $_SERVER['REQUEST_URI']

January 23rd, 2008 | No Comments | Posted in php by dreamluverz

$_SERVER[’PHP_SELF’], $_SERVER['REQUEST_URI'], and $_SERVER[’SCRIPT_NAME’] all behave in similar ways, they return information about what file is being used. When exposed to some differnt scenarios, you can see in some cases they do behave differently. This can help you decide which is best for what you need in your script. $_SERVER[’PHP_SELF’]

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /dir/test


When we use $_SERVER[’PHP_SELF’] we have the file name /example/index.php returned to us both when we did and did not actully type it in the URL.

When we appended variables to the end of it, they where truncated and again /example/index.php was returned. The only one that produced a different result was when we appended directories after the file name. In that case, it returned those directories.

$_SERVER['REQUEST_URI']

  • http://www.yoursite.com/example/ — – — /
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=test
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test

In all of our examples, this returned exactly what we entered for the URL. It returned a plain /, the file name, the variables, and the appended directories, all just as they had been entered.

$_SERVER[’SCRIPT_NAME’]

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php

In all cases here we were returned only the file name /example/index.php regardless of if it was typed, not typed, or anything was appended to it.

source: http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm

Tags: ,

debian - LAMP setup

January 19th, 2008 | 5 Comments | Posted in apache, mysql, php, server by dreamluverz

This tutorial has been helpful to me on my 1st attempt of setting up our dedicated server.

source: http://allyourtech.com/content/articles/16_01_2006_setting_up_a_local_web_server_in_debian_linux.php

The basic Linux setup

Setting this all up assumes you have a running version of Linux already installed. I won’t walk you through that part.

If you don’t have one and have an old box you’d like to use, I’d suggest using Debian as we are about to. But if you are new to Linux, you might want to try using a hard disk installation of Knoppix as the procedure will be identical.

Of course, you aren’t limited to Linux exclusively. All elements of LAMP (sans the Linux part) have been ported to most operating systems.

Setting up Apache

For the actual “web server” portion of our web server (i.e. the service sharing the web pages) we’ll be using Apache 2. In addition to being free and open source, Apache is by far the most used web server software on the Web.

Either dropping to a shell or connecting remotely, we’ll start by checking for updates to the Debian package lists. If you’ve done this recently or just did a fresh Internet-based installation, this won’t be necessary. This will require root access.

lineman@soundwave:~$ su
Password:
soundwave:/home/lineman# apt-get update
Get:1 http://security.debian.org stable/updates/main Packages [174kB]
Hit http://apt-mirror.sourceforge.net apt-mirror/ Packages
Ign http://apt-mirror.sourceforge.net apt-mirror/ Release
Get:2 http://security.debian.org stable/updates/main Release [110B]
Hit ftp://mirrors.kernel.org stable/main Packages
Hit ftp://mirrors.kernel.org stable/main Release
Hit ftp://mirrors.kernel.org stable/main Sources
Hit ftp://mirrors.kernel.org stable/main Release
Fetched 174kB in 3s (48.4kB/s)
Reading Package Lists... Done

Now that we’ve updated out package lists, we’ll tell Linux to go grab Apache. To fully install Apache, we’ll need more than one package. Thanks to Debian’s APT, we’ll be able to download and install all those dependencies with minimal work.

soundwave:/home/lineman# apt-get install apache2
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  apache2-common apache2-mpm-worker apache2-utils
Suggested packages:
  apache2-doc lynx www-browser
The following NEW packages will be installed:
  apache2 apache2-common apache2-mpm-worker apache2-utils
0 upgraded, 4 newly installed, 0 to remove and 5 not upgraded.
Need to get 1097kB/1131kB of archives.
After unpacking 4018kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Although it isn’t a requirement, APT suggested installing the Apache documentation. So we’ll go ahead and install that just in case. It suggested Lynx too but we probably won’t be needing that.

soundwave:/home/lineman# apt-get install apache2-doc
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
  apache2-doc
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 0B/3861kB of archives.

Now we’ll do a quick check to verify Apache is running.

soundwave:/home/lineman# /etc/init.d/apache2 start
Starting web server: Apache2httpd (pid 11205) already running

So it looks like Apache is running, but let’s not take that scripts word for it. I mean, we’re setting up a web server so why not use a web browser? To do this, just plug the IP address of your server into the address box of your favorite browser. This should forward you to http://servername/apache2-default/ where you’ll find a page congratulating you on your successful Apache installation.


If you’d like to start by editing this sample page, it’s easy enough to do. The default Apache files are stored in /var/www/apache2-default on your server.

To edit the English version of the page, we’ll just have to use Nano (or another text editor) to edit /var/www/apache2-default/index.html.en.

soundwave:/home/lineman# nano /var/www/apache2-default/index.html.en


If you’d like to play with a few of Apache’s settings, the main configuration file is /etc/apache2/apache2.conf. Since by default Debian will allow external connections to Apache, you may want to limit connections to your localhost or local network only.

If you’d like to make web folders for individual accounts, all that is needed to make a directory in the user’s home directory called /public_html. For example, if your username is “lineman,” you’ll need to mkdir /home/lineman/public_html. Files stored in that directory will then be viewable in your web browser at the address http://servername/~lineman/.

At this point, if all you want to work on and host are static pages, you are done. But for those who want to do more interesting things using the LAMP platform, we’ll move on.

Setting up MySQL

There are plenty of Apache-friendly database servers available, but MySQL is certainly a popular option. Again, this one is free and open source.

We’ll start by installing MySQL in a manner similar to the way we installed Apache.

soundwave:/home/lineman# apt-get install mysql-server
The following extra packages will be installed:
  libdbd-mysql-perl libmysqlclient12 mysql-client mysql-common
Suggested packages:
  mysql-doc
The following NEW packages will be installed:
  libdbd-mysql-perl libmysqlclient12 mysql-client mysql-common mysql-server
0 upgraded, 5 newly installed, 0 to remove and 5 not upgraded.
Need to get 4523kB of archives.
After unpacking 10.5MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Once MySQL begins to install, we’ll get a brief warning screen. This is mainly to fill us in a little on how passwords will work. By default, the root user MySQL has no password (something you will want to change for a public server).


Before moving on, we’ll make sure the MySQL service is running.

soundwave:/home/lineman# /etc/init.d/mysql start
Starting MySQL database server: mysqld...already running.

If you’d like to change some of MySQL’s settings from their default values, take a look at the files located in /etc/mysql.

As with Apache, APT suggests we install the MySQL documentation. Just to be safe, we’ll go ahead and do that.

soundwave:/home/lineman# apt-get install mysql-doc
Reading Package Lists... Done
Building Dependency Tree... Done
Package mysql-doc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package mysql-doc has no installation candidate

Unfortunately, this package has been removed from Debian. So if we want the documentation, we’ll have to grab the documents directly from MySQL.com.

If you are already comfortable using MySQL from the command line, you can probably skip the section on phpMyAdmin further down. But if you aren’t, phpMyAdmin will make your life much easier.

Setting up PHP

While HTML is a useful markup language, it lacks the sophisticated scripting ability that the modern Web user expects. This is where scripting languages like JavaScript, ASP, and PHP are needed. In particular, server-side scripts like those used in PHP and ASP provide a framework for building security-minded Web interfaces.

It is with good reason that most Linux-based hosts use PHP over ASP (and not because LAMA just doesn’t sound all that desirable). PHP is a completely free and open source operating system. Cost aside, there are security considerations here. PHP has certainly not had a spotless record of security, but flaws are found much more quickly and are fixed almost immediately.

Now if you really want to use ASP, Apache can be made to support it. However, support is limited.

Most of us, though, are using PHP (hence the popularity of LAMP) so we’ll go ahead and set it up. Again, this starts on the command line.

soundwave:/home/lineman# apt-get install php4
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  apache-common libapache-mod-php4
Suggested packages:
  apache apache-ssl apache-perl php4-pear
The following NEW packages will be installed:
  apache-common libapache-mod-php4 php4
0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded.
Need to get 2460kB of archives.
After unpacking 6357kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Since we will be using both PHP and MySQL on our server, we’ll go ahead and install the PHP’s MySQL module to help them play together better. We’ll also install PHP’s Pear extensions since so many packages will require it.

soundwave:/home/lineman# apt-get install php4-mysql php4-pear
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  php4-cli
Suggested packages:
  php4-dev
The following NEW packages will be installed:
  php4-cli php4-mysql php4-pear
0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded.
Need to get 1860kB/1882kB of archives.
After unpacking 5095kB of additional disk space will be used.
Do you want to continue? [Y/n] y

There are a few other packages we’ll need to install to get Apache working with PHP.

soundwave:/home/lineman# apt-get install libapache2-mod-php4 php4-cgi
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  apache2-mpm-prefork
The following packages will be REMOVED:
  apache2-mpm-worker
The following NEW packages will be installed:
  apache2-mpm-prefork libapache2-mod-php4 php4-cgi
0 upgraded, 3 newly installed, 1 to remove and 5 not upgraded.
Need to get 5024kB of archives.
After unpacking 9441kB of additional disk space will be used.
Do you want to continue? [Y/n] y

All the necessary packages are installed, but we aren’t quite done yet. Using your favorite text editor, we’ll need to make some changes to /etc/apache2/apache2.conf. First, locate the line “#AddType application/x-httpd-php .php” and un-comment the line by removing the # from the beginning. Next, we’ll need to add the line below.

LoadModule php4_module /usr/lib/apache2/modules/libphp4.so

To get those changes to take effect, we’ll have to restart Apache. If we don’t, web browsers will be downloading our full PHP files rather than Apache processing them first.

soundwave:/home/lineman# /etc/init.d/apache2 restart

To show that PHP is working, we’ll make a small PHP file and stick it in our web folder. Within the directory /home/lineman/public_html, I’m going to add a file called index.php with the following contents:

<?php
  phpinfo();
?>

This will generate a PHP page at http://servername/~lineman/ that will tell us a lot about our PHP installation.


Setting up phpMyAdmin

Don’t listen to the people who’ll tell you that you are cheating if you don’t run MySQL from the command line. Not only is that method more difficult, but you risk doing more damage if you make a mistake.

phpMyAdmin is a web interface designed specifically for administering MySQL. While there are times that MySQL is best used directly (like when you are moving a 50 MB database to a new co-located server), phpMyAdmin is commonly used to handle day-to-day database issues.

The installation of phpMyAdmin is fairly straightforward.

soundwave:/home/lineman# apt-get install phpmyadmin
Reading Package Lists... Done
Building Dependency Tree... Done
Suggested packages:
  php4-gd php5-gd
The following NEW packages will be installed:
  phpmyadmin
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 2768kB of archives.

Once the installation begins, we’ll be presented with a question about which web servers to reconfigure. Since we used Apache2, be sure to check that. When prompted, go ahead and have Apache2 restarted.


To test out phpMyAdmin, we’ll first point our web browser to http://servername/phpmyadmin/. We will connect using the username “root” and a blank password. Once we do, phpMyAdmin will greet us with stern warning about our blank password. Clicking on “Change password” will allow us to set one and get rid of that warning.


Conclusion

There you have it – your very own web server to tweak and test on without fear of downtime for your own or your clients’ websites! But I have to warn you about one thing; once you’ve learned all the things you can do on your own server that your shared host isn’t letting you have access to, you’ll almost certainly be shelling out extra cash every month for your own dedicated server.

Tags: , ,

passing session between subdomains

December 19th, 2007 | No Comments | Posted in php, server by dreamluverz

Few months ago i’ve been looking for ways how to do this. I’ve tried some things though but I need a better solution. Tonight I came across these sites on how to do it. I haven’t tried it yet coz I really don’t have time right now, i’m still packing my stuffs but I’m so eager to try it, for sure when I come back next year coz I need this code on the sites I’m working on.

<blockquote>

PHP configuration to set “session.cookie_domain” to “.mysite.com” (note the leading period) so that the session cookies are applicable across the entire domain.

ini_set(’session.cookie_domain’, ‘.example.com’);

</blockquote>

sources:http://www.phpbuilder.com/board/archive/index.php/t-10345127.html, http://www.dnforum.com/f181/keeping-session-variables-across-subdomains-thread-152857.html , http://www.webmasterworld.com/forum88/13145.htm

UPDATED: January 3, 2008

I just got back from my vacation and back to work again. :P

I’ve been trying out this session.cookie_domain for hours but can’t make it work. You may also find it in other forums or blogs that you need to set the cookie path but I didn’t try it coz according to some who tried it, it still didn’t do the trick.

Ssome says to use php_value session.cookie_domain as an alternative on .htaccess but I got internal server error 500. I’m not sure if it conflicts when the mod_rewrite i had on .htaccess so I just stick to ini_set() and try to make it work. I still believe in prayers so I did pray.

I tried checking the values cookie_domain, phpsessid on phpinfo(), defined ini_set(’session.cookie_domain’, ‘.example.com’); before calling session_start(), and restarted the browsers(tested on ie & ff) and now it works. Thanks God :)

UPDATED:  jan 7 ‘08

The session.cookie_domain doesn’t work in firefox when accessing url without www e.i. (http://domain.com)  so I removed  the preceeding dot ‘.’ on the domain value and now it works both for ie and firefox.

Tags: , , , , , ,

Save files on database or file system?

December 12th, 2007 | No Comments | Posted in mysql, php by dreamluverz

File System - Advantages

One of the main benefits of storing the file on disk is that it’s very easy to do. Just call SaveAs on a FileUpload control and you’re pretty much done.

Another advantage is that files on disk are easy to backup; you just copy the files to another location. This also makes it easier to do incremental backups; files that have already been backed up don’t need to be copied again.

FileSystem - Disadvantages

Storing your files in the file system has a few disadvantages as well. Probably the most problematic issue is the loosely coupled nature of the files on disk. They have no strong relation with a record in the database. So, when you delete, say, a product from the database, you may end up with an orphaned product image. There is no direct way to do an INNER JOIN between the product table and your images folder to determine what orphaned files you have left. This means that a page developer is responsible for writing code that deletes the file from disk whenever the associated database records gets deleted.

Also, to store uploaded files on disk, your web server needs permissions (6) to write to the file system. This is easy to come by (7) when you run your own server, but may prove to be more problematic in an ISP scenario.

Database - Advantages

Of course some of the advantages of a database are the exact opposite of the disadvantages of saving them as physical files: since they are stored in the database, they’re easy to relate to other records. They can be retrieved in JOIN style queries, and even be deleted automatically with cascading delete turned on. You also don’t need additional permissions on the server; if you can write to the database, you can store files in it.

But another advantage of storing your files in a database is the fact that all data is contained in a single location. Make a backup of your database, and you have everything you need. That makes it a lot easier to move your data to another server; other than the database, you don’t need to copy files, set up permissions and so on.

Database - Disadvantages

At the top of the list of disadvantages of storing your files in a database is probably performance. While I don’t have any hard figures to support this, the “word is” that it’s slow. How slow may depend on your situation, the type of files you have, the server, and so on.

Another downside is the lack of easy access to the files. When you store them on disk, it’s easy to download them to your desktop machine and batch process them; for example, use an imaging program to scale or rotate all your images. When you use a database, you need to “materialize” them to disk first and upload them again afterwards.

A final problem with the database is backups. Whenever you make a full backup of your database, all the files are included, whether they have been changed or not. If you copy your backups to a different machine or network for safety reasons, this could be problematic as you need to move the entire backup file. With a file based solution, you can use diff programs that can determine which files have been changed since the last backup, and only download those.
source: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=414

Tags: , ,

how to pass session from one domain to another

November 9th, 2007 | No Comments | Posted in php by dreamluverz

Is there any way to pass session from one domain to another without using iframe.

Let say 1st domain is one.com and i want to pass the session to two.com without using hidden iframes. Most of the articles I read suggest to use hidden iframes…but any other ideas please?

Tags: