TechMynd, Stuff That Works | Downloads, Tips & Tricks, Softwares, Programming, Resources


PHP Register Globals Explained - Headers already Sent - Undefined Variable

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 }

Tags:
Posted in: PHP
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

Get Dynamic And Static IP Address Of Visitor In PHP

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>"; 
?>
Tags: ,
Posted in: PHP, Tutorials
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

PHP Easy Most Database Connection

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.

Tags: ,
Posted in: PHP, mySQL
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

PMB Is Out For Download - PHP MySQL Records Management CMS

pmb

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

Tags: , ,
Posted in: CMS, Downloads, PHP, Resources
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

Developing A PHP CMS - Coding & Programming

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.

Tags: , , ,
Posted in: CMS, Developer's Corner, PHP, Personal, Resources, Tools
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

MySQL Query Is Not Updating Records

Did you wonder sometimes that why mysql update command is not updating my records when the syntax of update query is perfectly alright?

This is the problem i stuck with couple of times and I just wondered and looked for solution but seriously never found any solution to that anywhere untill I found the answer to this question and I was relieved than from tension.

The problem was that I was naming the variables used in mysql query which were used by mysql itself.
Suppose that if there are seven variables in total number and mistakenly you named just one of them which is used by mysql, even than mysql update query will not work also and will not update records in the database.

For example by, from, status etc.

Insert mysql query will run and add records in database but update query will not be running.

Incorrect Query
UPDATE expenditures set by=’$by’, amount=’$amount’, from=’$from’, purpose=’$purpose’ where id=’$action’;

Correct Query
UPDATE expenditures set bby=’$bby’, amount=’$amount’, ffrom=’$ffrom’, purpose=’$purpose’ where id=’$action’;

Testing Your Query
The trick is to echo the query which you are running and test it in phpMyAdmin query window. i.e.

$myquery=”UPDATE expenditures set bby=’$bby’, amount=’$amount’, ffrom=’$ffrom’, purpose=’$purpose’ where id=’$action’”;
echo “$myquery”;

By echoing that you will get something like this
UPDATE expenditures set bby=’javed’, amount=’2000′, ffrom=’home’, purpose=’books’ where id=’2′

Finding Error
This is just an example. Alright now copy that query (echo result) and go to phpMyAdmin and open that database and i suggest that table also which is going to be updated and click query button. In query window write that result and try running that.
If its right it will update successfully but if that’s not right than it will give some error saying something like;

syntax error
You have some error near UPDATE expenditures set by=’$by’, amount=’$amount’, from=’$from’, purpose=’$purpose’ … in line 1

If it gives error than it will highlight those variables also which are not right and there you can guess that what’s wrong.

Always when your query is not running and giving error it is recommended that you echo that query and run that in phpMyAdmin query window and see cautiously the error message. Hope it will help.

Did you find any problem like this or query related? Please share with me.

Tags: ,
Posted in: mySQL
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

Auto Populate Year Range in PHP

Building a ‘Year drop down list’ can be a difficult task. And you have to change it manually after every year. Here is a php easy way to auto populate years list and you can adjust the starting year.

PHP Year Drop Down Autopopulated List Code

<?php
$currentYear = date("Y");
$years = range ($currentYear, 1900);
echo "<select name='yyear' id='yyear'>";
echo "<option value='' selected>Year</option>";
foreach ($years as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
?>

Manual Year Drop Down List Code

<select name='yyear' id='yyear'>
<option value='' selected>Year</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
<option value="1919">1919</option>
<option value="1918">1918</option>
<option value="1917">1917</option>
<option value="1916">1916</option>
<option value="1915">1915</option>
<option value="1914">1914</option>
<option value="1913">1913</option>
<option value="1912">1912</option>
<option value="1911">1911</option>
<option value="1910">1910</option>
<option value="1909">1909</option>
<option value="1908">1908</option>
<option value="1907">1907</option>
<option value="1906">1906</option>
<option value="1905">1905</option>
<option value="1904">1904</option>
<option value="1903">1903</option>
<option value="1902">1902</option>
<option value="1901">1901</option>
<option value="1900">1900</option>
</select>

Tags:
Posted in: PHP
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

Primary Key & ID

A primary key is used to uniquely identify each row in a table. It can either be part of the actual record itself, or it can be an artificial field (one that has nothing to do with the actual record). A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, they are called a composite key.

Primary keys can be specified either when the table is created (using CREATE TABLE) or by changing the existing table structure (using ALTER TABLE).

CREATE TABLE Customer
(SID integer,
Last_Name varchar(30),
First_Name varchar(30),
PRIMARY KEY (SID));

Tags:
Posted in: phpMyAdmin
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

Date & Time in php

<?PHP
echo date(”D M d, Y H:i:s”);
?>

Tags:
Posted in: PHP
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment

Flash XML PHP

With Flash, XML and PHP you can create very professional, interactive, dynamic and customizable slideshows, galleries and lot more.

We basically control backend by php and create xml file which is called in flash to show the dynamic content.

This section is bringning php, xml and flash based utilities.

Tags: , ,
Posted in: FLASH, XML & PHP
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Respond: Post A Comment




  Subscribe Via RSS
  Subscribe Via Email


Add to Google Reader
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Add to My AOL
Add to Simpy
Add to Technorati Favorites!
Add to netvibes


Add to Technorati Favorites