htaccess (not the index.php) - php

i am struggling with the .htaccess file. I have got an intro page as the index.php and there is a link. If you click the link, i want that you will get to the home.php. The home.php should be my real(pseudo) main index.php
Here is a pic of my folder structur:
On that picture you can see my .htaccess file and the folder structur. I am not sure, if the rules are correct.
Thats my index.php:
<body onload="main()">
<!-- Main content -->
<div id="main">
<!-- Logo -->
<div id="logo">
</div><!-- End Logo -->
<!-- h2 Webdesign & Development -->
<h1 id="text"></h1>
<!-- End h2 Webdesign & Development -->
<!-- Enter link -->
<div id="enter">
ENTER
</div><!-- End enter link -->
</div><!-- End main content -->
There is a "ENTER" Link to the real website(home.php)
Here is my navi.inc.php file:
<nav>
<ul>
<li><img data-other-src="../pics/home_button_hover.svg" src="../pics/home_button.svg" id="home" alt="Home Button"></li>
<li>Info</li>
<li>Projects</li>
<li>Contact</li>
</ul>
and finally my home.php:
<?php
require_once '../include/config.inc.php';
if( isset( $_GET['site'] ) ){
$site = $_GET['site'];
}else{
$site = 'Home';
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Home | <?=$seiten_name?></title>
<link rel="stylesheet" type="text/css" href="../style/main.css">
<link href='http://fonts.googleapis.com/css?family=Iceland' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../js/image_switch.js"></script>
</head>
<body>
<div id="main">
<?php
// Navigation
switch ( $site ) {
case 'Home':
include('home.php');
break;
case 'Projects':
include('projects.php');
break;
case 'Contact':
include('contact.php');
break;
default:
include('home.php');
break;
}
?>
<div id="preloader">
<img src="../pics/ajax-loader.gif" alt="Preloader">
</div>
</div>
<?php
require('../include/navi.inc.php');
?>
</body>
</html>
Sorry for my poor english, but i hope you will understand my problem!! I want the home.php as my index :P

Please try below rule in your htaccess
DirectoryIndex home.php

This is working:
RewriteEngine On
RewriteBase /website/sites/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ home.php?site=$1 [L,QSA]

Related

Include between navbar and vertical menu

I am currently creating my first website and i have some trouble, i want to include a page between a navbar and a vertical bar, and i want to change to page to include when a click on a button of my vertical bar. Here is a screen :
Screen of my Website
And here is my code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Memeable | The 1# world meme generator</title>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<link href="css/bootstrap-social.css" rel="stylesheet">
</head>
<body>
<div >
<?php
include("head.php");
?>
</div>
</body>
Here is my head.php :
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Memeable</a>
</div>
</div>
</nav>
<div class="vertical-menu">
Premier
Deuxième
Troisième
Quatrième
</div>
I'm sure that the solution is easy but i don't see how to do.
Thank you for your help !
To show your content in your "content area" use include. You provide the file name you want to load as an argument. Use an array to specify all the valid files you want to use, then use a $_GET parameter to select the correct sub page to load.
<?php
$files = array();
$files['home'] = 'home.php';
$files['contact'] = 'contact.php';
$files['whatever'] = 'you_want.php';
?>
Then later at the location where you want the content to be displayed use the following code:
<?php
if (isset($_GET['nav'], $files[$_GET['nav']])) {
include $files[$_GET['nav']];
} else {
include $files['home']; // default page
}
?>
To "call" the right sub page add the ?nav=... query parameter to your URLs like
<ul>
<li>Home</li>
<li>Contact</li>
</ul>

Redirecting HomePage

Iam Learning PHP, so i have started an website..in that i have created index.php and index_1.php and login.php in which when user successful login the user has to be redirect to index.php but iam not getting it so i have created an another index_1.php in this page only three navigation bars will be there Home,projects and contactus.
This is my index.php Page
<!DOCTYPE HTML>
<html>
<head>
<title>Karthik</title>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link href="style/style.css" rel="stylesheet" type="text/css">
<style>
.mySlides {display:none;}
</style>
</head>
<body>
<div id="main">
<div id="header">
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1>KarthikAenugula</h1>
</div>
</div>
<div id="menubar">
<ul id="menu">
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li class="selected">Home</li>
<li>Projects</li>
<li>AboutMe</li>
<li>Login</li>
<li>Register</li>
<li>Contact</li>
</ul>
</div>
</div>
This is my index_1.php
<?
session_start();
if(!isset($_SESSION['user_email']))
{
echo '<p>Please Login to continue Log In</p>';
exit();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Karthik</title>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link href="style/style.css" rel="stylesheet" type="text/css">
<style>
.mySlides {display:none;}
</style>
</head>
<body>
<div id="main">
<div id="header">
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1>KarthikAenugula</h1>
</div>
</div>
<div id="menubar">
<ul id="menu">
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li class="selected">Home</li>
<li>Projects</li>
<li>AboutMe</li>
<li>Contact</li>
<?php
echo '<p align="right">';
session_start();
echo "Welcome";
echo '<br>';
echo ($_SESSION ['user_email']);
echo '<br> Logout?ClickHere</p>';
?>
This is my login.php
<?php
ob_start();
session_start();
if(isset($_POST["Submit"]))
{
$user_email=$_POST['user_email'];
$user_password=md5($_POST['user_password']);
$con=#mysql_connect('localhost','xxxxx','xxxx') or die(mysql_error());
mysql_select_db('suryapra_aenugula_karthik');
$query=mysql_query("SELECT * FROM user_registration where user_email='".$user_email."' AND user_password='".$user_password."'") or die("error in selection");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbusername=$row['user_email'];
$dbpassword=$row['user_password'];
}
if($user_email==$dbusername && $user_password==$dbpassword)
{
if(isset($_POST['remember']))
{
setcookie('user_email',$user_email,time()+60*60*7);
setcookie('user_password',$user_email,time()+60*60*7);
}
session_start();
$_SESSION['user_email']=$user_email;
header("Location: index_1.php");
ob_end_flush();
}
}
else
{
header("Location: login_2.php");
ob_end_flush();
}
}
else
{
header("Location: login.php");
}
?>
what my problem is if user logins he is redirecting to index.php and again login and register links are also getting in index.php
i want solution in which when user logins he should be redirect to index.php and login,register tabs should not be visible to him unless he presses logout button
The basic flow of User Authentication:
User submits login form to login.php this, if login is correct, will set a $_SESSION variable to signal user is logged in.
User is then redirected back to site, where
In the templates, anything that is optional for loggedin/logged out users are wrapped in IF blocks
Something like so:
<?php
$logged_in = $_SESSION['logged_in'];
?>
<nav>
<?php if (!$logged_in):?>
Login
<?php endif;?>
<?php if ($logged_in):?>
Logout
<?php endif;?>
</nav>
First of all after a successful login on the login page redirect user on the index.php page.
you dont need index_2.php page.
After that edit your index page with following code where first we will check if [user_email] session is been created or not when we logged in if it is created we are not echoing anything if not then we will echo the login and register link. bellow is your new index.php page
<?php session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Karthik</title>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link href="style/style.css" rel="stylesheet" type="text/css">
<style>
.mySlides {display:none;}
</style>
</head>
<body>
<div id="main">
<div id="header">
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1>KarthikAenugula</h1>
</div>
</div>
<div id="menubar">
<ul id="menu">
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li class="selected">Home</li>
<li>Projects</li>
<li>AboutMe</li>
<?php if(isset($_SESSION[user_email]))
{
}
else
{
echo "<li><a href='login.php'>Login</a></li>";
echo "<li><a href='register.php'>Register</a></li>";
}
?>
<li>Contact</li>
</ul>
</div>
</div>

