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.
Related
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>
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
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]
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);
i am trying to use different style-sheet files in different divs at the same time. I have tried by using switch cases, but nothing helps, Please one thing to be notable that i have to show both of the divs at the same time
here is my code which i have tried so far:
<?php
switch ($type_show1):
case 'welcome1':
//default:
?>
<link href="css/main.css" rel="stylesheet" type="text/css" /> // css to include
<div class="page-header">
<div class="page-title">
<h5>Booking Management</h5>
<span>Good morning, Admin!</span>
</div>
</div>
<!-- /page header -->
<?php
break;
endswitch;
?>
<?php
switch ($type_show2):
case 'welcome2':
//default:
?>
<link href="css/main2.css" rel="stylesheet" type="text/css" /> // Other css to include
<div class="page-header">
<div class="page-title">
<h5>Booking Management</h5>
<span>Good morning, Admin!</span>
</div>
</div>
<?php
break;
endswitch;
?>
What's the difference in those stylesheets?
Guess you want something like this?
This way the divs are always shown and the stylesheets are only imported on your switch.
<?php
switch ($type_show1):
case 'welcome1':
//default:
?>
<link href="css/main.css" rel="stylesheet" type="text/css" /> // css to include
<?php
break;
endswitch;
?>
<?php
switch ($type_show2):
case 'welcome2':
//default:
?>
<link href="css/main2.css" rel="stylesheet" type="text/css" /> // Other css to include
<?php
break;
endswitch;
?>
<div class="page-header">
<div class="page-title">
<h5>Booking Management</h5>
<span>Good morning, Admin!</span>
</div>
</div>
<!-- /page header -->
<div class="page-header">
<div class="page-title">
<h5>Booking Management</h5>
<span>Good morning, Admin!</span>
</div>
</div>
Why aren't you declaring your 2 stylesheets on the head of your html, and giving two different IDs to your divs ?