Displaying content based on user session PHP - php

* I've solved this. Thanks for the help /*
I am attempting to show some images to different users depending on their user_id / username.
I am trying to do so by using userSession.
I tried by using this code:
<?php
if ($_SESSION['user_id'] == 'Charlie') {
// do admin
<li class="span4 gallery-item" data-id="id-1">
<img class="fancybox" src="img/photoshop2_small.jpg" data-big="img/photoshop2.jpg" /> </li>
}
?>
I also tried "userSession" and "user_email". None worked.
It cannot even load my website when I type in the code above. When I remove it, it loads perfectly.
Here's my home.php class which is the one that loads when a user is logged in. It's the same for everything atm but I am trying to display just certain images to the users depending on who they are. They have no special rank or anything.
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['userSession']))
{
header("Location: index2.php");
}
$query = $MySQLi_CON->query("SELECT * FROM users WHERE user_id=".$_SESSION['userSession']);
$userRow=$query->fetch_array();
$MySQLi_CON->close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS
================================================== -->
<link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-responsive.css">
<!--<link rel="stylesheet" href="css/prettyPhoto.css" />-->
<!--<link rel="stylesheet" href="css/flexslider.css" />-->
<link rel="stylesheet" href="css/custom-styles.css">
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<link rel="stylesheet" href="css/style-ie.css"/>
<![endif]-->
<!-- Favicons
================================================== -->
<link rel="shortcut icon" href="img/favicon.ico">
<link rel="apple-touch-icon" href="img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114.png">
<!--Fancybox dwuser.com-->
<link rel="stylesheet" type="text/css" media="screen" href="http://cdnjs.cloudflare.com/ajax/libs/fancybox/1.3.4/jquery.fancybox-1.3.4.css" />
<style type="text/css">
a.fancybox img {
border: none;
-o-transform: scale(1,1); -ms-transform: scale(1,1); -moz-transform: scale(1,1); -webkit-transform: scale(1,1); transform: scale(1,1); -o-transition: all 0.2s ease-in-out; -ms-transition: all 0.2s ease-in-out; -moz-transition: all 0.2s ease-in-out; -webkit-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;
}
a.fancybox:hover img {
position: relative; z-index: 999; -o-transform: scale(1.03,1.03); -ms-transform: scale(1.03,1.03); -moz-transform: scale(1.03,1.03); -webkit-transform: scale(1.03,1.03); transform: scale(1.03,1.03);
}
</style>
<!--Fancybox end-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test | <?php echo $userRow['user_email']; ?></title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div class="color-bar-1"></div>
<div class="color-bar-2 color-bg"></div>
<div class="container main-container">
<div class="row header"><!-- Begin Header -->
<!-- Logo
================================================== -->
<div class="span5 logo">
<img src="img/%20black.png" alt="" />
</div>
<!-- Main Navigation
================================================== -->
<div class="span7 navigation">
<div class="navbar hidden-phone">
<ul class="nav">
<li>Hjem</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="gallery.html">Galleri <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Galleri</li>
<li>Bryllup</li>
<li>Portræt</li>
<li>Udendørs</li>
<li>Andet</li>
<!--<li></li>-->
</ul>
</li>
<li>Kontakt</li>
</ul>
<!-- Username and logout button .... nav bar only -->
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> <?php echo $userRow['user_name']; ?></li>
<li><span class="glyphicon glyphicon-log-out"></span> Logout</li>
</ul>
</div>
</div>
</div><!-- End Header -->
<div class="row headline"><!-- Begin Headline -->
<!-- Page Content
================================================== -->
<div class="row">
<!-- Gallery Items
================================================== -->
<div class="span12 gallery">
<div class="row clearfix">
<ul class="gallery-post-grid holder">
<h6>Tryk på billederne for at forstørre dem og for at opnå bedre kvalitet</h6>
<li class="span4 gallery-item" data-id="id-1">
<img class="fancybox" src="img/photoshop2_small.jpg" data-big="img/photoshop2.jpg" />
</li>
<li class="span4 gallery-item" data-id="id-2">
<img class="fancybox" src="img/IMG_2205-Edit-1_small.jpg" data-big="img/IMG_2205-Edit-1.jpg" />
</li>
</ul>
</div>
</div><!-- End gallery list-->
</div><!-- End container row -->
</div> <!-- End Container -->
<!-- Footer Area
================================================== -->
<div class="row"><!-- Begin Bottom Section -->
</div><!-- End Bottom Section -->
</div> <!-- End Container -->
<!-- Scroll to Top -->
<div id="toTop" class="hidden-phone hidden-tablet">Back to Top</div>
<!-- JS
================================================== -->
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<!--<script src="js/jquery.easing.1.3.js"></script>-->
<script src="js/bootstrap.js"></script>
<!--<script src="js/jquery.prettyPhoto.js"></script>-->
<!--<script src="js/jquery.quicksand.js"></script>-->
<!--<script src="js/jquery.custom.js"></script>-->
<!--Fancybox script-->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/fancybox/1.3.4/jquery.fancybox-1.3.4.pack.min.js"></script>
<script type="text/javascript">
$(function($){
var addToAll = false;
var gallery = true;
var titlePosition = 'inside';
$(addToAll ? 'img' : 'img.fancybox').each(function(){
var $this = $(this);
var title = $this.attr('title');
var src = $this.attr('data-big') || $this.attr('src');
var a = $('').attr('href', src).attr('title', title);
$this.wrap(a);
});
if (gallery)
$('a.fancybox').attr('rel', 'fancyboxgallery');
$('a.fancybox').fancybox({
titlePosition: titlePosition
});
});
$.noConflict();
</script>
</body>
</html>

