hi everyone im new to php frameworks development at all, and i can't make this code run please help me im using xampp
my welcome controller
<?php
class Welcome extends CI_Controller
{
public function index()
{
$this->load->view('home');
}
}
home view
<html>
<head>
<title>CTS - home</title>
<style type="text/css">
.auto-style1 {
text-align: center;
}
</style>
</head>
<body bgcolor="#C0C0C0" style="height: 226px">
<div class="auto-style1" style="height: 118px">
<img alt="" height="126" src="<?php echo $this->config->item('base_url'); ? >/IMG/YUC.png" style="float: left" width="147">
<center><h1 style="height: 39px; width: 696px">Cooperative Training Management System</h1></center>
</div>
<br>
<hr>
<div class="auto-style1">
<a href="<?php echo site_url('') ?>users/login">
<img alt="YUC Employee" height="410" src="<?php echo $this->config- >item('base_url'); ?>/IMG/employee.png" width="139">
</a>
<img alt="trainer" height="410" src="<?php echo $this->config->item('base_url'); ? >/IMG/Trainer.png" width="145">
<a href="<?php echo site_url('') ?>users/login">
<img alt="Student" height="410" src="<?php echo $this->config->item('base_url'); ? >/IMG/student.png" width="129">
</a>
<h3>Employee   ; Trainer   ; Student</h3>
</div>
<hr>
<p align="right">Page generated in <strong>{elapsed_time}</strong> seconds</p>
</body>
</html>
and this is the second controller users
<?php
class Users extends CI_Controller
{
function login()
{
$data['error']=0;
if($_POST){
$this->load->model('user');
$username=$this->input->post('username',ture);
$password=$this->input->post('password',true);
$user=$this->user->login($username,$password);
if(!$user){
$data['error']=1;
}else{
$this->session->set_userdata('userID',$user['userID']);
redirect(base_url().'home');
}
}
$this->load->view('login');
}
function logout()
{
$this->session->sess_destory();
redirect(base_url().'home');
}
}
and this is the model user
<?php
class User extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
}
function login($username,$password)
{
$where=array(
'username'=>$username,
'password'=>sha1($password)
);
$this->db->select()->from('s_users')->where($where);
$querh=$this->db->get();
return $querh->first_row('array');
}
}
and this is the login view
<html>
<head>
<title>CTS - Login</title>
<style type="text/css">
.auto-style1 {
text-align: center;
}
</style>
</head>
<body bgcolor="#C0C0C0" style="height: 98px">
<div class="auto-style1" style="height: 118px">
<img alt="" height="126" src="YUC.png" style="float: left" width="147">
<center><h1 style="height: 113px; width: 696px">Cooperative Training Management System</h1></center>
</div>
<br>
<hr>
<div class="auto-style1">
<fieldset name="Group1">
<legend align="left"><h1>Login</h1></legend>
<?php if($error==1){ ?>
<p>Your Username / Password did not match.</p>
<? } ?>
<form action="<?=base_url()?>users/login" method="post" style="height: 96px">
<label>Username </label><input name="Text1" type="text">
<br>
<label>Password</label> <input name="Password1" type="password">
<br><br>
<input name="Login" style="width: 96px" type="submit" value="Login">
</form>
</fieldset>
</div>
<hr>
<p align="right">Page generated in <strong>{elapsed_time}</strong> seconds</p>
</body>
</html>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Maybe url is incorrect.
http://localhost/projectfolder/index.php/controller/method
in ur case:
http://localhost/yourprojectfolder/index.php/users/login
Replace "projectfolder", "controller", "method" with yours. Make sure your file name for Users Controller is "users.php"
use
base_url();
instead of
$this->config->item('base_url');
if you want to keep a config param use this :
$this->config->config['base_url'];
also this is not ok:
<?php echo site_url('') ?>users/login
use it like this:
<?php echo site_url('users/login') ?>
In the end check if you have views/home.php file
can't see anyother error in your code
then be sure you have:
$config['index_page'] = '';
and use this htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
If you Using WAMP server then open "httpd.conf" file, search "LoadModule rewrite_module modules/mod_rewrite.so" and remove # which in the start of the same line..
and restart your WAMP Server
Then add this code to your .htaccess file which is in the codeigniter folder (if not create it in the folder's root):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
check for URL which call functions
for e.g
Correct URL
http://127.0.0.1/mysites/site1_ci_bootstrap/index.php/welcome/home
May be your URL is
http://127.0.0.1/mysites/site1_ci_bootstrap/welcome/home
NOTE : Initially always need to mention "index.php" into the path which redirect to main class "welcome", To remove "index.php" put .htaccess script into root folder, google several htaccess script you find one.
Related
I am using revolution slider in my Laravel website.When i removed the "/public" from the url using a .htaccess file in my root folder with this code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
The slider is not loading correctly anymore(no slider shown)
This is the html code:
<div class="topslider" style="margin-top: 80px;">
<div id="slider">
<div class="fullwidthbanner-container">
<div id="revolution-slider">
<ul>
#foreach($sliders as $slider)
#if($slider->type == 'video' && $slider->video && File::exists($slider->video))
<li {{-- data-transition="fade" data-slotamount="7" data-masterspeed="5000" --}}>
<video poster="" id="bgvid" playsinline="" autoplay="" muted="" loop="">
<source src="{{ asset($slider->video)}}" alt="" type="video/mp4">
</video>
{{-- <video src="{{ asset($slider->video)}}" type="video/mp4" playsinline autoplay muted loop> </video> --}}
</li>
#endif
#endforeach
</ul>
</div>
</div>
<div class="tp-bullets">
<div class="simplebullets round bullet">
</div>
</div>
</div>
</div>
And finally this my website url
I get this error in my console:"Uncaught TypeError: Cannot read property 'nextElementSibling' of null"
The standard .htaccess which comes with Laravel 5.4 is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Try to replace your .htaccess file in public/.htaccess with this contents.
Content copied from https://github.com/laravel/laravel/blob/5.4/public/.htaccess
my view is :-
<li class="">
<a class="" href="<?php echo base_url(); ?>Login">
<i class="fa fa-unlock-alt"></i> Login </a>
</li>
my Login Controler
class Login extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function index()
{
$this->load->view('login');
}
}
When i clicked on link it says 404 page not found.
but when edit the link manually and write /index.php/Login it is working fine. how to fix this...
You have to use 3 more steps:
create a .htaccess file on project root(on your project folder "/project" or domain root directory)
Insert following line of codes on .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Find config/congig.php file and change this line to-
*add base url in my case:
$config['base_url'] = 'http://localhost/cirest.dev/'; ( assign your project path/URL)
$config['index_page'] = 'index.php'; to $config['index_page'] = '';
ADD this HTML to your view:
<li>
<a href="<?php echo base_url('login'); ?>">
<i class="fa fa-unlock-alt"></i> Login </a>
</li>
I think it will work. :)
Try site_url() in place of base_url()
<a class="" href="<?php echo site_url(); ?>Login">
First of all you should properly define url in config/routes.php:
$route['login'] = 'login/index';
And then you can use this route in a template with site_url() function:
<li>
<a href="<?php echo site_url('login'); ?>">
<i class="fa fa-unlock-alt"></i> Login </a>
</li>
I changed from $route['login'] = ['login/index']; to $route['login'] = 'login/index'; in my case.
Create a file in the webroot and name it .htaccess then type this code in it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
And in your application/config/config.php file, find this
$config ['index_page'] = '';
I am submitting form using form helpers and it's going to blank page and when I see the view source, the action in the view source is like this http://::1/ci1/login_validation I don't understand the ::1 in it shouldn't it be localhost:8080/? But if I use simple form tags like regular html it works fine?
<?php
echo form_open ('login_validation');
echo form_input('email');
echo form_password('password');
echo form_submit('login_submit', 'login');
echo form_close();
?>
View Source
<form action="http://::1/ci1/login_validation" method="post" accept-charset="utf-8">
<p>Email:<input type="text" name="email" value="" /></p>
<p>Password:<input type="password" name="password" value="" /></p>
<p><input type="submit" name="login_submit" value="login" /></p>
</form>
I would think it is a couple of thing like.
If your form action has http://::1/ then does not submit correct because base url is empty
$config['base_url'] = '';
Fill base url example:
$config['base_url'] = 'http://localhost/project_name/';
On codeigniter 3 version not best idea to leave it blank because you will run in to that issue.
Make sure your class and file names of controllers etc have first letter upper case.
Filename: Login_validation.php
Controller:
<?php
class Login_validation extends CI_Controller {
public function index() {
// form submit controller code.
}
}
View
<?php
echo form_open ('login_validation');
echo form_input('email');
echo form_password('password');
echo form_submit('login_submit', 'login');
echo form_close();
?>
This is a common mistake people for get to check.
Why http://::1/??
This mean your base_url() is empty.
Then how this http://::1/ comes??
When your project URL is empty, CI detect your project URL. So this http://::1/ knows your project path.
How to set base_url()??
In config/config.php set $config['base_url'] = ''; the project URL.
Keeping base_url() empty any harm??
When you in local its ok and fine. But when you host that just add your site URL to it.
$config['base_url'] = 'www.stackoverflow.com';
I'm having some issues using sessions on my test website (Running it on WAMP server locally, using PHP php5.3.13) I have checked my php.ini to make sure that sessions are actually being saved, which they are:
C:\wamp\tmp
Basically, when the user logs in it shows, Welcome back, .$username so when I log in with the user "John", it shows this accordingly. Now, when I leave the login page and go back to it this sessions is somehow being lost. (And yes, I am using session_start at the top of every page).
Here is my code;
index.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Codecall Tutorials - Secured Login with php5</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php include "header.php" ?>
<div id="wrapper">
<form method="post" action="">
<h2>Log In</h2>
<div id="underline"></div>
<ul>
<li>
<label for="usn">Username : </label>
<input type="text" maxlength="30" required autofocus name="username" />
</li>
<li>
<label for="passwd">Password : </label>
<input type="password" maxlength="30" required name="password" />
</li>
<li class="buttons">
<input type="submit" name="login" value="Log me in" class="xbutton" />
<input type="button" name="register" value="Forgot Password?" onclick="location.href='passrecover.php'" class="xbutton" />
</li>
</ul>
</form>
</div>
</body>
</html>
<?php include "login.php" ?>
And my login.php page:
<?php
if($_POST){
if(empty($_POST['username']) && empty($_POST['password'])) {
echo 'Please enter all fields';
}else {
$username = $_POST['username'];
$password = $_POST['password'];
if($password !== $password){
echo 'Your password is wrong';
}else {
$db_name =
$db_user =
$db_pass =
$conn = new PDO('mysql:host=localhost;dbname=XXXXX', 'XXXXX', 'XXXXX', // My bd details have been removed for this post, for security issues obviously
array( PDO::ATTR_PERSISTENT => true )
);
$stmt = $conn->prepare("SELECT username,password from members WHERE username = ? AND password = ?");
$stmt = $conn->prepare("SELECT username,password FROM users WHERE username = ? AND password = ?");
$stmt->execute(array($username, $password));
if($stmt->rowCount() === 1 )
{
$_SESSION['name']= $username;
echo 'Welcome back '. $_SESSION['name'];
//echo '<META HTTP-EQUIV="Refresh" Content="0; URL=usercp.php">';
}else {
echo 'Username or Password incorrect.';
}
}
}
}
?>
So, when I originally log in it shows the $_SESSION['name'];
just fine, but when I move page and go back to it, it no longer shows it. (My other pages also have session_start(); ) My original assumption was that my code was wrong, or that my php.ini file wasn't saving any data. What is going wrong here?
You need to add session_start() on your login.php too
The reason it no longer shows is because when you go to another page, you aren't processing that block of code anymore. Because $_POST is empty on a regular page load, so you aren't echoing anything out. Try adding, var_dump($_SESSION); at the top of your page and then load something.
Try this right after your session_start();,
if(!empty($_SESSION['name'])) {
echo "Hello {$_SESSION['name']}";
}
Perhaps you're destroying the session somewhere in the script.
I have a problem with Codeigniter URL. I have a controller "welcome.php" :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$data['tiung'] = 'index';
$this->load->view('welcome_message',$data);
}
public function dor($bus)
{
$data['tiung'] = $bus;
$this->load->view('welcome_message',$data);
}
}
and a view "welcome_message.php" :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
</head>
<body>
sesuatu <?php echo $tiung?>
<img src="fragor.jpg" width="720" height="246" alt=""/>
ladalah
</body>
</html>
If I want to access the controller function 'dor' with a parameter I used this :
localhost/hostname/index.php/welcome/dor/something
and it works, but the problem is the image isn't loaded. I tried to put the image file in the webroot folder, 'application' folder, and even in the 'views' folder. But the image still can't load. Where should I put the image file?
The best practice for this is to create an /images/ directory in your webroot (the folder with index.php) and use the base_url() function to get the link to the image, I.E.
<img src="<?php echo base_url('images/fragor.jpg'); ?>" width="720" height="246" alt=""/>
Don't forget to load the url helper either with the autoloader or manually before using site_url() or base_url().
Also if you're using CodeIgniter's rewrite rules to remove the index.php from the URL (which it doesn't look like you're doing), don't forget to exclude the /images/ directory from the rewrite.
In CodeIgniter there is a specific way to indicate an image...like
echo img('images/gautam.gif');
put this in your view file and you need to create "images" folder at your root
Though you have to add CI helper 'html' in autoload config, but this goes easy after.
<?php
$image_properties = array(
'src' => 'images/picture.jpg',
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
'class' => 'post_images',
'width' => '200',
'height'=> '200',
'title' => 'That was quite a night',
'rel' => 'lightbox'
);
img($image_properties);
?>
/* <img src="site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a nigh`enter code here`t" rel="lightbox" />*/
OR JUST simple:
<?php
echo img('images/picture.jpg'); ?>
// gives <img src="site.com/images/picture.jpg" />