Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Friday, September 14, 2012

Magento :How Activate Demo store notice via Magento Admin, Demo Store text enabled in Magento

In the opensource world, Magento is one of the top most wanted E-commerce solution. Here we explained about Demo store message in the magento. We displayed Demo store text in the top of the page when are in the development. 

Find the following step to enable demo store,

1) Go to Magento admin 

2) Then go to System  -> Configuration

2) In the left side of the configuration -> General -> Web

3) HTML Head -> Tab have the select options named as "Display Demo Store Notice", choose "Yes" to activate demo store.

By PHP with 1 comment

Sunday, August 5, 2012

PHP Tutorial Online, Beginners Tutor Online, PHP eBooks

Learn About PHP online Materials, Download PHP E books Online, Online PHP tutorials, PHP Materials online.



Soure From: http://www.slideshare.net/. We are not copyrighted for this materials. we are placed embedded code from slideshare website

By PHP with No comments

Saturday, August 4, 2012

eSELECTplus Moneris Payment Gateway Integration - osCommerce

It’s a canada based Payment gateway solution provider. Moneris payment gateway provide various kit based on the opensource languages. Here we provide integration steps for osCommerce opensource.

eSELECTplus Moneris Payment Gateway Integration Steps

1.     Download the osCommerce Payment kit from eSELECTplus Moneris website which is already registered.
2.     Extract payment folder.
3.     Now we open phpmyadmin database for our oscommerce via cPanel/any other access
4.     Downloaded folder have Moneris.sql file, run this into osCommerce database
5.     Rename the "module.payment.moneriscampg.php” into "moneriscampg.php" and move to the \catalog\includes\modules\payment" folder on your web server.
6.     Rename the "language.english.moneriscampg.php" file into "moneriscampg.php” and move to "\catalog\includes\languages\english\modules\payment" folder on your web server.
7.     from the downloaded folder have "CANmpgClassesOsc.php ",  “CANmpiClassesOsc.php” files. Copy and paste into "\catalog\includes\classes\" folder.
8.     Move the file “orders_addon_campg.php” into to “\catalog\admin\” and then insert bolded code in “\catalog\admin\orders.php” as displayed below. (Approximately at line 204):

<?php


if (tep_not_null($order->info['cc_type']) || tep_not_null($order->info['cc_owner']) ||


tep_not_null($order->info['cc_number'])) {


?>


<tr>


<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>


</tr>


<tr>


<td class="main"><?php echo ENTRY_CREDIT_CARD_TYPE; ?></td>


<td class="main"><?php echo $order->info['cc_type']; ?></td>


</tr>


<tr>


<td class="main"><?php echo ENTRY_CREDIT_CARD_OWNER; ?></td>


<td class="main"><?php echo $order->info['cc_owner']; ?></td>


</tr>


<tr>


<td class="main"><?php echo ENTRY_CREDIT_CARD_NUMBER; ?></td>


<td class="main"><?php echo $order->info['cc_number']; ?></td>


</tr>


<tr>


<td class="main"><?php echo ENTRY_CREDIT_CARD_EXPIRES; ?></td>


<td class="main"><?php echo $order->info['cc_expires']; ?></td>


</tr>


<?php


}


?>


</table></td>


</tr>


<?php include ("orders_addon_campg.php"); ?>


<tr>


<td><?php echo tep_draw_separator(‘pixel_trans.gif’, ‘1’, ‘10’); ?></td>


</tr>


<tr>


<td><table border=”0” width=”100%” cellspacing=”0” cellpadding=”2”>


<tr class=”dataTableHeadingRow”>


<td class=”dataTableHeadingContent” colspan=”2”><?php echo TABLE_HEADING_PRODUCTS; ?></td>


<td class=”dataTableHeadingContent”><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>


<td class=”dataTableHeadingContent” align=”right”><?php echo TABLE_HEADING_TAX; ?></td>


<td class=”dataTableHeadingContent” align=”right”><?php echo


TABLE_HEADING_PRICE_EXCLUDING_TAX; ?></td>


<td class=”dataTableHeadingContent” align=”right”><?php echo


TABLE_HEADING_PRICE_INCLUDING_TAX; ?></td>


<td class=”dataTableHeadingContent” align=”right”><?php echo


TABLE_HEADING_TOTAL_EXCLUDING_TAX; ?></td>


eSELECTplus CAN - osCommerce Shopping Cart July 19, 2011


Page 6 of 17


<td class=”dataTableHeadingContent” align=”right”><?php echo


TABLE_HEADING_TOTAL_INCLUDING_TAX; ?></td>


</tr>

