Unable to redirect from one page to another page

how to redirect to another page in javascript with parameters
how to redirect to another page in javascript on button click
javascript redirect on page load
jquery redirect to same page with parameters
redirect to another page in php
html redirect to another page
javascript redirect to relative url
how to redirect to another page in php on button click

Main1.php

        <?php 

            class Main1 extends CI_Controller { 

                public function index() { 
                    //Load the URL helper
                    $this->load->helper('url'); 

                    //Redirect the user to some site
                    redirect('http://localhost/CodeIgniter/index.php/Main'); 

                   $this->load->view('test1'); 
                } 
            } 
        ?>

test1.php

    <!DOCTYPE html>
    <html>
        <head>
            <title>view page</title>
        </head>
        <body style="padding-top:50px; padding-left:300px">
                <h1 style="color:red"> Without Extension </h1>
                <a href="">Visit With Extension Example</a>
        </body>
    </html>

Main.php

    <?php 

        class Main extends CI_Controller { 

            public function index() { 
                $this->load->view('test.html'); 
            } 
        } 
    ?>

test.html

    <!DOCTYPE html>
    <html>
        <head>
            <title>view page</title>
        </head>
        <body style="padding-top:50px; padding-left:300px">
                <h1 style="color:red"> With Extension </h1>

        </body>
    </html>

I'm purely new to this codeignitor concept, i know its really a stupid question, but please guys try t help me .Actually when i click the link im trying to redirect one page to another page and vice versa using codeignitor functions , but im unable to do this please can any one tel me where im going wrong,sorry i know its really stupid question but not getting how to do.


If you want to have a link that moves you from one page to another the redirect() function is not the answer. A "redirect" is effectively the same as typing a new URL in a browser - only it is done programmatically.

The <a> HTML tag is used to create a link to another URL in the user interface.

Here are revised files that will do what you want. Note that the redirect() call has been removed.

/controllers/Main.php

<?php

class Main extends CI_Controller
{
    public function index()
    {
        //Load the URL helper
        $this->load->helper('url');
        //load the view
        $this->load->view('test.html');
    }
}

Please note that there is no PHP closing tag ie. ?> at the end of the file. As stated in the PHP documentation

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

/views/test.html is the view file loaded by the controller above.

<!DOCTYPE html>
<html>
        <head>
                <title>view page</title>
        </head>
        <body style="padding-top:50px; padding-left:300px">
                <h1 style="color:red">HTML file view</h1>
                <a href='<?= base_url('main1');?>'>View using php extension</a>
        </body>
</html>

Here are the other pair of files for loading a php view file.

/controllers/Main1.php

<?php
class Main1 extends CI_Controller
{
    public function index()
    {
        $this->load->helper('url');
        $this->load->view('test1');
    }
}

/views/test1.php

<!DOCTYPE html>
<html>
    <head>
        <title>view page</title>
    </head>
    <body style="padding-top:50px; padding-left:300px">
        <h1 style="color:red">PHP view file</h1>
        <a href='<?= base_url('main');?>'>View using html Extension</a>
    </body>
</html>

FWIW, there is no advantage in using .html files for your views, but there is a disadvantage. The problem will be that sometimes you will need to execute a little PHP in a view which means it must use .php for the extension. Soon you are trying to juggle a mix of .html and .php view files and before you know it you're confused and angry that things aren't working the way you expected. Make life easier and stick to .php for view files - even if there isn't any PHP code in the file.

How to redirect a page to another page in HTML ?, . Also, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. I have a scenario where from one page in AEM, I need to call another AEM page in the same application and I need to pass some hidden parameters. I choose to do it via POST and below are the steps which I followed: From page "A", I did a form submission via POST to the sling servlet and passed some


Just use redirect with your destination path (controller/method [if index, controller name is enough] )

redirect('main');

You can use redirect with these scenarios

  1. Controller redirect (automatically call index function)
  2. Controller method redirect (main/test)
  3. route redirect (main-test where main-test pointed to the specific method)

FYI : once redirect function reached, any code below that won't get executed

4 Ways JavaScript Can Redirect Or Navigate To A Url Or Refresh , How do I redirect a section of a page in HTML? Here Mudassar Ahmed Khan has explained with an example, how to redirect from one Page to another on Button Click in HTML. HTML Button cannot perform redirect similar to a HyperLink and hence using JavaScript a Click event handler is attached to the Button and then using JavaScript window.location property Page will be redirected to another Page.


You can use header('Location: http://www.example.com/'); if you wants redirect external link of any page

How to Redirect to Another Web Page Using jQuery / JavaScript, You can use this techique from your JavaScript to trigger page updates. There are many reasons why you might want to redirect to a new page or URL. Redirect from HTTP to HTTPS; You need to trigger a new page in a single page application page. Both may fail if there are security restrictions. How do I redirect a web page to another? I have a page with a .dk top level domain and one with .com and would like the .dk to automatic forward visitors to my .com domain. I've found 4 lines on the web describing the code but it doesn't work. And can the same be done if you just own the domain name and doesn't have space on a web server? •


How to Make HTML Redirect to Another Page: A Complete Guide, If you want to redirect the user from one page to another automatically, you can originating page in the session history, meaning the user won't be able to use  How to redirect one page to another page in reactJS? Ask Question Asked 1 year, 7 months ago. TypeError: Cannot read property 'history' of undefined.


Unable to redirect to another page in AEM using re, Find out how to make HTML redirect to another page with a beginner-friendly tutorial. If a user types a URL of the old one into their browser, it will return which the user might click manually if the HTML redirect code fails. JavaScript Redirect to a URL. Many URLs are redirected to new locations, typically using a server configuration and HTTP header properties. But there are many scenarios where you may need to use JavaScript to redirect or navigate to another URL. There are many reasons why you might want to redirect to a new page or URL.


How to make a redirect in PHP?, I have a scenario where from one page in AEM, I need to call another AEM page in the same application and I need to pass some hidden - 291075. Spring - Page Redirection Example - The following example show how to write a simple web-based application which makes use of redirect to transfer a http request to another page.