I am trying to display the code of a php file as plain html. This is all going well except for that fact that I would like it to 'open up' the <?php require 'Main_content_bar.php'; ?> statements aswell.
So far I have show_source($page); correctly working.
It currently prints:
<?php require 'Main_content_bar.php'; ?>
<!-- Jumbotron -->
<div class="jumbotron">
<h1>Property</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet.</p>
</div>
<div class="row">
<div class="col-md-12">
<h2>Current properties</h2>
</div>
</div>
<div class="footer">
<p><a href="Source_code.php" target="_blank"> <img src="Images/codebutton<?php echo $page_lower;?>.jpg" alt="<?php echo $page;?> Source"> </img>
</a></p>
<p>© Robin B'stards Retail 2014</p>
</div>
</body>
</html>
However, as one can see, the contents of the require statements do not show. I cannot for the life of me work out how to do this.
So what it would end up looking like is something like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.2/css/bootstrapValidator.min.css"/>-->
<!-- <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.2/js/bootstrapValidator.min.js"></script>-->
<link href="justified-nav.css" rel="stylesheet">
<script>
$(function(){
var url = window.location.href;
var page = url.substr(url.lastIndexOf('/')+1);
$('.nav a[href*="'+page+'"]').parent().addClass('active');
});
</script>
</head>
<body>
<div class="container" style="width: 1263px">
<div class="masthead">
<h3 class="text-muted">Ruthless Real Estate</h3>
<ul class="nav nav-justified">
<li class="menu">Property</li>
<li class="menu">Client</li>
<li class="menu">Type</li>
<li class="menu">Feature</li>
<li class="menu">Multiple Properties</li>
<li class="menu">Property Features</li>
<li class="menu">Images</li>
</ul>
</div>
<!-- Jumbotron -->
<div class="jumbotron">
<h1>Property</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet.</p>
</div>
<div class="row">
<div class="col-md-12">
<h2>Current properties</h2>
</div>
</div>
<div class="footer">
<p><a href="Source_code.php" target="_blank"> <img src="Images/codebutton<?php echo $page_lower;?>.jpg" alt="<?php echo $page;?> Source"> </img>
</a></p>
<p>© Robin B'stards Retail 2014</p>
</div>
</body>
</html>
Note the lack of require statements
You cannot do that with show_source, which just "show some code sources" of a file.
You need to create your own function which take a filename in argument, then you have to analyze the source like this:
replace all require/include/require_once/include_once (what do I forget?) by their own content
make the function recursive (because Main_content_bar.php can have other include inside it)
Use highlight_string at the end of your function.
EDIT to search & replace, one way (there is several) is to use preg_match_all. That part of the code would look like this :
$new_content = file_get_contents('your-file.php');
$base_path = __DIR__.'/';
// pattern to find require, require_once, include, include_once functions
// and catch their arguments
$pattern = "#<\?php (?:require|include(?:_once)?)\s*'(.*)'; \?>#u";
if (preg_match_all($pattern, $new_content, $matches))
{
foreach($matches[0] as $pattern_index => $full_pattern)
{
$file = $matches[1][$pattern_index];
$subcontent = file_get_contents($base_path.$matches[$pattern_index]);
$new_content = str_replace($new_content, $full_pattern, $subcontent);
}
}
highlight_string($new_content);
Related
im working on my crud skills, but im having some trouble. the first page shows a list of all blog posts, when the user clicks on read more it sends the specific posts id through the url and is recieved by the destination page which uses that id to display the single post/ heres the code for that part. it actually works fine
function display_single_post($title,$author,$date,$image,$content){
$main_page_blog_html = "<h2>
<a href='#'>%s</a>
</h2>
<p class='lead'>
by <a href='index.php'>%s</a>
</p>
<p><span class='glyphicon glyphicon-time'></span> Posted on %s</p>
<hr>
<img class='img-responsive' src='images/%s'>
<hr>
<p>%s</p>
<hr>
<hr>";
printf("{$main_page_blog_html}",$title,$author,$date,$image,$content);
if(isset($_GET["id"])){
$id = $_GET["id"];
$stmt = $connect->link->query("SELECT * FROM posts WHERE post_id = $id");
while($row = $stmt->fetch()){
$post_title = $row["post_title"];
$post_author = $row["post_author"];
$post_date = date('F j, Y \a\t g:ia', strtotime( $row["post_date"] ));
$post_image = $row["post_image"];
$post_content = $row["post_content"];
$id = $row["post_id"];
display_single_post($post_title,$post_author,$post_date,$post_image,$post_content);
}
}
like i said this all works fine. the get value is recieved and loads the post. the problem is when i try to use that $_get id in a query to insert a comment. all this code is on the one page im just showing the php without the html. anyway heres the code to insert the comment
if(isset($_POST["create_comment"])){
global $connect;
$post_id = $_GET["id"];
$comment_author = $_POST["comment_author"];
$author_email = $_POST["author_email"];
$comment_content = $_POST["comment_content"];
$comment_status = "pending";
edit with all the code
<div class="container">
<div class="row">
<!-- Blog Entries Column -->
<div class="col-md-8">
<h1 class="page-header">
Page Heading
<small>Secondary Text</small>
</h1>
<!-- First Blog Post -->
<?php
$connect = new db();
if(isset($_POST["create_comment"])){
global $connect;
echo "hello";
$post_id = $_GET["id"];
$comment_author = $_POST["comment_author"];
$author_email = $_POST["author_email"];
$comment_content = $_POST["comment_content"];
$comment_status = "pending";
$sql = "INSERT INTO comments(comment_post_id, comment_author, comment_email, comment_content, comment_status)
VALUES(:a,:b,:c,:d,:e)";
$stmt = $connect->link->prepare($sql);
$stmt->bindvalue(":a",$post_id);
$stmt->bindvalue(":b", $comment_author);
$stmt->bindvalue(":c",$author_email);
$stmt->bindvalue(":d",$comment_content);
$stmt->bindvalue(":e",$comment_status);
$stmt->execute();
}
function display_single_post($title,$author,$date,$image,$content){
$main_page_blog_html = "<h2>
<a href='#'>%s</a>
</h2>
<p class='lead'>
by <a href='index.php'>%s</a>
</p>
<p><span class='glyphicon glyphicon-time'></span> Posted on %s</p>
<hr>
<img class='img-responsive' src='images/%s'>
<hr>
<p>%s</p>
<hr>
<hr>";
printf("{$main_page_blog_html}",$title,$author,$date,$image,$content);
}
if(isset($_GET["id"])){
$id = $_GET["id"];
$stmt = $connect->link->query("SELECT * FROM posts WHERE post_id = $id");
while($row = $stmt->fetch()){
$post_title = $row["post_title"];
$post_author = $row["post_author"];
$post_date = date('F j, Y \a\t g:ia', strtotime( $row["post_date"] ));
$post_image = $row["post_image"];
$post_content = $row["post_content"];
$id = $row["post_id"];
display_single_post($post_title,$post_author,$post_date,$post_image,$post_content);
}
}
?>
<hr>
<!-- Blog Comments -->
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" method="post" action="post.php">
<div class="form-group">
<input type="text" class="form-control" name="comment_author" placeholder="name">
</div>
<div class="form-group">
<input type="email" class="form-control" name="author_email" placeholder="email">
</div>
<div class="form-group">
<textarea class="form-control" rows="3" name="comment_content"></textarea>
</div>
<button type="submit" name="create_comment" class="btn btn-primary">Submit</button>
</form>
</div>
<hr>
<!-- Posted Comments -->
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Start Bootstrap
<small>August 25, 2014 at 9:30 PM</small>
</h4>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
</div>
</div>
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Start Bootstrap
<small>August 25, 2014 at 9:30 PM</small>
</h4>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
<!-- Nested Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Nested Start Bootstrap
<small>August 25, 2014 at 9:30 PM</small>
</h4>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
</div>
</div>
<!-- End Nested Comment -->
</div>
</div>
</div>
Based on your code and your comments, I assume the page is called post.php and when you first reach the page it has the id on the url like this: post.php?id=156.
But once you submit the comments' form, since the action for said form it is simply post.php you're losing the id.
You could add the id on the action after post:
<form role="form" method="post" action="post.php?id=<?php echo $id; ?>">
or add a hidden input with the id:
<input type="hidden" name="id" value="<?php echo $id; ?>">
But then you'd have to reach it with $_POST
Another option is to use the SELF for the action like this:
<form role="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
This will retain the id but also any other get variables you may have on the url.
//EDIT
This is a simplification of the probelm which is working, if you visit post.php?id=456 (or any number) and then press Submit, you get the proper response:
<!-- First Blog Post -->
<?php
if(isset($_POST["create_comment"])){
$post_id = $_GET["id"];
echo "The id is: $post_id";
// gets comment and inserts into the db
}
if(isset($_GET["id"])){
$id = $_GET["id"];
// calls display_single_post
}
?>
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" method="post" action="post.php?id=<?php echo $id; ?>">
<button type="submit" name="create_comment" class="btn btn-primary">Submit</button>
</form>
</div>
I am trying to redirect the page using header("location: profile.php") after I click a submit button in the login form, but the page won't redirect. The username and password just gets submitted somewhere.
Here is my main page:
<?php
include ($_SERVER["DOCUMENT_ROOT"]."/example/login.php");
if(isset($_SESSION['login_user'])){
header("location: profile.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>welcome to noteshare</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-theme.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/jquery_popup.css" />
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/npm.js"></script>
<script src="js/jquery_popup.js"></script>
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/jquery.leanModal.min.js"></script>
<style>
/* Remove the navbar's default margin-bottom and rounded borders */
.navbar {
margin-bottom: 0;
border-radius: 0;
}
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {height: 450px}
/* Set gray background color and 100% height */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
height: 100%;
}
/* Set black background color, white text and some padding */
footer {
background-color: #555;
color: white;
padding: 15px;
}
/* On small screens, set height to 'auto' for sidenav and grid */
#media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}
}</style>
</head>
<!-- Body Starts Here -->
<body id="body">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-in"></span>Login</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid text-center">
<div class="row content">
<div class="col-sm-2 sidenav">
<p>Link</p>
<p>Link</p>
<p>Link</p>
</div>
<div class="col-sm-8 text-left">
<h1>noteshare</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididuntut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Excepteur sint occaecat cupidatat non proident,sunt in culpa qui
officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<hr>
<img src="images/girl_studying.jpg">
</div>
<div class="col-sm-2 sidenav">
<div class="well">
<p>ADS</p>
</div>
<div class="well">
<p>ADS</p>
</div>
</div>
</div>
</div>
<footer class="container-fluid text-center">
<p>Footer Text</p>
</footer>
<div id="abc">
<!-- Popup Div Starts Here -->
<div id="popuplogin">
<!-- Contact Us Form -->
<form action="" id="form" method="post" name="form">
<img id="close" src="images/cross.png" onclick ="div_hide()">
<h2>login form</h2>
<hr id="line">
<input id="username" name="username" placeholder="username" type="text" required>
<input id="password" name="password" placeholder="password" type="password" required>
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
<p> click here to register first</p>
</form>
</div>
<!-- Popup Div Ends Here -->
</div>
<!-- Display Popup Button -->
</body>
<!-- Body Ends Here -->
</html>
and here is the login.php page that contains the header() function call:
<?php
session_start(); // Starting Session
$error=""; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$server="localhost";
$username="root";
$password="";
$database="noteshare";
$conn = new mysqli($server, $username, $password, $database);
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
//$username = mysql_real_escape_string($username);
//$password = mysql_real_escape_string($password);
// Selecting Database
//$db = mysqli_select_db("noteshare", $conn);
// SQL query to fetch information of registerd users and finds user match.
$qry="select * from signin where password='$password' AND username='$username'";
$query = mysqli_query($conn,$qry);
$rows = mysqli_fetch_row($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("Location:http://localhost.com/profile.php", true, 301); exit;// Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysqli_close($conn); // Closing Connection
}
}
?>
function mysqli_fetch_row returns an array or NULL. Therefore
if ($rows == 1)
is never true and you won't reach the redirect with header().
You can use i.e if (is_array($rows)) or if (isset($rows))
You can always insert a var_dump($rows) for debugging to see what the variable $rows looks like.
Note, HTTP code 301 is a permanent redirect. It should be 302. Or simply you can omit the second and third argument of the header() function and it will be a 302.
Did your connection with mysql is ok, then try this,
header('Location:filename');
Eg: header('Location:test1.php');
Try this
header("Location:profile.php"); die();
OR redirect with JS
echo '<script>window.location.href = "profile.php";</script>' ;
You are using an absolute URL. TLD .com is not used when working on a local server.
Change:
header("Location:http://localhost.com/profile.php");
To:
header("Location:http://localhost/profile.php");
It should work!
On my index page i have my login form for users, then it goes to login.php to handle the login script, from there the users are redirected to dashboardd.php. But i want it to to be so that they have to be logged in to access this page, and not just type in the URL.
Index.php
<?php
session_start();
?>
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul style="padding:0; color:red;">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="img/favicon.ico">
<title>Jumbotron Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Alec Grogan</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<form class="navbar-form navbar-right" role="form" action="login.php" method="POST">
<div class="form-group">
<input type="text" placeholder="Username" name="uname" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Password" name="pword" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
</form>
</div><!--/.navbar-collapse -->
</div>
</nav>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more »</a></p>
</div>
</div>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>
<div class="col-md-4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>
<div class="col-md-4">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>
</div>
<hr>
<footer>
<p>© Company 2014</p>
</footer>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
login.php
<?php
session_start();
$errmsg_arr = array();
$errflag = false;
// configuration
$dbhost = "localhost";
$dbname = "alecgrogan";
$dbuser = "root";
$dbpass = "";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$user = $_POST['uname'];
$password = $_POST['pword'];
if($user == '') {
$errmsg_arr[] = 'You must enter your Username';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'You must enter your Password';
$errflag = true;
}
// query
$result = $conn->prepare("SELECT * FROM users WHERE username= :hjhjhjh AND password= :asas");
$result->bindParam(':hjhjhjh', $user);
$result->bindParam(':asas', $password);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
if($rows > 0) {
header("location: dashboard.php");
}
else{
$errmsg_arr[] = 'Username and Password are not found';
$errflag = true;
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
?>
dashboard.php
<?php
echo "string";
?>
Make a $_SESSION e.g. $_SESSION['logged_in'] and fill it with data or set it to true
$username = $_POST['username']; //don't forget to sanitize $_POST values
$userID = (int)$_POST['userID'];
$_SESSION['logged_in'] = array('username' => $username, 'id' => $userID);
OR
$_SESSION['logged_in'] = TRUE;
And then check on the dashboard
if(!isset($_SESSION['logged_in'])){
header('Location:index.php');
}
Now if it does not exists, it will return the user to index.php. Don't forget to use session_start() at the top of every page where you want to call the $_SESSION variables.
You can set an array() in a $_SESSION, so this is ideal for storing user info. Do not store user passwords in a $_SESSION tho.
Hi Im developng an hotel search website where client can search for hotel... I have developed my backend where hotel can update the details into my database... now im stuck with my front end where client can see my database based upon there search criteria. In php i do know how to display data in in table but unable to get my head stright in html div... I want to understand would i can display database instent of table... What all the coding required to get such resulte... Please click on my below link and you would understand how i want to display in result
http://hotel.makemytrip.com/makemytrip/site/hotels/search?session_cId=1388679988524&city=BOM&country=IN&checkin=01042014&checkout=01062014&area=South%20Mumbai&roomStayQualifier=1e0e&type=&sortName=
<div class="offset-2">
<div class="col-md-4 offset-0">
<div class="listitem2">
<img src="images/items/item7.jpg" alt=""/>
<div class="liover"></div>
<a class="fav-icon" href="#"></a>
<a class="book-icon" href="details.html"></a>
</div>
</div>
<div class="col-md-8 offset-0">
<div class="itemlabel3">
<div class="labelright">
<img src="images/filter-rating-5.png" width="60" alt=""/><br/><br/><br/>
<img src="images/user-rating-5.png" width="60" alt=""/><br/>
<span class="size11 grey">18 Reviews</span><br/><br/>
<span class="green size18"><b>$36.00</b></span><br/>
<span class="size11 grey">avg/night</span><br/><br/><br/>
<form action="http://demo.titanicthemes.com/travel/details.html">
<button class="bookbtn mt1" type="submit">Book</button>
</form>
</div>
<div class="labelleft2">
<b>Mabely Grand Hotel</b><br/><br/><br/>
<p class="grey">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec semper lectus. Suspendisse placerat enim mauris, eget lobortis nisi egestas et.
Donec elementum metus et mi aliquam eleifend. Suspendisse volutpat egestas rhoncus.</p><br/>
<ul class="hotelpreferences">
<li class="icohp-internet"></li>
<li class="icohp-air"></li>
<li class="icohp-pool"></li>
<li class="icohp-childcare"></li>
<li class="icohp-fitness"></li>
<li class="icohp-breakfast"></li>
<li class="icohp-parking"></li>
<li class="icohp-pets"></li>
<li class="icohp-spa"></li>
</ul>
</div>
</div>
</div>
</div>
It is simple as you do it using the tables. Tables are used only because they already formatted so the output is clear means you can display different data in different rows by using or different columns using
You can also print the data in the divs same things as you follow in a table. If you have problems using the divs go through some tutorials for divs or you can still do it using the tables just give it proper styling using CSS.
I am new to joomla and trying to change a simple html template to joomla template. I made changes over the templatedetails.xml and index.php. Now my template is visible at templates of joomla. But it is not allowing to add menus or perform any joomla operation over to it.
Here is my index.php file,
<?php
/****************************************************
#####################################################
##-------------------------------------------------##
## TEMP ##
##-------------------------------------------------##
## Copyright = TEMP - 2013 ##
## Date = april 2013 ##
## Author = XYZ ##
## Websites = http://www.google.com ##
## ##
#####################################################
****************************************************/
// no direct access
defined('_JEXEC') or die('Restricted access');
/* The following line loads the MooTools JavaScript Library */
JHtml::_('behavior.framework', true);
/* The following line gets the application object for things like displaying the site name */
$app = JFactory::getApplication();
$csite_name = $app->getCfg('sitename');
$path = $this->baseurl.'/templates/'.$this->template;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<jdoc:include type="head" />
<?php $mod_right = $this->countModules( 'position-7' );
if ( $mod_right ) {
$width = '';
} else {
$width = '-full'; }
?>
<?php
$newsflash = $this->params->get("newsflash", " Content to be added here.. ");
?>
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/superfish.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/hoverIntent.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/hide.js"></script>
<script type="text/javascript" src="templates/<?php echo $this->template ?>/js/slideshow.js"></script>
<link rel="icon" type="image/gif" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/favicon.gif" />
<!--[if IE 7]>
<link href="templates/<?php echo $this->template ?>/css/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script type="text/javascript">
// initialise plugins
jQuery(function(){
jQuery('.navigation ul').superfish();
});
</script>
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
</div>
<div id="menu">
<ul id="main">
<li class="current_page_item">Home</li>
<li>Courses and Admission </li>
<li>Department</li>
<li>Research</li>
<li>Hospital</li>
</ul>
<ul id="feed">
<li>Webmail</li>
<li>Contact us </li>
</ul>
</div>
</div>
<!-- end header -->
<div id="wrapper">
<!-- start page -->
<div id="page">
<div id="sidebar1" class="sidebar">
<ul>
<li>
<h2>Recent Posts</h2>
<marquee scrollamount="3" direction="up" onmouseout="start()" onmouseover="stop();">
<ul>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Proin gravida orci porttitor</li>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Proin gravida orci porttitor</li>
</ul>
</marquee>
</li>
<li>
<h2>Recent Comments</h2>
<ul>
<li> Templates on Aliquam libero</li>
<li> Templates on Consectetuer adipiscing elit</li>
<li> Templates on Metus aliquam pellentesque</li>
<li> Templates on Suspendisse iaculis mauris</li>
<li> Templates on Urnanet non molestie semper</li>
<li> Templates on Proin gravida orci porttitor</li>
</ul>
</li>
<li>
<h2>Categories</h2>
<ul>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
</ul>
</li>
<li>
<h2>Archives</h2>
<ul>
<li>September (23)</li>
<li>August (31)</li>
<li>July (31)</li>
<li>June (30)</li>
<li>May (31)</li>
</ul>
</li>
</ul>
</div>
<!-- start content -->
<div id="content">
<div class="flower">
<img src="templates/<?php echo $this->template ?>/images/img06.jpg" width="510" height="250" alt="logotype" /></div>
<div class="post">
<h1 class="title">Welcome to TEMP !</h1>
<div class="entry">
<p>
<strong>TEMP </strong> is one of the SIX TEMP like apex healthcare institutes being established by the Ministry of Health & Family Welfare, Government of India under the Pradhan Mantri Swasthya Suraksha Yojna (PMSSY). With the aim of correcting regional imbalances in quality tertiary level healthcare in the country, and attaining self sufficiency in graduate and postgraduate medical education and training the PMSSY planned to set up 6 new TEMP like institutions in under served areas of the country.</p>
<p>These institutions are being established by an Act of Parliament on the lines of the original All India Institute of Medical Sciences in New Delhi which imparts both undergraduate and postgraduate medical education in all its branches and related fields, along with nursing and paramedical training. to bring together in one place educational facilities of the highest order for the training of personnel in all branches of health care activity. </p>
<p> </p>
<p class="links">«« Read More »»</p>
</div>
</div>
<div class="post">
<h2 class="title">Sample Tags</h2>
<div class="entry">
<h3>An H3 Followed by a Blockquote:</h3>
<blockquote>
<p>“Donec leo, vivamus nibh in augue at urna congue rutrum. Quisque dictum integer nisl risus, sagittis convallis, rutrum id, congue, and nibh.”</p>
</blockquote>
<h3>Bulleted List:</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Phasellus nec erat sit amet nibh pellentesque congue.</li>
<li>Cras vitae metus aliquam risus pellentesque pharetra.</li>
</ul>
<h3>Numbered List:</h3>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Phasellus nec erat sit amet nibh pellentesque congue.</li>
<li>Cras vitae metus aliquam risus pellentesque pharetra.</li>
</ol>
<p class="links">«« Read More »»</p>
</div>
</div>
<!-- end content -->
<!-- start sidebars -->
<div id="sidebar2" class="sidebar">
<ul>
<li>
<form id="searchform" method="get" action="#">
<div>
<h2>Site Search</h2>
<input type="text" name="s" id="s" size="15" value="" />
</div>
</form>
</li>
<li>
<h2>Tags</h2>
<p class="tag">dolor ipsum lorem sit amet dolor ipsum lorem sit amet</p></li>
<li>
<h2>Calendar</h2>
<div id="calendar_wrap">
<table summary="Calendar">
<caption>
October 2009
</caption>
<thead>
<tr>
<th abbr="Monday" scope="col" title="Monday">M</th>
<th abbr="Tuesday" scope="col" title="Tuesday">T</th>
<th abbr="Wednesday" scope="col" title="Wednesday">W</th>
<th abbr="Thursday" scope="col" title="Thursday">T</th>
<th abbr="Friday" scope="col" title="Friday">F</th>
<th abbr="Saturday" scope="col" title="Saturday">S</th>
<th abbr="Sunday" scope="col" title="Sunday">S</th>
</tr>
</thead>
<tfoot>
<tr>
<td abbr="September" colspan="3" id="prev">« Sep</td>
<td class="pad"> </td>
<td colspan="3" id="next"> </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td id="today">4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<td>29</td>
<td>30</td>
<td>31</td>
<td class="pad" colspan="4"> </td>
</tr>
</tbody>
</table>
</div>
</li>
<li>
<h2>Categories</h2>
<ul>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Metus aliquam pellentesque</li>
</ul>
</li>
</ul>
</div>
<!-- end sidebars -->
<div style="clear: both;"> </div>
</div>
<!-- end page -->
</div>
<div id="footer">
<p class="copyright">© 2009 All Rights Reserved • Design by TEMP IT Dept..</p>
<p class="link">Privacy Policy • Terms of Use</p>
</div>
</html>
Please suggest how i can change this html template to exact joomla template. Thanks.
Replace conrete content with references to module positions, message container and component output. Your template will then look like
<?php
/**
* My template
*
* #copyright (C)2013 Neetesh <neetesh#example.com>
* #author XYZ
* #link http://www.google.com
*/
// No direct access
defined('_JEXEC') or die('Restricted access');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<link rel="icon" type="image/gif" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/favicon.gif" />
<!--[if IE 7]>
<link href="templates/<?php echo $this->template ?>/css/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
<jdoc:include type="modules" name="logo" />
</div>
<div id="menu">
<jdoc:include type="modules" name="header" />
</div>
</div>
<div id="wrapper">
<div id="page">
<div id="sidebar1" class="sidebar">
<jdoc:include type="modules" name="left" />
</div>
<div id="content">
<jdoc:include type="message" />
<jdoc:include type="component" />
</div>
<div id="sidebar2" class="sidebar">
<jdoc:include type="modules" name="right" />
</div>
<div style="clear: both;"> </div>
</div>
</div>
<div id="footer">
<jdoc:include type="modules" name="footer" />
</div>
</html>
The example above provides the module positions logo, header, left, right, and footer. Add these to the templateDetails.xml.
Next, find modules producing the sudebar content, you want, and assign them to the position, where you want to see them.