9.     Modify the error message text content display in the shopping cart go to “\catalog\includes\languages\english\modules\payment\moneriseselectplus.php”.
10.  Now we logged into osCommerce Admin panel ->Modules ->Payments
11.  Payment has the payment gateway lists, Click on “Install” to enable the Moneris eSELECTplus payment module and press edit to configure the payment parameters.
12.  Once configure Now go to front end to test product purchase using eSelectplus.
13.  If we have any issues in the test order, we need to check  cURL info settings,
a.     cURL CA Root Certificate File:
b.    The default installation of PHP/cURL does not include the cURL CA root certificate file. In order for the eSelectPlus PHP API to connect to the eSelectPlus gateway during transaction processing, the ‘mpgclasses.php’ file that’s included with the PHP API package needs to be modified to include a path to the CA root certificate file. Follow the instructions below to set this up.
c.     If cURL was not installed separately from your PHP installation, libcurl is included in your PHP installation. You will need to download the ‘cacert.pem’ file from ‘http://curl.haxx.se/docs/caextract.html’ and save it to the necessary directory. Once downloaded, rename the file to ‘curl-ca-bundle.crt’ (e.g. 'C:\path\to\curl-ca-bundle.crt'). If cURL was installed separately from PHP, you may need to determine the path to the cURL CA root certificate bundle on your system (e.g. 'C:\path\to\curl-ca-bundle.crt').
d.    Insert the code below into the "CANmpgClassesOsc.php ",  “CANmpiClassesOsc.php” files as part of the cURL option setting, at approximately line 73 below the line ‘curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);‘
curl_setopt($ch, CURLOPT_CAINFO, getwed().'\curl-ca-bundle.crt');
getwed() – Is the function in the PHP, which is used to get the document root[absolute filepath]

Test Card For Moneris eSELECTplus Payment Gateway
MasterCard: 5454545454545454
Visa:  4242424242424242 or 4005554444444403
Amex:  373599005095005

Test IDs

store_id
api_token
Username
Password
store1
yesguy
DemoUser
password
store2
yesguy
DemoUser
password
store3
yesguy
DemoUser
password
store5*
yesguy
DemoUser
password

For more information please read the document which is included in the payment gateway kit.
Reference from eSelectPlus_OSCommerce_IG_CAN.pdf which is provided by eSelectPlus payment gateway. Please ready document which is provided by the payment gateway before going to proceed. We are not responsible for any issues.


By PHP with 1 comment

Friday, July 20, 2012

PHP…MYSQL…JQUERY… Starting History at a glance

Nowadays one of most used open source web development script is PHP. Because PHP is easy to learn as well as easy develop website and web application easily with short period of time.

When we create PHP, No need to invest money to purchase all the supporting softwares are open source.

About PHP:

The great open source PHP creator is : “Rasmus Lerdorf”
Top know more about PHP language creator visit following,
  1. http://en.wikipedia.org/wiki/Rasmus_Lerdorf
  2. http://lerdorf.com/bio.php
  3. http://www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html

About MYSQL:

PHP is frontend scripting language, When we need to store the data, we need backend database. MYSQL one of the powerful databases to store the data’s in the backend. Mysql is also an open source.
The creator of MYSQL is : “Michael Widenius”
  1. http://www.mysql.com/

About Jquery:

Process is done without page reloading... So we go for an jQuery. jQuery used to create fast web based application with any events, animations and also interact with ajax functionality. to know more about this,
  1. http://docs.jquery.com/Tutorials
Leader of jQuery :“John Resig”

By PHP with No comments

Sunday, June 3, 2012

PHP Multipurpose


Let’s say you wanted to construct your site so that it showed the visitor’s name at the top of every page. With our custom welcome message example above, we’re halfway there already. Here are the problems we’ll need to overcome to extend the example:

We need the name on every page of the site, not just one.

We have no control over which page of our site users will view first



The first problem isn’t too hard to overcome. Once we have the user’s name in a variable on one page, we can pass it with any request to another page by adding the name to the query string of all links:2
<a href="newpage.php?name=<?php echo urlencode($_GET['name']);?>"> A link</a>


Notice that we’ve embedded PHP code right in the middle of an HTML tag. This is perfectly legal, and will work just fine.

You’re familiar with echo statements, but the urlencode function is probably new to you. This function takes special characters in the string (for example, spaces) and converts them into the special codes they need to be in order to appear in the query string. For example, if the $name variable had a value of 'Kevin Yank', then, as spaces are not allowed in the query string, the output of urlencode (and thus, the string output by echo) would be 'Kevin+Yank'. PHP would then convert it back automatically when it created the $_GET variable in newpage.php. Okay, so the user’s name will be passed with every link in our site. Now all we need is to get that name in the first place. In our welcome message example, we had a special HTML page containing a form that prompted the user for his or her name. The problem with this (identified by the second point above) is that we couldn’t—nor would we wish to—force the user to enter our Website by that page every time he or she visited our site.

The solution is to have every page of our site check to see if a name has been specified, and prompt the user for a name if necessary.3 This means that every page of our site will either display its content, or prompt the user to enter a name, depending on whether the $name variable is found to have a value. If you think this is beginning to sound like a good place for an if-else statement, you’re a quick study!

We’ll refer to pages that can decide whether to display one thing or another as multipurpose pages. The code of a multipurpose page looks something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Multipurpose Page Outline</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php if (condition) { ?>
<!-- HTML content to display if condition is true -->
<?php } else { ?>
<!-- HTML content to display if condition is false -->
<?php } ?>
</body>
</html>


This code may confuse you at first, but, in fact, this is just a normal if-else statement with HTML code sections that depend on the condition, instead of PHP statements. This example illustrates one of the big selling points of PHP: that you can switch in and out of “PHP mode” whenever you like. If you think of <?php as the command to switch into “PHP mode”, and ?> as the command to go back into “normal HTML mode,” the above example should make perfect sense.

