Archive

Posts Tagged ‘Php’

Removing a directory in php with rmdir()

January 7th, 2010 No comments

The php function rmdir() enables developers to remove a directory from the file system. The process trying to delete the directory must have enough permissions and the directory must be empty. The rmdir() function requires a string representing the path to the directory to be deleted. It returns TRUE on success or FALSE on failure.

Example code:

rmdir( "mydir" );
<?php
if (!is_dir('exampledir')) {
    mkdir('exampledir');
}
 
rmdir('exampledir');
?>
Categories: Php Tags:

Getting PHP & Form variable in different operating system

January 7th, 2010 No comments

Why Windows code does not working in Linux and Unix or Linux code does not working in Windows and Unix.

This is the most frequently asked question in PHP. While running a PHP document in Windows we get the form variable by either GET or POST method. For which we use the following code:

$name=$_POST["txtName"]; or $name=$_GET["txtName"];

While using the same code in Linux and Unix you will get a error message. To solve this problem or to run a PHP page in a different operating system without any errors, first declare the GET variables and POST variables globally using the following code. Read more…

Categories: Php Tags:

How to include a file in PHP

January 7th, 2010 No comments

If you have ever wondered how to include another PHP file into a PHP script, this simple one line code sample will show you how.


<?php

// Place this into your PHP page

// and edit the file name

include "some_other_file.php";

?>

Categories: Php Tags: ,

How can I check if a variable is defined?

January 1st, 2010 No comments

if (isset($var)) {
echo “the var is set, and equals $var. It may be empty though.”;
}

http://www.php.net/isset

isset() will tell you is a varaible has been defined. This can bite some
users, because it will return true even if the varable has an empty
value. Look at empty() as well. Sometimes you’ll want to use one rather
than the other. Note that even “0″ and 0 are considered empty. Read more…

Categories: Know more, Php Tags:

How can i do auto redirect using php?

January 1st, 2010 1 comment

Put the following code at the top of your page.

<?
$URL="http://www.yourdomain.com";
header ("Location: $URL");
?>
Categories: Php Tags: ,

How to create WordPress Plugin

November 23rd, 2009 No comments

WordPress blogs are getting more popular then ever, there are literally hundreds of new weblogs popping up everyday. However WordPress is not a new software, so I think it is about time to learn how to create decent plugins for it, and once you learn how to write plugins you will discover that this is not only fun but can be very profitable as well.

I want to show you how to write very simple WordPress (WP) plugin. General purpose behind every plugin is to enhance WP possibilities in some way or another, so I started to think: what kind of plugin will contain no more then 100 lines of code, (so someone who is new to WordPress API won’t get lost in tons of code) and will be somewhat useful at the same time. Read more…

Categories: Wordpress Tags: , ,

PHP DateTime and DateTimeZone Tutorial

November 22nd, 2009 3 comments

With each new version PHP is getting more and more object oriented. In version 5.x we get two useful classes for date and time handling. Many programmers are still using outdated methods which are available in PHP mainly for compatibility reasons, so i want to introduce you to DateTime and DateTimeZone objects.
Server default Timezone

Before i do that, first let’s start with some basics, which tend to cause a lot of troubles in the beginning. Each computer has it’s own default timezone and local time set. If you are using Microsoft Windows, then probably timezone on your local machine is already set correctly, on the other hand if you are using Linux chances are that you will have to do it manually (i had to, however i am not using typical Linux so maybe this is just me). Read more…

Categories: Php Tags:

Creating a Multi-File Upload Script in PHP

November 20th, 2009 No comments

As a PHP programmer I had run into a problem where a client needed a form to upload more than one file at a time. So one night I sat down and spent an hour figuring out the best and easiest way to do this. In this tutorial, the for loop is going to be your best friend.

uploadForm1.php

<html>
<head>
<title># of Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</meta></head>
 <a href="http://www.ashesh.com.np/1088/#more-1088" class="more-link">Read more...</a></html>

Display total online users in web page

November 13th, 2009 No comments

Here, how you can display total number of online user in your webpage you want. Just include file name, which I have given file name as online-user.php here. You need to include this file on any php page you want to display total users online.

I have developed this php script to implement on my own webpage.
See this, I have implement this on http://www.ashesh.com.np/nepali-date-converter.php

    Example for how to include online-user.php in web page.

    < ?php include 'path/online-user.php'; ?>

online-user.php

1
2
3
4
< ?php
$rip = $_SERVER['REMOTE_ADDR'];
$sd  = time();
$count = 1; <a href="http://www.ashesh.com.np/display-total-online-users-in-web-page/#more-1037" class="more-link">Read more...
Categories: How to..., Php, WebDevelopment Tags: ,

How to Send E-Mail using PHP script

November 9th, 2009 No comments

This article explains about sending a simple mail using PHP mail function.

Creating a Email Form using HTML

1
2
3
4
5
6
7
<form method="post" action="">
Sender Email: <input type="text" name="sender_email" size="18" />
Receipent Email: <input type="text" name="receipent_email" size="18" />
Mail Subject: <input type="text" name="email_subject" size="18" />
Email Message: <textarea name="message" rows="50" cols="6"></textarea>
<input type="submit" name="submit" value="Send Email" />
</form>

Read more…

Categories: How to..., Php Tags: