Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Sunday, January 22

ViewData, ViewBag and TempData in ASP.Net MVC

ViewBag

– ViewBag is used to send a small amount of data to the view.
– There may be some situation where you want to transfer some temporary data to view which is not included in the model object.
– The viewBag is a dynamic type property of ControllerBase class.
– It does not retain value when redirection occurs,it is available only for Current Request.
– ViewBag is a dynamic property and it makes use of the C# 4.0 dynamic features.
public class DemoController : Controller
{
IList CarList = new List() {
new Car(){ CarName=”i10″, CarColor=”Black”,CarMileage=18.2 },
new Car(){ CarName=”EON”, CarColor=”Silver”, CarMileage=18.2 },
new Car(){ CarName=”Swift”, CarColor=”Red”, CarMileage=18.2},
new Car(){ CarName=”Verna”, CarColor=”Black”, CarMileage=18.2},
new Car(){ CarName=”Ciaz”, CarColor=”Silver”, CarMileage=18.2}
};
public ActionResult Index()
{
ViewBag.TotalCar = CarList.Count();
return View();
}
}

ViewData

– ViewData is similar to ViewBag, It can be used to send data from controller to view.
– It is a dictionary , which possese key-value pairs, where each key must be string.
– Viewdata last long only for current http request.
public class DemoController : Controller
{
public ActionResult Index()
{
ViewData[“Simple”] = “This string is stored in viewData.”;
return View();
}
}
To get back value from viewData write below line in view.

@ViewData[“Simple”]

TempData

– TempData retain value across subsequent HTTP Request
– It can be use to maintain data between controller actions as well as redirects.
– It internally stores data in session but it get destroyed earliar than session.
In the below example, a string value is stored in the TempData object in JupiterController
and it is redirected to EarthController and finally it is displayed in View.
public class JupiterController : Controller
{
// GET: First
public ActionResult Index()
{
TempData[“Message”] = “Jupiter is largest planet in solar system”;
return new RedirectResult(@”~\Earth\”);
}
}
public class EarthController : Controller
{
// GET: Second
public ActionResult Index()
{
return View();
}
}
View of EarthController
<html>
<head>
<meta name=”viewport” content=”width=device-width”/>
<title>Solar System</title>
</head>
<body>
<div>
@TempData[“Message”];
</div>
</body>
</html>

Tuesday, January 3

QR code – How to generate QR code in php

How to generate QR code in PHP

In this post we will generate QR code (Quick Response Code) using php. QR code is used to read data with smart devices for easy.
Hear pass you uel and it will generate qr code of you url.

<?php
// include QR Generator class
include "QRGenerator.php";

// check for post method call.
if($_SERVER["REQUEST_METHOD"] === "POST")
{
    $set_url = $_POST['set_url'];
    $set_size = $_POST['set_size'];
    $example_1 = new QRGenerator($set_url,$set_size);
    $qr_img_1 = "<img src=".$example_1->generate().">";
    $html_content ='<form method="post" action="">
        <table>
            <tr>
                <td colspan="2">'.$qr_img_1.'</td>
            </tr>         
            <tr>
                <td>Text/URL</td>
                <td><input type="text" name="url" /></td>
            </tr>         
            <tr>
                <td>Size</td>
                <td><input type="text" name="size" /> <i>min: 100 and max: 800</i></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input type="submit" name="generate" value="Generate" /></td>
            </tr>
        </table>
    </form>';
}
else
{
    $html_content ='<form method="post" action="">
    <table>
        <tr>
            <td>Text/URL</td>
            <td><input type="text" name="set_url" /></td>
        </tr>         
        <tr>
            <td>Size</td>
            <td><input type="text" name="set_size" /></td>
        </tr>
        <tr>
            <td rowspan="2"><i>min: 80 and max: 800</i></td>
        </tr>
        <tr>          
            <td>
                <input type="submit" name="generate" value="Generate" />
            </td>
            <td>
                <input type="reset" name="reset" value="reset" />
            </td>
        </tr>
    </table></form>';
    $example_1 = new QRGenerator('http://onlinecode.org',100);
    $qr_img_1 = "<img src=".$example_1->generate().">";
     
    $example_2 = new QRGenerator('https://in.yahoo.com/',100);
    $qr_img_2 = "<img src=".$example_2->generate().">";

    $example_3 = new QRGenerator('https://www.google.com/',100,'ISO-8859-1');
    $qr_img_3 = "<img src=".$example_3->generate().">";

    $example_4 = new QRGenerator('https://www.bing.com',100,'ISO-8859-1');
    $qr_img_4 = "<img src=".$example_4->generate().">";

    $html_content .='
    <table>
        <tr>
            <td>'.$qr_img_1.'</td>
            <td>'.$qr_img_2.'</td>
        </tr>         
        <tr>
            <td>'.$qr_img_3.'</td>
            <td>'.$qr_img_4.'</td>
        </tr>
    </table>';
}
$pre = 1;
$page_title = "How to generate QR code in PHP | onlinecode";
$page_heading = "How to generate QR code in PHP example - onlinecode";
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>
            <?php
                // add page title
                echo $page_title;
            ?>
        </title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <style type="text/css">
          img {border-width: 0}
          * {font-family:'Lucida Grande', sans-serif;}
        </style>
    </head>
    <body>
        <div>
            <h2>
                <?php
                    // add page heading
                    echo $page_heading;
                ?>
            </h2>
            <p>
                <!-- add this tag after last badge tag -->
                <script type="text/javascript">
                    (function() {
                        var qr_var = document.createElement('script');
                        // assign javascript
                        qr_var.type = 'text/javascript';
                        // assign async
                        qr_var.async = true;
                        // assign javascript                    
                        qr_var.src = 'https://apis.google.com/js/plusone.js';
                        // get script
                        var get_script = document.getElementsByTagName('script')[0];
                        get_script.parentNode.insertBefore(qr_var, get_script);
                    })();
                </script>
        </div>
        <hr />     
        <p>
        <?php
            if(!isset($pre)) {
        ?>
            <pre>
                <?php
                    print_r($html_content);
                ?>
            </pre>
        <?php } else  { ?>
            <pre>
                <?php
                    print_r($html_content);
                ?>
            </pre>   
        <?php  } ?>
        </p>
    </body>
</html>

class of QRGenerator

 <?php
// assign class QRGenerator
class QRGenerator {
    // assign protected variable
    protected $qr_size;
    protected $qr_data;
    protected $qr_encoding;
    protected $qr_errorCorrectionLevel;
    protected $qr_marginInRows;
    protected $qr_debug;
  
    // assign construct
    public function __construct($qr_data='http://onlinecode.org',$qr_size='100',$qr_encoding='UTF-8',$qr_errorCorrectionLevel='L',$qr_marginInRows=4,$qr_debug=false)
    {        
        $this->qr_data = urlencode($qr_data);
        $this->qr_size = ($qr_size>80 && $qr_size<800)? $qr_size : 100;
      
        $this->qr_encoding = ($qr_encoding == 'Shift_JIS' || $qr_encoding == 'ISO-8859-1' || $qr_encoding == 'UTF-8') ? $qr_encoding : 'UTF-8';
      
        $this->qr_errorCorrectionLevel = ($qr_errorCorrectionLevel == 'L' || $qr_errorCorrectionLevel == 'M' || $qr_errorCorrectionLevel == 'Q' || $qr_errorCorrectionLevel == 'H') ?  $qr_errorCorrectionLevel : 'L';
      
        $this->qr_marginInRows=($qr_marginInRows>0 && $qr_marginInRows<10) ? $qr_marginInRows:4;
        $this->qr_debug = ($qr_debug==true)? true:false;   
    }
    // function generate
    public function generate()
    {        
        $QRLink = "https://chart.googleapis.com/chart?cht=qr&chs=".$this->qr_size."x".$this->qr_size.               
                   "&chl=" . $this->qr_data .
                   "&choe=" . $this->qr_encoding .
                   "&chld=" . $this->qr_errorCorrectionLevel . "|" . $this->qr_marginInRows;
        if ($this->qr_debug)
        {
            echo $QRLink;
        }
        return $QRLink;
    }
}
?>

 

Ubuntu – How To Install Linux, Apache, MySQL, PHP (LAMP) stack

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu

The following instructional exercise presumes you comprehend what a LAMP(Linux, Apache, MySQL, PHP) Server is, the means by which to work a site from the back end and how to introduce programming utilizing either the Software Center or the Terminal.

It additionally expect encounter running other Basic Terminal Commands.

There is additionally a phenomenal article on Digital Ocean that might be of more pertinence on the off chance that you are taking a shot at a remote or open confronting server.

1. Introduce Apache

To install Apache you should install the Metapackage apache2. This should be possible via hunting down and introducing in the Software Center, or by running the following order.

1
sudo apt-get install apache2
 
2. Install MySQL

To Install MySQL you should Install the Metapackage mysql-server. This should be possible via hunting down and introducing in the Software Center, or by running the following command.
1
sudo apt-get install mysql-server
 
3. Introduce PHP

To introduce PHP you should introduce the Metapackages php5 and libapache2-mod-php5. This should be possible via hunting down and introducing in the Software Center, or by running the following command.

1
sudo apt-get install php5 libapache2-mod-php5
 
4. Restart Server 

Your server ought to restart Apache consequently after the establishment of both MySQL and PHP. In the event that it doesn’t, execute this command.
1
sudo /etc/init.d/apache2 restart

5. Check Apache
Open a web program and explore to http://localhost/. You ought to see a message saying It works!

6. Check PHP
You can check your PHP by executing any PHP record from inside /var/www/. On the other hand you can execute the following command, which will make PHP run the code without the requirement for making a record.
 
1
php - r 'echo "sucess :: Your PHP installation is working fine. thanks to onlinecode.org";'

remove .php, .html, .htm extensions using .htaccess

htaccess – How to remove .php, .html, .htm extensions with .htaccess

we are going to show you how to remove .php, .html, .htm extensions with .htaccess file.

Remove .php, .html, .htm Extensions

To remove the .php extension from a PHP file as an example your-domain.com/your-page.php to your-domain.com/your-page you’ve got to feature the subsequent code within the .htaccess file ::

RewriteEngine On
RewriteCond % !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

If we would like to get rid of the .html extension from a HTML file as an example your-domain.com/your-page.html to your-domain.com/your-page you just ought to alter the last line from the code higher than to match the computer filename ::

RewriteRule ^([^\.]+)$ $1.html [NC,L]

That’s it! you’ll currently link pages within the HTML document without having to feature the extension of the page.

example:

<a href="http://your-domin-name.com/your-dir" title="your-dir">NAME-OF-LINK</a>

Adding a trailing slash at the tip

I received several requests asking a way to add a trailing slash at the tip. Ignore the primary piece and insert the subsequent code.

The primary four lines modify the removal of the extension and therefore the following, with the addition of the trailing slash and redirecting.

Link to the HTML or PHP file as shown higher than. Don’t forget to alter the code if you would like it applied to associate HTML file.

RewriteEngine On
RewriteCond % !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond % !-f
RewriteCond % !-d
RewriteCond % !(\.[a-zA-Z0-9]|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
 
Some individuals asked however you’ll take away the extension from each HTML and PHP files. I haven’t got a writing resolution for that.
But, you’ll simply modification the extension of your HTML file from .html or .htm to .php and add the code for removing the .php extension.

Conclusion for Removing Extensions

For those that don’t seem to be thus skilled with .htaccess files there’s an internet tool for making .htaccess files. it’s pretty smart for novice users and really straightforward to use. Visit their web site.

Note For GoDaddy User

Attention For GoDaddy users only ::

so as to get rid of the extensions you wish to modify MultiViews before.

The code ought to appear as if this ::

Options +MultiViews
RewriteEngine On
RewriteCond % !-d
RewriteCond % !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

If you’re disquieted that search engines may index these pages as duplicate content, add a canonical meta tag in your HTML head :: 

<link rel="canonical" href="https://your-domin-name.com/your-dir/other-data">

 

 


10 Best Chatting Apps In India

  The modern world is all about Internet. There was a time when people use to pay high telephone bills to stay in touch with their friends a...