There’s an alternate form of the if-else statement that can make your code more readable in situations like this. Here’s the outline for a multipurpose page using the alternate if-else form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Multipurpose Page Outline</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php if (condition): ?>

<!-- HTML content to display if condition is true -->
<?php else: ?>
<!-- HTML content to display if condition is false -->
<?php endif; ?>
</body>
</html>

Okay, now that we have all the tools we need in hand, let’s look at a sample page of our site:
File: samplepage.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample Page</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php if (!isset($_GET['name'])): ?>
<!-- No name has been provided, so we
prompt the user for one. -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<label>Please enter your name:
<input type="text" name="name" /></label>
<input type="submit" value="GO" />
</form>
<?php else: ?>
<p>Your name: <?php echo $_GET['name']; ?></p>
<p>This paragraph contains a
<a href="newpage.php?name=<?php echo urlencode($_GET['name']);
?>">link</a> that passes the name variable on to the next
document.</p>
<?php endif; ?>

</body>
</html>
There are two new tricks in the above code, but overall you should be fairly comfortable with the way it works. First of all, we’re using a new function called isset in the condition. This function returns (outputs) a value of true if the variable it is given has been assigned a value (i.e. if a name has been provided in this example), and false if the variable does not exist (i.e. if a name has not yet been provided). The exclamation mark (also known as the negation operator, or the not operator), which appears before the name of the function, reverses the returned value from true to false, or vice-versa. Thus, the form is displayed
when the $_GET['name'] variable is not set.

The second new trick is the use of the variable $_SERVER['PHP_SELF'] to specify the action attribute of the <form> tag. Like $_GET, $_POST, and $_REQUEST, $_SERVER is an array variable that is automatically created by PHP. $_SERVER contains a whole bunch of information supplied by your Web server. In particular, $_SERVER['PHP_SELF'] will always be set to the URL of the current page. This gives us an easy way to create a form that, when submitted, will load the very same page, but this time with the $name variable specified. If we structure all the pages on our site in this way, visitors will be prompted for their name by the first page they attempt to view, whichever page this happens to be, as shown in Figure 3.8. Once they enter their names and click GO, they’ll be presented with the exact page they requested.

By PHP with No comments

PHP Control Structures Tips


All the examples of PHP code we’ve seen so far have been either simple, onestatement scripts that output a string of text to the Web page, or series of statements that were to be executed one after the other in order. If you’ve ever written programs in other languages (JavaScript, C, or BASIC) you already know that practical programs are rarely so simple. PHP, just like any other programming language, provides facilities that allow us to affect the flow of control in a script. That is, the language contains special statements that permit you to deviate from the one-after-another execution order that has dominated our examples so far. Such statements are called control structures. Don’t get it? Don’t worry! A few examples will illustrate perfectly. The most basic, and most often-used, control structure is the if-else statement.



Here’s what it looks like:
if (condition) {
// Statement(s) to be executed if
// condition is true.
} else {
// (Optional) Statement(s) to be
// executed if condition is false.
}


This control structure lets us tell PHP to execute one set of statements or another, depending on whether some condition is true or false. If you’ll indulge my vanity for a moment, here’s an example that shows a twist on the personalized welcome page example we created earlier:

File: welcome6.php (excerpt)
$name = $_REQUEST['name'];
if ($name == 'Kevin') {
echo 'Welcome, oh glorious leader!';
} else {
echo "Welcome to our Website, $name!";
}


Now, if the name variable passed to the page has a value of Kevin, a special message will be displayed. Otherwise, the normal message will be displayed and will contain the name that the user entered.

As indicated in the code structure above, the else clause (that part of the ifelse statement that says what to do if the condition is false) is optional. Let’s say you wanted to display the special message above only if he appropriate name was entered; otherwise, you didn’t want to display any message. Here’s how the code would look:

$name = $_REQUEST['name'];
if ($name == 'Kevin') {
echo 'Welcome, oh glorious leader!';
}


The == used in the condition above is the PHP equal-to operator that’s used to compare two values to see whether they’re equal.

Conditions can be more complex than a single comparison for equality. Recall that our form examples above would receive a first and last name. If we wanted to display a special message only for a particular person, we’d have to check the values of both names:

File: welcome7.php (excerpt)
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
if ($firstname == 'Kevin' and $lastname == 'Yank') {
echo 'Welcome, oh glorious leader!';
} else {
echo "Welcome to my Website, $firstname $lastname!";
}


This condition will be true if and only if $firstname has a value of Kevin and $lastname has a value of Yank. The word and in the above condition makes the whole condition true only if both of the comparisons evaluate to true. Another such operator is or, which makes the whole condition true if one or both of two simple conditions are true. If you’re more familiar with the JavaScript or C forms of these operators (&& and || for and and or respectively), that’s fine—they work in PHP as well.

We’ll look at more complicated conditions as the need arises. For the time being, a general familiarity with the if-else statement is sufficient. Another often-used PHP control structure is the while loop. Where the if-else statement allowed us to choose whether or not to execute a set of statements depending on some condition, the while loop allows us to use a condition to determine how many times we’ll execute a set of statements repeatedly. Here’s what a while loop looks like:

