Binod's Blog

Web Designing

Defining class in PHP

by on Sep.19, 2011, under PHP, Technology, Web Designing

This is a simple Example of Defining a class in PHP.

<?php
class test
{
function do_test()
{
echo “Testing class function.”;
}
}

$test_object = new test;
$test_object->do_test();
?>

The Output will be

Testing class function.

Leave a Comment : more...

E-mail Script in PHP

by on Sep.18, 2011, under PHP, Web Designing

This is an example of simple e-mail script for PHP that can be used.

<?php
//define the receiver of the email
$to = ‘someone@somemail.com’;
//define the subject of the email
$subject = ‘Test email’;
//define the message to be sent. Each line should be separated with \n
$message = “Hello World!\n\nThis is my first mail.”;
//define the headers we want passed. Note that they are separated with \r\n
$headers = “From: webmaster@example.com\r\nReply-To: webmaster@example.com”;
//send the email
$mail_sent = mail( $to, $subject, $message, $headers );
//if the message is sent successfully print “Mail sent”. Otherwise print “Mail failed”
if($mail_sent){
print “Mail sent”;
}
else {
print “Mail failed.”;
}

?>

Leave a Comment : more...

Embed your font in website

by on Sep.17, 2011, under Tips & Tricks, Tutorial, Web Designing

I was thinking to embed my own font to the website but How??  suppose i am making a website with a nepali font ie Preeti. But the problem is there is no font installed in my clients computer, so i receive the unwanted output. to fix it i started to search n finally i m with the solution. Here it goes.

Demo Font Taken is “PREETI_1.TTF”

To embed this font on your web page, you will need to place the following CSS code in the <head> section of your page, or in an external CSS file:

<style type="text/css">
@font-face {
 font-family: MyCustomFont;
 src: url("PREETI_1.eot") /* EOT file for IE */
}
@font-face {
 font-family: MyCustomFont;
 src: url("PREETI_1.TTF") /* TTF file for CSS3 browsers */
}
</style>

Note that in the code above, “MyCustomFont” can be any name you want. You will probably want to set this to be the real name of your font.

To use your embedded font, you can simply refer to it by name like you do with any other font. Some examples:

body {
 font-family: MyCustomFont;
 font-size: medium;
 color: black
}
span.header {
 font-family: MyCustomFont;
 font-weight: bold;
 color: red
}

Don’t see your font?

There are two likely reasons why your font isn’t working. First, make sure you’re using a browser that supports embedding fonts. Firefox 3.5 and Internet Explorer 4+ are browsers that support them. If you’re not using a browser that supports embedded fonts, you won’t see your font in the example above.

Cheers !! Enjoy Your Fonts in Your Website. let the client see what you want to show

Leave a Comment :, , more...

Passing JavaScript variables to PHP

by on Aug.28, 2011, under Javascript, PHP, Tips & Tricks, Tutorial, Web Designing

What if I can pass variables between 2 scripting language. JavaScript is mainly used as a client side scripting language, while PHP is a server side technology. Unlike Java or ASP.Net, PHP doesn’t have tools to make it work client side. That is why you need to combine JavaScript and PHP scripts to develop powerful web-applications.

One of the frequent problems is defining visitor’s screen resolution using JavaScript tools and passing this data to PHP-script. The following script provides solution for this problem:

<!—index.htm –>
<script type=”text/javascript”>
width = screen.width;
height = screen.height;
if (width > 0 && height >0) {
window.location.href = “http://localhost/main.php?width=” + width + “&height=” + height;
} else
exit();
</script>

Copy and paste this code snippet in the text editor, save it as index.htm and run it in your browser. After this code has been executed, a user is automatically redirected to the main.php page where screen resolution is displayed in the browser window.

The main.php looks as follows:

<!—main.php –>
<?php
echo “<h1>Screen Resolution:</h1>”;
echo “Width  : “.$_GET['width'].”<br>”;
echo “Height : “.$_GET['height'].”<br>”;
?>

As you can see, passing JavaScript variables in PHP is similar to sending data using GET method.

Leave a Comment :, , more...

Get File Extension in PHP

by on Aug.28, 2011, under PHP, Tips & Tricks, Tutorial, Web Designing

Today I will be sharing some piece of code for getting the real file extension of the uploaded file. I was working on the CMS few days back and there I made the file upload section but I didn’t checked which type of file is been uploaded. During my testing phase I just tested for jpeg file.[ as it was my target]. I hosted it over my server, it was working fine…