You never changed the session data in your example code. You should do something like:
$_SESSION['user_id'] = $userRow['user_id']
to set the concerning session var.

try this code instead of yours:
<?php
if ($_SESSION['user_id'] == 'Charlie') { ?>
// do admin
<li class="span4 gallery-item" data-id="id-1">
<img class="fancybox" src="img/photoshop2_small.jpg" data-big="img/photoshop2.jpg" /> </li>
<?php } ?>
EDIT if user ID is unique and not depended on letters casing you can do
if (strtolower($_SESSION['user_id']) === 'charlie')

Related

script show errors about design

i tested a script like 5months ago it was all good, when i uploaded now it on a host it shows so much errors any idea what is the problem ?
It shows like this: https://prnt.sc/118djwo , https://prnt.sc/118dkmy
So it dont show the design like navbar, butons etc it shows only text typed
the code of this page:
<?php
include "config.php";
include "functions/function.views.php";
include "functions/function.notifications.php";
if(!isset($_SESSION['aname']) and !isset($_SESSION['apass'])){
header("location: login.php");
exit();
}
function extrat_ress($item,$query, $dbcon){
$line1 = mysqli_query($dbcon,$query);
$line2 = mysqli_fetch_assoc($line1);
return $line2[$item];
}
?>
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/favicon.ico">
<title>TEST</title>
<style type="text/css">
.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('https://vanishingpointcreative.com/bhiva/app/assets/preloader.gif') 50% 50% no-repeat rgb(249,249,249);
}
.well-box.linnea {
line-height: 25px;
}
.rad-info-box {
border-radius:13px;
margin-bottom: 10px;
box-shadow: 1px 1px 2px 0 #CCCCCC;
padding: 20px;
box-shadow: 0 1px 1px 0 rgba(0,0,0,.16),0 1px 1px 0 rgba(0,0,0,.12);
background: white !important;}
.rad-info-box i {
display: block;
background-clip: padding-box;
margin-right: 15px;
height: 60px;
width: 60px;
border-radius: 100%;
line-height: 60px;
text-align: center;
font-size: 4.4em;
position: absolute;
}
.rad-info-box .value,
.rad-info-box .heading {
display: block;
position: relative;
color: #515d6e;
text-align: right;
z-index: 10;
}
.rad-info-box .heading {
font-size: 1.2em;
font-weight: 300;
text-transform: uppercase;
}
.rad-info-box .value {
font-size: 2.1em;
font-weight: 600;
margin-top: 5px;
}
#media screen and (max-width: 450px) {
.rad-info-box i {
opacity: .3;
}
}
</style>
<!-- jquery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<!-- Notifer Alert -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap252.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css" >
<!-- Custom core CSS -->
<link href="css/stylea.css" rel="stylesheet">
<link href="css/navbarr.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/offcanvas.css" rel="stylesheet">
<!-- datatable information -->
<link href="css/dataTables.bootstrap.min.css" rel="stylesheet">
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<!-- SweetAlert -->
<link rel="stylesheet" href="alerts/sweetalert.css">
<script src="alerts/sweetalert-dev.js"></script>
<script src="alerts/sweetalert.min.js"></script>
<!-- spin files -->
<script src="js/spin.js"></script>
<script src="js/spin.min.js"></script>
<link rel="stylesheet" href="css/alertify.core.css" />
<link rel="stylesheet" href="css/alertify.default.css" />
<script src="js/alertify.min.js"></script>
<!-- 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.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body style="margin-top: 75px;">
<!-- // loader -->
<div class="loader"></div>
<!-- // nav menu -->
<nav class="navbar navbar-fixed-top navbar-inverse">
<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">TEST</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Dashboard" style="margin-left: 10px;">TEST</a>
</div>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="border-radius: 0;">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header" style="margin-left: 15px;">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">TEST</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Dashboard">TEST</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<!-- //left menu -->
<ul class="nav navbar-nav">
<li>
<a>||</a>
</li>
<li></i>A</li>
<li></i>S</li>
<li></i>T</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Balance <b>
<?php
$uid = mysqli_real_escape_string($dbcon,$_SESSION['aname']);
echo '<span class="label btn-info">'.
extrat_ress('balance',"SELECT * FROM users WHERE username='".$uid."'",$dbcon).
'$</b></span>';
?>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><i class="fa fa-btc"></i> Add Bitcoin$</li>
<li><i class="fa fa-rub"></i> Add PerfectMoney$</li>
<li class="divider"></li>
<li><i class="fa fa-history"></i> Billing History</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Support <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><i class="fa fa-commenting"></i> My Tickets</li>
<li><i class="fa fa-envelope"></i> Reported</li>
<li class="divider"></li>
<li><i class="fa fa-plus-circle"></i> Open New Ticket</li>
</ul>
</li>
<li><i class="fa fa-shopping-cart"></i> Purchased </li>
<li></i>Rules</li>
<li><i class="fa fa-angle-double-up"></i> </li>
</ul>
<!-- // reight menu -->
<ul class="nav navbar-nav navbar-right" style="margin-right : 5px;">
=
<li><i class="fa fa-user"></i> My Profile</li>
<li class="divider"></li>
</li><li><i class="fa fa-power-off"></i></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</nav>
<?php
$q=mysqli_query($dbcon,"SELECT * FROM s WHERE sold='0'");
$q0=mysqli_query($dbcon,"SELECT * FROM c WHERE sold='0'");
$q1=mysqli_query($dbcon,"SELECT * FROM a WHERE sold='0'");
$q2=mysqli_query($dbcon,"SELECT * FROM t WHERE sold='0'");
$q3=mysqli_query($dbcon,"SELECT * FROM tool ");
$wsq = mysqli_query($dbcon,"SELECT * FROM settings")or die(mysqli_error());
$rsq = mysqli_fetch_assoc($wsq);
// check if banned
$user = $_SESSION['aname'];
$sbanned = mysqli_query($dbcon,"SELECT * FROM banned WHERE username='$user'") or die(mysqli_error());
$nbanned = mysqli_num_rows($sbanned);
if($nbanned > 0)
{
header("Location: banned.html");
die();
exit();
}
?>
<script type="text/javascript">
function buythistool(id){
var tbl = $("#buyt"+id).attr('type');
$.ajax({
method:"GET",
url:"ajax/buytool.php?id="+id+"&t="+tbl,
dataType:"text",
success:function(data){
if(data.match(/successfully/)){
sweetAlert("",data,"success")
}else{
sweetAlert("",data,"error")
}
},
});
}
function check(id){
var type = $("#shop"+id).attr('type')
$("#shop"+id).html('<img src="w1loading.gif" alt="Wait">').show();
$.ajax({
type: 'GET',
url: 'checker.php?id='+id+'&type='+type,
success: function(data)
{
$("#shop"+id).html(data).show();
}});
}
function cpanelit(id){
$("#shop"+id).html('<img src="img/w1loading.gif" alt="Wait">').show();
$.ajax({
type: 'GET',
url: 'cpanel.php?id='+id,
success: function(data)
{
$("#shop"+id).html(data).show();
}});
}
$(window).load(function() {
$(".loader").fadeOut("slow");
})
</script>
Your issue in style paths, you set static path for heads file...
Simply, try to add backslash for your includes like:
"/css/..."
or
"/js/..."
<script src="/js/jquery.min.js"></script>
<!-- Notifer Alert -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap252.css" rel="stylesheet">
<link rel="stylesheet" href="/css/font-awesome.min.css" >
<!-- Custom core CSS -->
<link href="/css/stylea.css" rel="stylesheet">
<link href="/css/navbarr.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/css/offcanvas.css" rel="stylesheet">
<!-- datatable information -->
<link href="/css/dataTables.bootstrap.min.css" rel="stylesheet">
<script src="/js/jquery.dataTables.min.js"></script>
<script src="/js/dataTables.bootstrap.min.js"></script>
<!-- SweetAlert -->
<link rel="stylesheet" href="alerts/sweetalert.css">
<script src="alerts/sweetalert-dev.js"></script>
<script src="alerts/sweetalert.min.js"></script>
<!-- spin files -->
<script src="/js/spin.js"></script>
<script src="/js/spin.min.js"></script>
<link rel="stylesheet" href="/css/alertify.core.css" />
<link rel="stylesheet" href="/css/alertify.default.css" />
<script src="/js/alertify.min.js"></script>
<!-- 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>
================
For trace issue, you can open console and check errors, if this solution not resolve your issue, you can take screen shoot from console error and check network error file...any 404 or 401
also make sure your read/write file is set correctly in host like
644 for file, 755 for directory.