while (condition) {
// statement(s) to execute over
// and over as long as condition
// remains true
}


The while loop works very similarly to an if-else statement without an else clause. The difference arises when the condition is true and the statement(s) are executed. Instead of continuing the execution with the statement that follows the closing brace (}), the condition is checked again. If the condition is still true, then the statement(s) are executed a second time, and a third, and will continue to be executed as long as the condition remains true. The first time the condition evaluates false (whether it’s the first time it’s checked, or the one-hundred-andfirst), execution jumps immediately to the statement that follows the while loop,
after the closing brace.

Loops like these come in handy whenever you’re working with long lists of things (such as jokes stored in a database… hint, hint!), but for now we’ll illustrate with a trivial example: counting to ten.

File: count10.php (excerpt)
$count = 1;
while ($count <= 10) {
echo "$count ";
++$count;
}
It looks a bit frightening, I know, but let me talk you through it line by line. The first line creates a variable called $count and assigns it a value of 1. The second line is the start of a while loop, the condition for which is that the value of $count is less than or equal (<=) to 10. The third and fourth lines make up the body of the while loop, and will be executed over and over, as long as that condition holds true. The third line simply outputs the value of $count, followed by a space.

The fourth line adds one to the value of $count (++$count is a short cut for $count = $count + 1—both will work).

So here’s what happens when this piece of code is executed. The first time the condition is checked, the value of $count is 1, so the condition is definitely true. The value of $count (1) is output, and $count is given a new value of 2. The condition is still true the second time it is checked, so the value (2) is output and a new value (3) is assigned. This process continues, outputting the values 3, 4,
5, 6, 7, 8, 9, and 10. Finally, $count is given a value of 11, and the condition is false, which ends the loop.

The condition in this example used a new operator: <= (less than or equal). Other numerical comparison operators of this type include >= (greater than or equal), < (less than), > (greater than), and != (not equal). That last one also works when comparing text strings, by the way. Another type of loop that is designed specifically to handle examples like that above, in which we’re counting through a series of values until some condition is met, is called a for loop. Here’s what it looks like:

for (initialize; condition; update) {
// statement(s) to execute over
// and over as long as condition
// remains true after each update
}


The initialize statement is executed once at the start of the loop; the condition statement is checked each time through the loop, before the statements in the body are executed; the update statement is executed each time through the loop, but after the statements in the body. Here’s what the “counting to 10” example looks like when implemented with a for loop:

File: count10–for.php (excerpt)
for ($count = 1; $count <= 10; ++$count) {
echo "$count ";
}


As you can see, the statements that initialize and increment the $count variable join the condition on the first line of the for loop. Although, at first glance, the code seems a little more difficult to read, putting all the code that deals with controlling the loop in the same place actually makes it easier to understand once you’re used to the syntax. Many of the examples in this book will use for loops, so you’ll have plenty of opportunity to practice reading them.

By PHP with No comments

PHP User Interaction and PHP Forms


The ability to interact with users who view a Web page is essential for many applications of PHP. Veterans of JavaScript tend to think in terms of event handlers, which let you react directly to the actions of the user—for example, the movement of the cursor over a link on the page. Server-side scripting languages such as PHP have a more limited scope when it comes to user interaction. As PHP code is activated when a page is requested from the server, user interaction can occur only in a back-and-forth fashion: the user sends requests to the server, and the server replies with dynamically generated pages.

The key to creating interactivity with PHP is to understand the techniques we can use to send information about a user’s interaction along with his or her request for a new Web page. PHP makes this fairly easy, as we’ll now see.

The simplest method we can use to send information along with a page request uses the URL query string. If you’ve ever seen a URL in which a question mark followed the file name, you’ve witnessed this technique in use. Let’s look at an easy example. Create a regular HTML file called welcome1.html (no .php file extension is required, since there will be no PHP code in this file) and insert this
link:

File: welcome.html (excerpt)
<a href="welcome1.php?name=Kevin">Hi, I'm Kevin!</a>
This is a link to a file called welcome1.php, but as well as linking to the file, we’re also passing a variable along with the page request. The variable is passed as part of the query string, which is the portion of the URL that follows the question mark. The variable is called name and its value is Kevin. To restate, we have created a link that loads welcome1.php, and informs the PHP code contained in the file that name equals Kevin.

To really understand the results of this process, we need to look at welcome1.php. Create it as a new HTML file, but, this time, note the .php extension—this tells the Web server that it can expect to interpret some PHP code in the file. In the body of this new file, type the following:

File: welcome1.php (excerpt)
<?php
$name = $_GET['name'];
echo "Welcome to our Website, $name!";
?>


Now, if you use the link in the first file to load this second file, you’ll see that the page says “Welcome to our Website, Kevin!” This is illustrated in Figure 3.1.

Figure 3.1. Greet users with a personalized welcome message.

PHP creates automatically an array variable called $_GET that contains any values passed in the query string. $_GET is an associative array, so the value of the name variable passed in the query string can be accessed as $_GET['name']. Our script assigns this value to an ordinary PHP variable ($name), then displays it as part of a text string using an echo statement.

register_globals before PHP 4.2


In versions of PHP prior to 4.2, the register_globals setting in php.ini was set to On by default. This setting tells PHP to create ordinary variables for all the values supplied in the request automatically. In the previous example, the $name = $_GET['name'];

line would be completely unnecessary if the register_globals setting were set to On, since PHP would do it automatically. Although the convenience of this feature was one aspect that helped to make PHP such a popular language in the first place, novice developers could easily leave security holes in sensitive scripts with it enabled. For a full discussion of the issues surrounding register_globals, see my article
Write Secure Scripts with PHP 4.2![2] at sitepoint.com. You can pass more than one value in the query string. Let’s look at a slightly more complex version of the same example. Change the link in the HTML file to read as follows:

File: welcome2.html (excerpt)
<a href="welcome2.php?firstname=Kevin&amp;lastname=Yank">Hi,
I'm Kevin Yank!</a>


This time, we’ll pass two variables: firstname and lastname. The variables are separated in the query string by an ampersand (&, which is encoded as &amp; as it is a special character in HTML). You can pass even more variables by separating each name=value pair from the next with an ampersand. As before, we can use the two variable values in our welcome2.php file:


File: welcome2.php (excerpt)
<?php
$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];
echo "Welcome to my Website, $firstname $lastname!";

This is all well and good, but we still have yet to achieve our goal of true user interaction, where the user can enter arbitrary information and have it processed by PHP. To continue with our example of a personalized welcome message, we’d like to allow the user to type his or her name and have it appear in the message.

To allow the user to type in a value, we’ll need to use an HTML form. Here’s the code:

File: welcome3.html (excerpt)
<form action="welcome3.php" method="get">
<label>First Name: <input type="text" name="firstname" />
</label><br />
<label>Last Name: <input type="text" name="lastname" />
</label><br />
<input type="submit" value="GO" />
</form>

This form has the exact same effect as the second link we looked at (with firstname=Kevin&amp;lastname=Yank in the query string), except that you can now enter whatever names you like. When you click the submit button (which is labelled GO), the browser will load welcome3.php and add the variables and their values to the query string for you automatically. It retrieves the names of the variables from the name attributes of the input type="text" tags, and obtains the values from the information the user typed into the text fields. The method attribute of the form tag is used to tell the browser how to send the
variables and their values along with the request. A value of get (as used above) causes them to be passed in the query string (and appear in PHP’s $_GET array), but there is an alternative. It’s not always desirable—or even technically feasible— to have the values appear in the query string. What if we included a textarea tag in the form, to let the user enter a large amount of text? A URL whose
query string contained several paragraphs of text would be ridiculously long, and would possibly exceed the maximum length for a URL in today’s browsers. The alternative is for the browser to pass the information invisibly, behind the scenes. The code for this looks exactly the same, but where we set the form method to get in the last example, here we set it to post:

File: welcome4.html (excerpt)
<form action="welcome4.php" method="post">
<label>First Name:
<input type="text" name="firstname" /></label><br />
<label>Last Name:
<input type="text" name="lastname" /></label><br />

<input type="submit" value="GO" />
</form>


As we’re no longer sending the variables as part of the query string, they no longer appear in PHP’s $_GET array. Instead, they are placed in another array reserved especially for ‘posted’ form variables: $_POST. We must therefore modify welcome4.php to retrieve the values from this new array:

File: welcome4.php (excerpt)
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
echo "Welcome to my Website, $firstname $lastname!";
?>


The form is functionally identical to the previous one; the only difference is that the URL of the page that’s loaded when the user clicks the GO button will not have a query string. On the one hand, this lets you include large values, or sensitive values (like passwords), in the data that’s submitted by the form, without their appearing in the query string. On the other hand, if the user bookmarks the page that results from the form’s submission, that bookmark will be useless, as it doesn’t contain the submitted values. This, incidentally, is the main reason that search engines use the query string to submit search terms. If you bookmark a search results page on Google[3] or AltaVista[4], you can use that bookmark to perform the same search again later, because the search terms are contained in the URL. Sometimes, you want access to a variable without having to worry about whether it was sent as part of the query string or a form post. In cases like these, the special $_REQUEST array comes in handy. It contains all the variables that appear in both $_GET and $_POST. With this variable, we can modify our form processing script one more time so that it can receive the first and last names of the user from either source:

File: welcome5.php (excerpt)
<?php
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
echo "Welcome to my Website, $firstname $lastname!";
?>


That covers the basics of using forms to produce rudimentary user interaction with PHP. I’ll cover more advanced issues and techniques in later examples.

By PHP with No comments

PHP Arrays, Learn about Arrays

An array is a special kind of variable that contains multiple values. If you think of a variable as a box that contains a value, then an array can be thought of as a box with compartments, where each compartment is able to store an individual value. The simplest way to create an array in PHP is to use the built-in array function:


$myarray = array('one', 2, '3');
This code creates an array called $myarray that contains three values: 'one', 2, and 'three'. Just like an ordinary variable, each space in an array can contain any type of value. In this case, the first and third spaces contain strings, while the second contains a number.

To get at a value stored in an array, you need to know its index. Typically, arrays use numbers, starting with zero, as indices to point to the values they contain. That is, the first value (or element) of an array has index 0, the second has index 1, the third has index 2, and so on. In general, therefore, the index of the nth element of an array is n–1. Once you know the index of the value you’re interested in, you can get that value by placing that index in square brackets after the array variable name:

echo $myarray[0]; // Outputs 'one'
echo $myarray[1]; // Outputs '2'
echo $myarray[2]; // Outputs '3'


You can also use the index in square brackets to create new elements, or assign new values to existing array elements:

$myarray[1] = 'two'; // Assign a new value
$myarray[3] = 'four'; // Create a new element


You can add elements to the end of an array using the assignment operator as usual, but leaving empty the square brackets that follow the variable name:

$myarray[] = 'the fifth element';
echo $myarray[4]; // Outputs 'the fifth element'

Array indices don’t always have to be numbers; that’s just the most common choice. You can also use strings as indices to create what is called an associative array. This type of array is called associative because it associates values with meaningful indices. In this example, we associate a date with each of three names:

$birthdays['Kevin'] = '1978-04-12';
$birthdays['Stephanie'] = '1980-05-16';
$birthdays['David'] = '1983-09-09';

By PHP with No comments

Saturday, June 2, 2012

PHP Variables and PHP Operators

Variables in PHP are identical to variables in most other programming languages. For the uninitiated, a variable can be thought of as a name that’s given to an imaginary box into which any value may be placed. The following statement creates a variable called $testvariable (all variable names in PHP begin with a dollar sign) and assigns it a value of 3:



$testvariable = 3;

PHP is a loosely typed language. This means that a single variable may contain any type of data, be it a number, a string of text, or some other kind of value, and may change types over its lifetime. So the following statement, if it appears after the statement above, assigns a new value to our existing $testvariable. In the process, the variable changes type: where it used to contain a number, it now contains a string of text:

$testvariable = "Three";


The equals sign we used in the last two statements is called the assignment operator, as it is used to assign values to variables. Other operators may be used to perform various mathematical operations on values:

$testvariable = 1 + 1; // Assigns a value of 2
$testvariable = 1 - 1; // Assigns a value of 0
$testvariable = 2 * 2; // Assigns a value of 4
$testvariable = 2 / 2; // Assigns a value of 1

Each of the lines above ends with a comment. Comments are a way to describe what your code is doing—they insert explanatory text into your code, and tell the PHP interpreter to ignore it. Comments begin with // and they finish at the end of the same line. You might be familiar with the /* */ style of comment used in other languages—these work in PHP as well. I’ll be using comments
throughout the rest of this book to help explain the code I present.

Now, let’s get back to the four statements above. The operators we used are called the arithmetic operators, and allow you to add, subtract, multiply, and divide numbers. Among others, there is an operator that sticks strings of text together, called the concatenation operator:

$testvariable = "Hi " . "there!";
// Assigns a value of "Hi there!"
Variables may be used almost anywhere that you use an actual value. Consider these examples:

$var1 = 'PHP'; // Assigns a value of 'PHP' to $var1
$var2 = 5; // Assigns a value of 5 to $var2
$var3 = $var2 + 1; // Assigns a value of 6 to $var3
$var2 = $var1; // Assigns a value of 'PHP' to $var2
echo $var1; // Outputs 'PHP'
echo $var2; // Outputs 'PHP'
echo $var3; // Outputs '6'
echo $var1 . ' rules!'; // Outputs 'PHP rules!'
echo "$var1 rules!"; // Outputs 'PHP rules!'
echo '$var1 rules!'; // Outputs '$var1 rules!'


Notice the last two lines in particular. You can include the name of a variable right inside a text string, and have the value inserted in its place if you surround the string with double quotes instead of single quotes. This process of converting variable names to their values is known as variable interpolation. However, as the last line demonstrates, a string surrounded with single quotes will not interpolate
the variable names it contains.

By PHP with No comments

PHP Basic Syntax and PHP Commands



PHP syntax will be very familiar to anyone with an understanding of C, C++, C#, Java, JavaScript, Perl, or any other C-derived language. A PHP script consists of a series of commands, or statements. Each statement is an instruction that must be followed the Web server before it can proceed to the next. PHP statements, like those in the above-mentioned languages, are always terminated by a semicolon (;).

This is a typical PHP statement:
echo 'This is a <b>test</b>!';


This is an echo statement, which is used to send output to the browser. An echo statement simply takes the text it’s given, and places it into the page’s HTML
code at the current location. Order this 350 page hard-copy PHP/MySQL book now! 45

Basic Syntax and Commands
In this case, we have supplied a string of text to be output: 'This is a <b>test</b>!'. Notice that the string of text contains HTML tags (<b> and </b>), which is perfectly acceptable. So, if we take this statement and put it into a complete PHP script (echo.php in the code archive), here’s the code we get:


File: echo.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple PHP Example</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<p><?php echo 'This is a <b>test</b>!'; ?></p>
</body>
</html>


If you place this file on your Web server, a browser that views the page will see this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple PHP Example</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>This is a <b>test</b>!</p>
</body>
</html>


Our today.php example contained a slightly more complex echo statement:
File: today.php (excerpt)

echo date('l, F dS Y.');