The next day, I received a wall post on Facebook from my friend. Binod, you got a security flaw in ur script. I checked it. What he did was he uploaded his scripted file [PHP file] thru that upload section and started to traverse my whole server files.

Then, I realized I need to check the extension of the file and to block the unwanted extension. (E.g. “php” from “myscript.php”).

Here is some piece of code of my CMS that will be beneficial for the users.

//for the upload page

<input type=”file” name=”myfile” />

//for the submit page

$fileatt = $_FILES['myfile']['tmp_name'];
$filename = $_FILES['myfile']['name'];

//there are Five ways that may be helpful

// 1. The “explode/end” approach
$ext = end(explode(‘.’, $filename));

// 2. The “strrchr” approach
$ext = substr(strrchr($filename, ‘.’), 1);

// 3. The “strrpos” approach
$ext = substr($filename, strrpos($filename, ‘.’) + 1);

// 4. The “preg_replace” approach
$ext = preg_replace(‘/^.*\.([^.]+)$/D’, ‘$1′, $filename);

//5. The “pathinfo” approch
$ext = pathinfo($filename, PATHINFO_EXTENSION);

//Checking The uploaded
if(($ext==”jpg”)||($ext==”jepg”)||($ext==”gif”)||($ext==”png”)){
// Uploading and processing script
}else{
// Error script amd msg
}

Leave a Comment :, , more...

Using XAMPP and IIS together

by on May.23, 2011, under Technology, Tips & Tricks, Web Designing

Today I installed IIS in my windows, it worked…. OMG i just remembered i had installed XAMPP (the windows flavor of Apache, MySQL, Perl and PHP) as well and when i started running it the Apache Server couldn’t get started. When i looked for the issue i could see that IIS uses port 80 for its functioning so Apache of XAMPP couldn’t get started. I guess most of the Web Developers who needs to install both services might be facing this problem, As i did. Today i got a solution for that.