How to add a carousel as background in bootstrap4?

I am building a simple website with bootstrap4 and I am trying to set a carousel as the background. Is there any simple way to do it without keyframes?
You can use bootstrap default carousel with some tweaks, namely the z-index and position attributes.
Image 1, 2 and 3 must be replaced by your own images, without them it will not work very well and the size adapted to your needs, you can also add indicators for the image and arrows cycle through images.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Carousel Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<style>
/* Make the image fully responsive */
.carousel-inner img {
width: 100%;
height: 100%;
}
#demo{
position: absolute;
z-index: -1;
}
#frontpage{
color: red;
font-size: larger;
background-color: yellow;
opacity: 0.5;
padding: 50px;
}
</style>
</head>
<body>
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="Image1.jpg" alt="Image1" width="1920" height="1080">
</div>
<div class="carousel-item">
<img src="Image2.jpg" alt="Image2" width="1920" height="1080">
</div>
<div class="carousel-item">
<img src="Image3.jpg" alt="Image3" width="1920" height="1080">
</div>
</div>
</div>
<div id="frontpage">
My frontpage over the carousel
</div>
</body>
</html>

$_SESSION['login_user'] not workig

I'm trying to figuring out what the problem but I can't.
Basically I have the index.php with a login to an admin area and admin.php that Is the main page of the admin area.
If I remove the SESSION from the admin.php page the login itself works but I can reach the page admin.php without logging into index, but if I add the SESSION to admin.php after the login it goes straight to the else at the end of the admin.php page.
For sure I'm failing something with the SESSION but I don't know what.
Index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="icon" type="image/png" href="images/favico.png">
<title>eWaste</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="css/mdb.min.css" rel="stylesheet">
<!-- Your custom styles (optional) -->
<link href="css/style.css" rel="stylesheet">
<style>
html{
margin-top: 100px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light grey lighten-5 fixed-top">
<div class="container">
<a class="navbar-brand" href="../index.php">
<img src="../images/logo.png" height="30" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarResponsive">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" id="navi-current" href="index.php">Admin</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Navbar -->
<!--Main-->
<main class="mb-4 pb-5">
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-3"></div>
<div class="col-xl-4 col-lg-4 col-md-6">
<form class="text-center border border-light p-5" method="post" name="">
<p class="h4 mb-4">Sign in</p>
<!-- Email -->
<input type="text" id="materialContactFormUsername" class="form-control" placeholder="User" name="formuser">
<!-- Password -->
<input type="password" id="defaultLoginFormPassword" class="form-control mb-4" placeholder="Password" name="formpass">
<!-- Login button -->
<button class="btn btn-info btn-block my-4" type="submit" name="submit">Sign in</button>
</form>
</div>
<div class="col-xl-4 col-lg-4 col-md-3"></div>
</div>
</div>
</main>
<!--/.Main-->
<?php
if (isset($_POST['submit']))
{
include 'conn.php';
session_start();
$user = $_POST['formuser'];
$pass = $_POST['formpass'];
$query = mysqli_query($conn, "SELECT user FROM login WHERE user='$user' and pass='$pass'");
if (!$query) {
die('Invalid query: ' . mysqli_error());
}
if (mysqli_num_rows($query) != 0){
$_SESSION['login_user']=$username;
header("Location: admin.php");
}
else{
echo "<script type='text/javascript'>alert('User Name Or Password Invalid!')</script>";
}
mysqli_close($conn);
}
?>
<!--Footer-->
<?php include 'footer.php';?>
<!--/.Footer-->
<!-- SCRIPTS -->
<!-- JQuery -->
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Initializations -->
<script type="text/javascript">
// Animations initialization
new WOW().init();
</script>
</body>
Admin.php
<?php
if (isset($_SESSION['login_user'])){
session_start();
echo "ok";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="icon" type="image/png" href="images/favico.png">
<title>eWaste</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="css/mdb.min.css" rel="stylesheet">
<!-- Your custom styles (optional) -->
<link href="css/style.css" rel="stylesheet">
<style>
html{
margin-top: 100px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light grey lighten-5 fixed-top">
<div class="container">
<a class="navbar-brand" href="../index.php">
<img src="../images/logo.png" height="30" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarResponsive">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" id="navi-current" href="index.php">Admin</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Navbar -->
<!--Main-->
<main class="mb-4 pb-5">
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-3"></div>
<div class="col-xl-4 col-lg-4 col-md-6">
</div>
<div class="col-xl-4 col-lg-4 col-md-3"></div>
</div>
</div>
</main>
<!--/.Main-->
<!--Footer-->
<?php include 'footer.php';?>
<!--/.Footer-->
<!-- SCRIPTS -->
<!-- JQuery -->
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Initializations -->
<script type="text/javascript">
// Animations initialization
new WOW().init();
</script>
</body>
</html>
<?php
}
else{
echo "no";
exit();
}
?>
Please try to place this code
<?php
if (isset($_POST['submit']))
{
include 'conn.php';
session_start();
$user = $_POST['formuser'];
$pass = $_POST['formpass'];
$query = mysqli_query($conn, "SELECT user FROM login WHERE user='$user' and pass='$pass'");
if (!$query) {
die('Invalid query: ' . mysqli_error());
}
if (mysqli_num_rows($query) != 0){
$_SESSION['login_user']=$username;
header("Location: admin.php");
}
else{
echo "<script type='text/javascript'>alert('User Name Or Password Invalid!')</script>";
}
mysqli_close($conn);
}
?>
At the Start of the page. You can not assign value into the session if you print something on browser. It will give you warnings.

Redirect to another page after user login using angular.js router and PHP

i need one help.I want to redirect into another page after user login using angular.js.I am using php for back end and here i want to use Angular router.I have done some coding but its not working properly.I am explaining my code below.
index.html:
<!DOCTYPE html>
<html lang="en" ng-app="Channabasavashwara">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>...:::WELCOME TO Channabasavashwara Institude of Technology:::...</title>
<!-- PACE LOAD BAR PLUGIN - This creates the subtle load bar effect at the top of the page. -->
<link href="css/pace.css" rel="stylesheet">
<script src="js/pace.js"></script>
<script src="js/angularjs.js" type="text/javascript"></script>
<script src="controller/loginController.js" type="text/javascript"></script>
<!-- GLOBAL STYLES - Include these on every page. -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic' rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel="stylesheet" type="text/css">
<link href="icons/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link rel="shortcut icon" href="img/favicon.png">
<!-- PAGE LEVEL PLUGIN STYLES -->
<!-- THEME STYLES - Include these on every page. -->
<link href="css/style.css" rel="stylesheet">
<link href="css/plugins.css" rel="stylesheet">
<link href="css/chosen.css" rel="stylesheet">
<!-- THEME DEMO STYLES - Use these styles for reference if needed. Otherwise they can be deleted. -->
<link href="css/demo.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<style type="text/css">
<!--
body{
background-color:#FFF !important;
}
.well {
min-height: 20px;
padding: 19px !important;
margin-bottom: 20px;
background-color: #f5f5f5;
border: 1px solid #e3e3e3;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
}
-->
</style>
</head>
<body>
<!-- /#wrapper -->
<div id="wrapper">
<div class="container">
<div class="row">
<div class="col-md-12 text-center login-header" style="padding:40px 0px;">
</div>
<!--/span-->
</div><!--/row-->
<div class="col-md-6 marginautodiv floatnonediv well" ng-controller="loginController">
<div class="totalaligndiv">
<div class="alert alert-info text-center">
<span style="font-weight:bold; font-size:22px">Channabasavashwara Institude of Technology</span>
<BR>
Please login with your Username and Password.
</div>
<form class="form-horizontal" name="frmlogin" id="frmlogin" action="" autocomplete="off">
<fieldset>
<div class="input-group input-group-lg">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" name="txtname" id="txtname" class="form-control" placeholder="Username" ng-model="user_name">
</div>
<div class="clearfix"></div><br>
<div class="input-group input-group-lg">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" name="pwd" id="pwd" class="form-control" placeholder="Password" ng-model="user_pass">
</div>
<div class="clearfix"></div>
<div class="input-prepend">
</div>
<div class="clearfix"></div>
<p class="text-center tbpaddingdiv2">
<button type="text" name="login" id="login" class="btn btn-primary" style="width:270px;" ng-click="user_login();">Login</button>
</p>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<!-- GLOBAL SCRIPTS -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.slimscroll.min.js"></script>
<script src="js/jquery.popupoverlay.js"></script>
<script src="js/defaults.js"></script>
<!-- Logout Notification Box -->
<!-- /#logout -->
<!-- Logout Notification jQuery -->
<script src="js/logout.js"></script>
<!-- HISRC Retina Images -->
<!-- THEME SCRIPTS -->
<script src="js/flex.js"></script>
<script src="js/dashboard-demo.js"></script>
<script src="js/chosen.jquery.js" type="text/javascript"></script>
<script src="js/prism.js" type="text/javascript"></script>
<script type="text/javascript">
var config = {
'.chosen-select' : {},
'.chosen-select-deselect' : {allow_single_deselect:true},
'.chosen-select-no-single' : {disable_search_threshold:10},
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
'.chosen-select-width' : {width:"95%"}
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
</script>
</body>
</html>
In this page user will login and when click on login button the user will redirect to dashboard page.
loginController.js:
var loginAdmin=angular.module('Channabasavashwara',['ngRoute']);
loginAdmin.config(function($routeProvider){
$routeProvider
.when('/dashboard',{
templateUrl: 'view/dashboard.html',
controller: 'dashboardController'
});
})
loginAdmin.controller('loginController',function($scope,$http){
$scope.user_login=function(){
if($scope.user_name==''){
alert('user name filed should not keep blank');
}else if($scope.user_pass==''){
alert('password filed should not keep blank');
}else{
var userData={'user_name':$scope.user_name,'user_pass':$scope.user_pass};
$http({
method: 'POST',
url: "php/Login/login.php",
data: userdata,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
alert(response.data['msg']);
location.href='#dashboard';
},function errorCallback(response) {
alert(response.data['msg']);
});
}
}
});
I want to use router for routing the page.Please help me to resolve this problem.
use this
$location.path == '/dashboard';
instead of using
location.href='#dashboard';
You can use routing also
this.router.navigate(['/dashboard']);
in TS file.

Passing values over two pages PHP

Just trying to refresh my memory of PHP and have come across this problem. Im trying to pass a value from one page to another. I have been trying session variables and have called session_start(). Even when setting the variable on the page = 'string' it prints nothing. What am I doing wrong here? Im trying to get the value of the # of stars and the textarea from the contactus page to the review.php page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<link rel="stylesheet" href="Icons/icon-pack-custom.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
[data-role=page]{height: 100% !important; position:relative !important;}
[data-role=footer]{bottom:0; position:absolute !important; top: auto !important; width:100%;}
#banner img {
width:100%;
}
.ui-collapsible {
width:130px;
}
</style>
</head>
<body>
<!-- Start of first page: #one -->
<div data-role="page" id="home" data-theme="b">
<div data-role="header" >
<h1>Forever Fitness</h1>
<nav data-role="navbar" data-iconpos="left">
<ul>
<li>Home</li>
<li>Products</li>
<li>Contact Us</li>
</ul>
</nav>
</div><!-- /header -->
<div data-role="content" >
</div><!-- /content -->
<div data-role="controlgroup">
<p>
<?php
session_start();
echo $_SESSION['ta'] = 'string';
?>
</p>
Home
Back
</div>
</div><!-- /page one -->
START OF THE NEXT PAGE
<?php
session_start();
$_SESSION['ta'] = 'string';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Citizenship Canada</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<link rel="stylesheet" href="Icons/icon-pack-custom.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
[data-role=page]{height: 100% !important; position:relative !important;}
[data-role=footer]{bottom:0; position:absolute !important; top: auto !important; width:100%;}
#banner img {
width:100%;
}
.ui-collapsible {
}
</style>
</head>
<body>
<!-- Start of first page: #one -->
<div data-role="page" id="home" data-theme="b">
<div data-role="header" >
<h1>Forever Fitness</h1>
<nav data-role="navbar" data-iconpos="left">
<ul>
<li><a href="index.html" data-icon="home" >Home</a></li>
<li><a href="provinces.html" data-icon="shop" >Products</a></li>
<li>Contact Us</li>
</ul>
</nav>
</div><!-- /header -->
<div data-role="content">
<div data-role="collapsible" data-collapsed-icon="phone" data-expanded-icon="phone">
<h4>Contact By Phone</h4>
<ul data-role="listview" data-inset="true">
<li>1-800-991-1929 Toll Free</li>
</ul>
</div>
<div data-role="collapsible" data-collapsed-icon="phone" data-expanded-icon="phone">
<h4>Contact By Email</h4>
<ul data-role="listview" data-inset="true">
<li>Send an Email</li>
</ul>
</div>
<ul data-role="listview" data-inset="true">
<li>Write a Review</li>
</ul>
</div>
</div>
<div data-role="page" id="r" data-theme="b">
<div data-role="content" >
<h2 style="text-align:center;">Write a Review</h2>
<form action="review.php" method="get">
<label for="stars">Stars</label>
<input type="range" name="stars" id="stars" value="5" min="0" max="5" data-highlight="true" />
<div data-role="fieldcontain">
<label for="textarea">Your Review</label>
<textarea name="textarea" id="textarea"></textarea></br>
<input type="submit"value="submit" data-theme="b">
</div>
</form>
</div><!-- /content -->
<div data-role="controlgroup">
Home
Back
</div>
</div><!-- /page one -->
</html>
First page - define session variable
<?php
session_start();
$_SESSION['ta'] = 'string';
?>
On second page - display the session variable
<?php
session_start();
echo $_SESSION['ta'];
?>

Categories