1

I have a problem when the login button is pressed the url becomes

http://localhost/library% 20/-login/login_aksi

How do I get rid of %20?

error

Controller

function login_aksi() {

        if ($sebagai == "admin") {
            $cek = $this->m_data->cek_login('admin', $where)->num_rows();
            $data = $this->m_data->cek_login('admin', $where)->row();
            if ($cek > 0) {
                $data_session = array(
                    'id' => $data->id,
                    'username' => $data->username,
                    'status' => 'admin_login'
                );
                $this->session->set_userdata($data_session);
                redirect(base_url() . 'admin');
            } else {
                redirect(base_url() . 'login?alert=gagal');
            }

View

<body class="bg-dark">
    <div class="container">
        <br /><br /><br /><br />
        <h3 class="font-weight-normal text-center text-white">SISTEM
            INFORMASI</h3>
        <h2 class="font-weight-normal text-center text-white mb5"><b>PERPUSTAKAAN</b></h2>
        <div class="col-md-4 offset-md-4">
            <div class="card">
                <div class="card-body">
                    <?php
                    if (isset($_GET['alert'])) {
                        if ($_GET['alert'] == "gagal") {
                            echo "<div class='alert alert-danger font-weight-bold textcenter'>LOGIN GAGAL!</div>";
                        } else if ($_GET['alert'] == "belum_login") {
                            echo "<div class='alert alert-danger font-weight-bold textcenter'>SILAHKAN LOGIN TERLEBIH DULU!</div>";
                        } else if ($_GET['alert'] == "logout") {
                            echo "<div class='alert alert-success font-weight-bold textcenter'>ANDA TELAH LOGOUT!</div>";
                        }
                    }
                    ?>
                    <h4 class="font-weight-bold text-center mb-3 mt-3">LOGIN</h4>
                    <!-- validasi error -->
                    <?php echo validation_errors(); ?>
                    **<form method="post" action="<?= base_url() . 'login/login_aksi'; ?>">**
       
Kartika
  • 11
  • 3
  • 3
    Looks like your `base_url()` has a space in it (%20 is a url-encoded space). – prieber May 21 '21 at 15:26
  • You have space before URL encoding, remove it first. – biesior May 21 '21 at 15:28
  • Agreed. Use trim() inside your base_url() function – Beshambher Chaukhwan May 21 '21 at 15:28
  • Please share more details - what have you tried to resolve the problem? Where are you stuck? – Nico Haase May 21 '21 at 15:33
  • so I added a trim to action = " = base_url (). 'login / login_action';?>">? sorry if my question is weird i'm still a beginner – Kartika May 21 '21 at 15:35
  • @NicoHaase when pressing the login button it should be directed to the url http: // localhost/perpustakaan/ admin. But the problem is when the login button is pressed, a 404 Page Not Found appears and the URL becomes% 20, even though the tutorial I followed was not like that – Kartika May 21 '21 at 15:40
  • Please add all clarification to your question by editing. Also, either add the JS code that is helpful here, or remove that tag – Nico Haase May 21 '21 at 16:06

4 Answers4

0

Replace your form tag with the following code

<form method="post" action="<?=base_url()?>login/login_aksi">

0

%20 is an URL encoded space. You can use a dash - or an underscore _ instead of a space.

let character = ' '; // Space Character
let charCode = character.charCodeAt(0); // Get The Space's Char Code
let hex = charCode.toString(16).padStart(2,'0'); // Hex Representation (in URL)

let enc = encodeURIComponent(character);

console.log('Character: "' + character + '"');
console.log('Charcode: ' + charCode);
console.log('Hex: ' + hex);
console.log('Enc: ' + enc);

So if you wanted to know why you see %20 rather than a space, it is because the hex representation of the space is put in the url bar. If a browser didn't encode the space, it would be considered unsafe. Check out this other Stack Overflow question that explains if you should include a space in a URL.

quicVO
  • 778
  • 4
  • 13
0

config/config.php: $config['base_url'] = 'http ://localhost/library /';->if you have something similar remove space from this line.

user27976
  • 149
  • 1
  • 7
0

Replace your form tag with the following code

<form method="post" action="<?=base_url()?>login/login_aksi">

If this is not working then check you config file and base url their must space before (/)