Snap Shots: This is a snapshot when i try to run apache, the service of Apache couldn’t get started. [IIS has already been installed and it doesn't allow to use port 80]

xaamp

There are two ways to solve this:

  • Either change IIS (the harder way)
  • Change the Apache config (the easier way)

from both way you’ll achieve the same thing. Personally I went the Apache route and here’s how I did it (using XAMPP ).

Only one way Change the  Default Port

By default IIS uses ports 80 and 443 for HTTP and HTTPS access respectively. By default, Apache also assumes these same settings. By altering two config files in Apache you can easily over-ride this:

Steps to go:

Firstly find xampp\apache\conf\httpd.conf

  • Find Listen :80 …. Change to 81 [this tells Apache to listen to all IP addresses on port 81]
  • Again find ServerName localhost:80 change it to 81

Secondly find xampp\apache\conf\extra\httpd-ssl.conf

  • Find Listen 443…. Change to 442 [This changes the SSL (HTTPS) port to 442 (or again, your port of choice).]

Snap Shot : I edit the two files as mentioned above.

edit

Finally You are done….Enjoy Both Servers at the same time

apapa

The Service had been Started after editing 2 files.

iis xaa

NOTE: When You start the XAMPP in browser type : localhost:81

Leave a Comment :, , , more...

Uploding photo using HTML and PHP

by on Apr.18, 2011, under PHP, Tips & Tricks, Web Designing

First create a form to choose a pic as code shown below

<html>
<head>
<title>Uploading the picture using html and php</title>
</head>
<body bgcolor=”#C0C0C0″ leftmargin=”0″ topmargin=”0″ marginwidth=”0″ marginheight=”0″>
<div align=”center”>

<form enctype=”multipart/form-data” name=”form” method=”post” action=”submit.php”>
Main File:<input type=”hidden” name=”MAX_FILE_SIZE” value=”5000000″ />
<input name=”pic_file” type=”file” />

<br />    Thumb File:<input type=”hidden” name=”MAX_FILE_SIZE” value=”2000000″ />
<input name=”thumb_file” type=”file” />
<input type=”submit”>
</form>

</div>
</body>
</html>

 

After this as the form had been submitted into the submit.php page create a new page submit.php as below

<?php
$file_name = “binod”;

// for main file
$target_path = “test/pic_”.$file_name;
$target_path = $target_path . basename( $_FILES['pic_file']['name']);
$man_file=$target_path;
if(move_uploaded_file($_FILES['pic_file']['tmp_name'], $target_path)) {
$m_result= “<h3><font color=#800000>Main Pic</font> “.  basename( $_FILES['pic_file']['name']).”&nbsp;&nbsp;has been uploaded
</font>”;
}
else{
$m_result=”<h3>There was an error uploading the file, Error may be because of maximum file size of connection interruption.. Please try again! ! !</h3>”;
}

// for thumb file
$target_path = “test/thumb_”.$file_name;
$target_path = $target_path . basename( $_FILES['thumb_file']['name']);
$thumb_file=$target_path;
if(move_uploaded_file($_FILES['thumb_file']['tmp_name'], $target_path)) {
$d_result= “<h3><font color=#800000>Thumbnail File</font> “.  basename( $_FILES['thumb_file']['name']).”&nbsp;&nbsp;has been uploaded
</font>”;
}
else{
$d_result= “<h3>There was an error uploading the file, Error may be because of maximum file size of connection interruption.. Please try again! ! !</h3>”;
}

?>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body bgcolor=”#C0C0C0″ leftmargin=”0″ topmargin=”0″ marginwidth=”0″ marginheight=”0″>
<div align=”center”>
<?php echo “Thank You <b> </b> <br><br>”. ” Your following details has been sent successfully.<br><br>”;
echo $m_result.”<br>”;echo   $d_result.”<br>”;
?>
</div>
</body>

</html>

Finally run using localhost  and DO NOT FORGET TO CREATE A ‘test’ FOLDER IN ROOT. and in server give the write mode to the test folder

4 Comments :, , more...

Domain name tips

by on Mar.04, 2011, under General, Technology, Web Designing

Domain name is the center of your Internet identity. So what type of things should you take into consideration when choosing the name that will represent you on the Web? I am giving you these 8 tips.

1. Keep it short and Unique

Although some places allow you to register a name with up to 63 characters, you have to keep in mind that people need to be able to remember it, and easily type it into their browser. Try to register the shortest name that your customers and visitors will associate with your Website. The general rule of thumb is, keep it under seven characters if possible. (Not including the suffix.)
2. Dot What?[.???]

There are many different extensions available right now. For businesses, we recommend a .com suffix. It is the first extension that most people try when searching for a Website. Also, since it is one of the oldest extensions, .com shows that your business has been around for a while and that you have a well-established presence on the Web.

3. Avoid Trademarked Names

There are two really good reasons for this. First, it’s not very nice. We have all heard the stories about the zany guy who thought ahead and bought “some-huge-multi-million-dollar-company.com” and sold it to the company for enough money to retire on. But, remember that those companies, like yours, have spent lots of time and money creating their brand, and what goes around comes around. Also, companies are no longer opening their pocketbooks to get their names back. They are calling their lawyers.

4. Register Your Domain NOW

Domain names are being snatched up faster than candy. You must register soon unless you want to get stuck with “the-domain-name-that-no-one-wanted.net”. You do not have to have a Webmaster or an ecommerce department or a Web design consultant or… Heck, you don’t even need a Web page. Just get out there and register before you loose the opportunity to get the name you really want. just log on to any registrars website like “www.godaddy.com” or many other and start to buy it now.

5. One May Not Be Enough

Sometimes, it isn’t a bad idea to register several similar domain names. If you have “yourname.com”, register “yourname.net” so no one else takes it. You can register your full company name and a shorter, easier to remember version. Some people even register common misspellings of their company’s name. (You don’t need a separate Web page for each. Several domains can point to the same Website.)

6. Character Types

Just a reminder. Domain names can only use letters, numbers, and dashes. Spaces and symbols are not allowed. Also, domain names are not case sensitive.

7. Ask Around

When you have settled on several available name choices, see what your friends and clients have to say. A name that may make perfect sense to you may be too hard for other people to remember. Is your domain easy to say? Is it hard to spell? Do you have to explain why you chose the name? Don’t make domain that will have confusion in the Spelling, Don use local names.

8. Some Domain Registar Websites.

  • www.godaddy.com
  • www.maddogdomains.com
  • www.mochahost.com
  • www.register.com

For Registering .np domain log on to http://www.mos.com.np

And remember, if you think that if you have found the right domain name, but you’re not quite sure if it’s the one… register it anyway before someone else does!

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...