Instead of giving echo a simple string of text to output, this statement invokes a built-in function called date and passes it a string of text: 'l, F ds Y.'. Built-in functions can be thought of as things that PHP knows how to do without our needing to spell out the details. PHP has many built-in functions that let us do everything from sending email, to working with information stored in various
46 Order this 350 page hard-copy PHP/MySQL book now!

Chapter 3: Getting Started with PHP

types of databases. In this case, the date function produces a text representation of the current date, using the string it is given to determine the format. You may wonder why we need to surround the string of text with both parentheses (()) and single quotes (''). Quotes are used to mark the beginning and end of strings of text in PHP, so their presence is fully justified. The parentheses serve two purposes. First, they indicate that date is a function that you want to call.

Second, they mark the beginning and end of a list of parameters that you wish to provide, in order to tell the function what to do. In the case of the date function, you need to provide a string of text that describes the format in which you want the date to appear.1 Later on, we’ll look at functions that take more than one parameter, and we’ll separate those parameters with commas. We’ll also consider functions that take no parameters at all. These functions will still need the parentheses, though we won’t type anything between them.

By PHP with 1 comment

What is PHP? Introduction about PHP



PHP is a server-side scripting language. This concept is not obvious, especially if you’re used to designing pages with just HTML and JavaScript.

A server-side scripting language is similar to JavaScript in that it allows you to embed little programs (scripts) into the HTML of a Web page. When executed, such scripts allow you to control what appears in
the browser window more flexibly than straight HTML.

The key difference between JavaScript and PHP is simple. JavaScript is interpreted by the Web browser once the Web page that contains the script has been downloaded. Conversely, server-side scripting languages such as PHP are interpreted by the Web server before the page is even sent to the browser. And, once it’s interpreted, the results of the script replace the PHP code in the Web page itself—all the browser sees is a standard HTML file. The script is processed entirely by the server, hence the designation: server-side scripting language.

Let’s look back at the today.php example presented in Chapter 1: File: today.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Today's Date</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>Today's Date (according to this Web server) is
<?php
echo date('l, F dS Y.');
?></p>
</body>
</html>

Most of this is plain HTML; however, the line between <?php and ?> is written in PHP. <?php means “begin PHP code,” and ?> means “end PHP code.” The Web server is asked to interpret everything between these two delimiters, and to convert it to regular HTML code before it sends the Web page to the requesting browser. The browser is presented with something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Today's Date</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>

<p>Today's Date (according to this Web server) is
Sunday, May 16th 2004.</p>
</body>
</html>

44 Order this 350 page hard-copy PHP/MySQL book now!

Getting Started with PHP

Notice that all signs of the PHP code have disappeared. In its place, the output of the script has appeared, and it looks just like standard HTML. This example demonstrates several advantages of server-side scripting:

No browser compatibility issues

PHP scripts are interpreted by the Web server alone, so you don’t have to worry about whether the language you’re using is supported by visitors’ browsers. Access to server-side resources

In the above example, we placed the date, according to the Web server, into the Web page. If we had inserted the date using JavaScript, we would only be able to display the date according to the computer on which the Web browser was running. Now, while this isn’t an especially impressive example of the exploitation of server-side resources, we could just as easily have inserted some other information that would be available only to a script running on the Web server. An example might be information stored in a MySQL database that runs on the Web server computer.

Reduced load on the client JavaScript can slow significantly the display of a Web page on slower computers, as the browser must run the script before it can display the Web page. With server-side scripting, this burden is passed to the Web server machine.

By PHP with No comments

How to start PHP, PHP Syntax to start?


PHP have simple tags to star and ends. PHP star tag is "<?php" and ending with "?>". We place PHP tags anywhere in our page. Normally HTML page have the tags of table or div. we will place any where we want to place PHP.

PHP have the another method to start "<?. This is shorthand methode. Normally we recommended to PHP with "<?php".

Sample PHP

<?php

content need to placed

?>

PHP file extension is ".php".<html>
<html>
<body>


<?php
echo "Welcome to Way2discuss!";
?>


</body>
</html>
In the above example, PHP code written in the body content. PHP script line ends with semicolon.

"echo" - statement used to print the content into our webpage.

PHP have two methods to print the content, One is "echo" and another one is "print".


PHP have the 2 formt to comment the lines as follows

PHP comments : "//" and /* --- */


In PHP, we use // to make a one-line comment or /* and */ to make a comment block:

<html>
<body>

<?php
//This is a way2discuss comment

/*
multi line discussion comment
*/
?>

</body>
</html>

By PHP with No comments

Wednesday, May 16, 2012

PHP: Top 10 SEO URL Rewrite Tips using .htaccess

If you are looking for the examples of URL rewriting then this post might be useful for you. In this post, I’ve given five useful examples of URL rewriting using .htacess. If you don’t know something about url rewriting then please check my older post about url rewriting using .htaccess.
Now let’s look at the examples
1)Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
2) Rewriting product.php?id=12 to product/ipod-nano/12.html
SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
3) Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
5) Redirecting the domain to a new subfolder of inside public_html.
Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1

By PHP with No comments

Basic String Functions for PHP Programmers