Two dynamic parts (template)

I don't know, how to descripe my problem, but I going to try.
I have build my own Template and with one part it is working, but I want to have two parts that are changing, if I click a link.
It is working on my index.php and if I click on the other links, but if I click on news to go back to news(it is my home (index.php)) I will get to a directory explorer.
a example:
my folder structure:
my htaccess:
RewriteEngine On
RewriteBase /inexorablez/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?site=$1 [L,QSA]
my navigation file:
<nav>
<ul>
<li>News</li>
<li>Teams</li>
<li>Downloads</li>
<li>Partner</li>
</ul>
</nav>
my index.php:
if( isset( $_GET['site'] ) ) {
$site = $_GET['site'];
} else {
$site = 'News';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>inexoarablez</title>
<link rel="stylesheet" href="unslider/dist/css/unslider.css">
<link rel="stylesheet" href="unslider/dist/css/unslider-dots.css">
<link rel="stylesheet" href="font-awesome-4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<!-- wrapper start -->
<div id="wrapper">
<div id="header">
<div id="col-left">
<!-- logo section start -->
<div id="logo-section">
<div id="logo"></div>
<h1>inexorablez</h1>
</div>
<!-- logo section end -->
</div>
<div id="col-right">
<!-- navigation start -->
<?php require( "includes/navigation.inc.php" ); ?>
<!-- navigation end -->
<!-- news start -->
<div id="news">
<?php
// Navigation
switch ( $site ) {
case 'News':
include( 'news/news.news.php' );
break;
case 'Teams':
include( 'news/teams.news.php' );
break;
case 'Downloads':
include( 'news/downloads.news.php' );
break;
case 'Partner':
include( 'news/partner.news.php' );
break;
default:
include( 'news/news.news.php' );
break;
}
?>
</div>
<!-- news end -->
</div>
</div>
<div id="main">
<div id="content">
<?php
// Navigation
switch ( $site ) {
case 'News':
include( 'sites/news.php' );
break;
case 'Teams':
include( 'sites/teams.php' );
break;
case 'Downloads':
include( 'sites/downloads.php' );
break;
case 'Partner':
include( 'sites/partner.php' );
break;
default:
include( 'sites/news.php' );
break;
}
?>
</div>
</div>
<!-- footer start -->
<footer>
fsdgdsfgfdsg
</footer>
<!-- footer end -->
</div>
<!-- wrapper end -->
<!-- scripts -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="unslider/src/js/unslider.js"></script> <!-- but with the right path! -->
<script>
jQuery(document).ready(function($) {
$('.my-slider').unslider({
autoplay: true
});
});
</script>
here a jsfiddle:
jsfiddle
Sorry for my english, I guess something is wrong, but I don't know really what...
If I go back to new, I will get this:
It is working on my index.php and all other links, but not on the "News" link, if I hit the "News" link I will get the folder structure.
If you want to disable directory listings, add this line to your .htaccess file(s)
Options -Indexes
You can have an .htaccess file in each directory
inexorablez/unslider/.htaccess
indexorablez/News/.htaccess
and/or at the root
indexorablez/.htaccess

navigation include loop(php switch)

I am somewhere in a loop! My browser is including over and over again my navigation until the page crashes. I dont know why. I do the switch normally in the index.php, but I want to have an intro page and therfore I want to do it in the home.php.
Here is a pic of my folder structur:
Thats my index.php:
<body onload="main()">
<!-- Main content -->
<div id="main">
<!-- Logo -->
<div id="logo">
</div><!-- End Logo -->
<!-- h2 Webdesign & Development -->
<h1 id="text"></h1>
<!-- End h2 Webdesign & Development -->
<!-- Enter link -->
<div id="enter">
ENTER
</div><!-- End enter link -->
</div><!-- End main content -->
There is a "ENTER" Link to the real website(home.php)
Here is my navi.inc.php file:
<nav>
<ul>
<li><img data-other-src="../pics/home_button_hover.svg" src="../pics/home_button.svg" id="home" alt="Home Button"></li>
<li>Info</li>
<li>Projects</li>
<li>Contact</li>
</ul>
and finally my home.php:
<?php
require_once '../include/config.inc.php';
if( isset( $_GET['site'] ) ){
$site = $_GET['site'];
}else{
$site = 'Home';
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Home | <?=$seiten_name?></title>
<link rel="stylesheet" type="text/css" href="../style/main.css">
<link href='http://fonts.googleapis.com/css?family=Iceland' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../js/image_switch.js"></script>
</head>
<body>
<div id="main">
<?php
// Navigation
switch ( $site ) {
case 'Home':
include('home.php');
break;
case 'Projects':
include('projects.php');
break;
case 'Contact':
include('contact.php');
break;
default:
include('home.php');
break;
}
?>
<div id="preloader">
<img src="../pics/ajax-loader.gif" alt="Preloader">
</div>
</div>
<?php
require('../include/navi.inc.php');
?>
</body>
</html>
Sorry for my poor english, but i hope you will understand my problem!! I want the home.php as my index :P
In your home.php file you have the following code:
switch ( $site ) {
case 'Home':
include('home.php');
break;
(Same goes for your default: block)
Which basically means that there's a situation where the home.php file will include itself, which will cause an infinity loop.

Php after redirect the button doesn't work

I have two PHP pages:
giardino.php:
<?php
SESSION_START();
if (isset($_SESSION['utente'])){
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="immagini/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="css/stile.css"/>
</head>
<body>
<div data-role="page" data-theme="d">
<div data-role="header">
Ambienti
<a href="logout.php" data-role="button" data-theme="b" data-icon="delete" >Logout</a>
<h1>Domos - Giardino</h1>
</div><!-- /header -->
<div data-role="content" id="centramento">
<?php
include("configurazione.php");
$id_stanza=1;
$pin=26;
//lettura stato attuale
$comando="select luci from casa where ID_stanza=1";
$query=mysql_query($comando,$connessione);
while($riga=mysql_fetch_array($query)){
$oldstate=$riga['luci'];
}
if($oldstate == 0){
$newstate='accendi luce';
$theme='e';
}
else{
$newstate='spegni luce';
$theme='a';
}
echo "<a href='luce.php' data-role='button' data-theme='$theme' id='radio'>$newstate</a>"
?>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
<h4>Credits: Silvio Mattiello 5C Informatica 2014/2015</h4>
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>
<?php
}
else{
header("location:home.php?msg=6");
}
?>
luce.php:
<?php
$id_stanza=1;
$pin=$_GET=26;
$comando = escapeshellcmd("sudo /var/www/domotica/python/luce.py $pin $id_stanza");
$esito = exec($comando);
if ($esito == "allarme attivato"){
header("location:ambienti.php");
exit();
}
else {
header("location:giardino.php");
exit();
}
?>
When I click the button on the first page, I get redirected to the second page.
In the second page, there are some operations and then I get redirected to the first page (or another page, ambienti.php).
But when I am redirected to the first page again, the button on this page (giardino.php) doesn't work. I can't click it. Why?
try to use a require instead of the include, to see if there is any error... It seems to be something with include.
Also, you could try to add 302 http to the header like this and add the full path
header('Location: http://server_name/ambienti.php', true, 302);

Categories