Archive for the ‘PHP’ Category
There are some situations where simple code may work properly in case of PHP online or at localhost if register_globals are on. But not necessarily if register_globals are off.
Warning: Undefined Index - Use of Undefined constant selected
Warning: Header already sent
Sometimes messages like above that header already sent or undefined variable or index can appear.
Recommendation: You can use javascript redirect instead of header redirect.
Header Redirect
header("location: somepage.php?action=posted");
Use javascript redirection if header redirect is not working. i.e.
<script language=”javascript” type=”text/javascript”>
<!–
alert(”Please Login.”);
document.location = “index.php”;
–>
</script>
Use @ to avoid warnings
<? session_start();
if(@$_SESSION['usrName']==”") {
?>
And
$getname=@$_REQUEST["name"];
Note how I have used @ which is not necessary to use but working at strict server and with globals off to avoid warnings you can use this.
Register_Globals are by default off. These are for security reasons. Meant to be like it. It is recommended to program with globals off settings and use POST and REQUEST always while passing variables through pages. i.e.
$getact=$_REQUEST["act"];
$_POST["act"]
OR
echo $_POST["act"];
if(isset($_GET['action']) && $_GET['action']==”download”)
{ // do something }
Suppose we have a website and we want to get the user IP address and want to display it for him or we want to store it and get a log for hits of website. Also sometimes users may share same IP address for internet sharing & usage so his PC’s IP will be something like 192.168.0.2 (Proxy Case) and actual IP address which he is using for internet, shared by his internet service provider will be different. We can find these both IP by this simple example of PHP code.
PHP Code:
<?
$domain=$_SERVER['REMOTE_ADDR'];
$domain1 = isset($_SERVER['HTTP_X_FORWARDED_FOR'])
? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
echo "Viewer's Server's IP Address: <strong>$domain</strong> - ";
echo "Viewer's PC IP Address: <strong>$domain1</strong>";
?>
Setting up a database connection can be a difficult task if you google through different codes present online.
Here is the easy most method to create a dbconnection for PHP and mysql.
<?php
/* Online settings
$db = mysql_connect(”localhost”, “root”, “password”);
mysql_select_db(”dbname”,$db);
$siteurl = http://javedkhalil.com/;
*//* Local settings */
$siteurl = http://javedkhalil.com;
$db = mysql_connect(”localhost”, “root”, “”);
mysql_select_db(”dbname”,$db);
?>
Always write code both for Online and Local usage. Comment the code which is not being used. Also use siteurl variable and store website root path in it. It comes very very handy in times. We have to use many times website name inside the pages.
Now you can save this code in a file named like dbcon.php or whatever you like and include this file in php pages where you want to use dbconnection by this.
<?php Include (”dbcon.php”); ?> Here you are done.Another very simple code for dbconnection if you like, I am writing it here.
<?
$con=mysql_connect(”localhost”,”root”,”")or die(”Unable to connect”);
mysql_select_db(”dbname”,$con)or die(”Unable to open database”);
?>
This easy way to connect from mysql database through PHP will give a message if the connetion is not established.

PHP Personal Management Book is available for download, absolutely free. PHP Personal Management Book is a complete PHP CMS for personal record management and covers more than just Address Book or Phone Book requirements. The purpose of this software is to enable you manage upcoming events which matter to you most and help you remember and manage your contacts and expenditures in well-organized manner.
PMB is PHP based open source absolutely free software for Home PC or Online Web Application usage.
Well every PHP developer search for stuff and examples about some PHP knowledge or ready to use codes and snippets and CMS etc. Who is not aware with the sourceforge.net? I also download stuff and get learning and PHP knowledge but mostly developers do not care about the design, interactivity and simplicity. Here, I suggest that you download PMB, use it and tell me how you feel about it? I was in need of such CMS, so I built it myself. I will enhance PMB even more along with planning and working with more Open-Source content-management-systems. Developing PMB was more than a joyful experience to me.
Everybody can use this CMS even without learning a thing about PHP. I have included all the help and how-to stuff along with PMB. PMB is my first Open-Source CMS development struggle and I am launching it at my birthday. I hope that PMB might prove useful for you and I wish that I will get suggestions and requests for upgrades and to add more modules and support in it.
Top Features
- Complete Personal & Home Record Management, CMS, More than a personal diary
- Dual Controllable Accounts (Admin, User)
- Dual Security with Password Protection and Secret Code
- Flexible Modules, Enable/Disable Feature
- Photo Support for Contacts and Events
- Group Management (Arrange records into groups)
- Alerts & Reminders
Other All Features
- Complete Phone Book (Home, Office, Mobile)
- Complete Address Book (Home, Business, Personal contact details, enhanced and advanced Contact Book experience, Easy Groups Management, manage contacts into groups)
- Birthday Record management, upcoming birthdays reminders
- Monthly Bills Record management
- Expenditures management (Your important major expendiures record management to keep track of at what and how much you spend over time…)
- Borrow, Lent, Balance and Saving Record management
- To-Do-List
- Events Diary with photo support
- Reminders and alerts
- Advanced search (Search by name, date, month, year, category or record detail)
- Dual Controllable Accounts (Admin, User)
You can use PMB front-end with both password protection or without password protection
Decide your security option by yourself
- Dual Security with Password Protection and Secret Code
Assign password to any record you want to hide it from normal view if its private
- Modules Enable/Disable Feature
You can enable any module to use it or disable to ignore it. Flexibility allows you to keep your desired modules and sections available while others disabled. You can use disabled modules anytime by enabling them. Your data is secure, whether you enable or disable any one of it anytime.
and much more…
Download PMB
I will have to admit. Programming is a very sensitive and careful work to do. Its been quite some days while I have been developing my new but first open source based, php full content management system. Even if I did write down all the points which I will be going to cover in this management system but as the project went on I had to drop some code and add some new by time to time. I like to do PHP stuff. Its my one of many interesting things to do.
In PMB I promised my readers to provide them a complete content management system which will cover more than just a phone book or address book. I would say that it has actually more bells and whistles in it. The development process went on fairly. I am almost done with it. I have planned to provide my readers full support relating to this system. I have created some web-based instructions on how to use PMB? what PMB contains? What platform is uses? How PMB can be used at local machine? How to use it at local server? How to use wamp server in fact and wamp general settings and also screenshots of the software. Even if anybody do not know that how to run PHP pages at PC locally, I can say that by reading detailed instruction manual along with PMB, he will be able to setup PMB locally and use it successfully for his record management needs.
I am pretty happy about the development of this CMS. If I will get responses and suggestions, I will even enhance its functionality, support and modules. Presently it will support images also and everything is customizable. Just waiting for 17-December-2007 to arrive and PMB will be on its way.