PHP Programmer should know the following string functions in PHP.
Note : In the below mentioned functions the parameters marked in < and > tags are mandatory and
the parameters marked in [< and >] are optional
substr()
This function returns the part of the string as an output.
Syntax :
substr(<string>,<start>,[<length>]);
Explanation :
String : It is mandatory parameter. The string from which the part is to be extracted is mentioned
here.
Start : The start in the string from which the characters are to be extracted
· Positive number - Start at a specified position in the string
· Negative number - Start at a specified position from the end of the string
· 0 - Start at the first character in string
Length : It is an optional parameter. It specifies the length of the string which is to be extracted.
· Positive number - The length to be returned from the start parameter
· Negative number - The length to be returned from the end of the string
Example 1:
<?php echo substr("Hello world",6); ?> //Returns world
Example 2 :
<?php echo substr("Hello world",6,4); ?> // Returns worl
Example 3 :
<?php echo substr("Hello world", -1); ?> // Returns d
Example 4:
<?php echo substr("Hello world", -3, -1); ?> // Returns rl
strlen()
This function returns the length of the string
Syntax :
strlen(<string>);
Explanation:
String : It is mandatory field. The string whose length is to be found out is mentioned here.
Example 1:
<?php echo strlen("Hello world"); ?> // Returns 11
trim()
This function removes the whitespaces from both start and the end of the string.
Syntax :
trim(<string>);
Explanation :
String : It is mandatory field. The string of which the whitespaces are to be removed is passed as
parameter.
Example 1:
<?php echo trim( " Hello World "); ?> // returns Hello World. If you go view source then you
can see that there are no whitespaces.
ltrim()
This function removes the whitespaces from the left part of the string.
Syntax :
ltrim(<string>);
Explanation :
String : It is mandatory field. The string of which the whitespaces are to be removed from left side is
passed as parameter.
Example 1:
<?php echo ltrim( " Hello World "); ?> // returns Hello World. If you go view source then you
can see that there are no whitespaces on left side but there are spaces on right side.
rtrim()
This function removes the whitespaces from the right part of the string.
Syntax :
rtrim(<string>);
Explanation :
String : It is mandatory field. The string of which the whitespaces are to be removed from right side
is passed as parameter.
Example 1:
<?php echo rtrim( " Hello World "); ?> // returns Hello World. If you go view source then you
can see that there are no whitespaces on right side but there are spaces on left side
strtolower()
This function converts the string to lower case
Syntax :
strtolower(<string>);
Explanation :
String : It is mandatory field. The string which is to be converted to lower case is passed here.
Example 1:
<?php echo strtolower("HELLO WORLD"); ?> // Returns hello world
strtoupper()
This function converts the string to upper case
Syntax :
strtoupper(<string>);
Explanation :
String : It is mandatory field. The string which is to be converted to upper case is passed here.
Example 1:
<?php echo strtoupper("hello world"); ?> // Returns HELLO WORLD
str_replace()
The str_replace() function replaces some characters with some other characters in a string.
This function works by the following rules:
· If the string to be searched is an array, it returns an array
· If the string to be searched is an array, find and replace is performed with every array
element
· If both find and replace are arrays, and replace has fewer elements than find, an empty
string will be used as replace
· If find is an array and replace is a string, the replace string will be used for every find value
Syntax :
str_replace(<search>,<replace>,<string/array>,[<count>]);
Explanation :
Search : It is mandatory . The string or value to be searched comes here.
Replace : It is mandatory. The string or value to be replaced comes here.
String/Array : It is mandatory. The string or array in which the value is to be found out comes here.
Count : It is optional. It counts the number of replacements to be done.
Example 1:
<?php echo str_replace("world","Peter","Hello world"); ?>// Returns Hello Peter
Example 2:
<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
?>
/*
Output :
Array
(
[0] => blue
[1] => pink
[2] => green
[3] => yellow
)
Replacements: 1
*/
Example 3:
<?php
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
?>
/*
Output :
You should eat pizza, beer, and ice cream every day
*/
strcmp()
The strcmp() function compares two strings.
This function returns:
· 0 - if the two strings are equal
· <0 - if string1 is less than string2
· >0 - if string1 is greater than string2
Syntax :
strcmp(<string1>,<string2>);
Explanation :
String1 : It is mandatory. The first string comes here.
String 2 : It is mandatory. The Second string comes here.
Example 1:
<?php echo strcmp("Hello world!","Hello world!"); ?> //Returns 0
Note: The strcmp() function is binary safe and case-sensitive. For case insensitive comparison you
can use strcasecmp(<string1>,<string2>); function. It is similar to strcmp() function.
explode()
This function breaks the string into array on the basis of delimiter passed.
Syntax:
explode(<delimeter>,<string>,[<limit>]);
Explanation:
Delimeter: It is mandatory field. It specifies where to break the string.
String: It is mandatory. It specifies the string to split.
Limit : It is optional. It specifies the maximum number of array elements to return.
Example 1:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
/* Output :
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
)
*/
implode()
This function join array elements with a string on the basis of delimiter passed.
Syntax:
implode(<delim>,<array>);
Explanation:
Delimiter: It is mandatory field. It specifies what to put between the array elements. Default is "" (an
empty string).
Array: It is mandatory field. It specifies the array to join to a string.
Example 1:
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>
/*
Output:
Hello World! Beautiful Day!
*/

By PHP with No comments

    • Popular
    • Categories
    • Archives