I am creating a qr-code generator program with PHP, and I am using a library called qr-code. I have gotten to the point where I have successfully gotten the string the user wishes to convert into a qrcode, at the point to generate the qrcode I get the following error :
Uncaught Error: Call to a member function getContentType() on null in index.php:13 Stack trace: #0 {main} thrown in index.php on line 13
I have been at this for a while now, and I am stuck. There is really now in-depth documentation for the library in question, Please help me out. Here is my code :
<?php
require __DIR__ . '/vendor/autoload.php';
use Endroid\QrCode\QrCode;
// Get url from form
if (isset($_GET['submit'])) {
$url = strval($_GET['url']);
echo gettype($url);
$qrcode = new QrCode("$url");
echo "</br>";
header('Contert-Type: application/' . $qrCode->getContentType());
$createCode = $qrCode->writeString();
}
?>
<!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 name="description" content="" />
<title>QR Code Generator</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="./bootstrap.min.css" />
<style>
body {
padding-top: 5rem;
}
.starter-template {
padding: 3rem 1.5rem;
text-align: center;
}
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-danger fixed-top">
<a class="navbar-brand text-center" href="#">QR Code Generator</a>
</nav>
<main role="main" class="container">
<div class="starter-template">
<form method="GET" action="<? htmlspecialchars($_SERVER['PHP_SELF']);?>">
<div class="form-group">
<label for="url">URL</label>
<input type="text" class="form-control" id="url" name="url" />
</div>
<button type="submit" name="submit" class="btn btn-danger">Generate</button>
</form>
<div class="d-flex justify-content-center mt-5">
<div
class="starter-template card text-white bg-danger mb-3"
style="max-width: 20rem;"
>
<div class="card-body">
<p class="card-text">
<?php echo $createCode;?>
</p>
</div>
</div>
</div>
</div>
</main>
<!-- /.container -->
<script
src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"
></script>
</body>
</html>
Here is a link to the library
You are trying to use $qrCode which does not exist, look at your code carefully:
$qrcode = new QrCode("$url");
echo "</br>";
header('Contert-Type: application/' . $qrCode->getContentType());
$createCode = $qrCode->writeString();
First you use $qrcode then you use $qrCode (which does not exist).
Change the first line to:
$qrCode = new QrCode("$url");
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
In the following codes I used universal header and footer and my problem is that when I add universal footer(I mean this part of code : ) calendrer does not open and I can not select date and time there!! and when I remove footer everything is fine!! I wonder what should I do to overcome this problem.
Thank you for your help in advance
<?php
$title = "drinkmenu";
include "header.php" ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $title ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css">
<style>
body {
background-image: url(images/salad.jpg);
color: white;
text-align: center;
background-size: cover;
background-attachment:fixed;
background-repeat: no-repeat;
mmargin-top: 90px;
display: flex;
flex-flow: column;
overflow-x: hidden;
}
.image {
display: block;
width: 100%;
height: 100%;
}
h2 , h3 {
margin-left: 1%;
color: white !important;
}
#booking {
margin-left: 1%;
background-color: rgb(43, 26, 8);
}
</style>
</head>
<body>
<div class="row">
<h2>Book a table</h2>
</div>
<div class="row">
<div class="col" id="booking">
<label for="sel1" class="form-label">Party size</label>
<select class="form-select form-select-lg mb-5" id="sel1" name="sellist1">
<option>1 person</option>
<option>2 persons</option>
<option>3 persons</option>
<option>4 persons</option>
<option>+5 persons</option>
</select>
<div class="">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<span>Select time with Date</span>
<div class='input-group date' id='datetimepicker2'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<br/>
</div>
</div>
</div>
</div>
<script>
$(function() {
$('#datetimepicker1').datetimepicker({
format: 'HH:mm'
});
$('#datetimepicker2').datetimepicker({
format: 'MM/DD/YYYY HH:mm'
});
$('#datetimepicker3').datetimepicker({
format: 'hh:mm A',
});
});
</script>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<div class="col" id="">
<img class="image" src="images/Bookatable.jpg" alt="Moroccan tomato salad">
</div>
</div>
<?php include "footer.php" ?>
</body>
</html>
i expect calendar works properly
I want both the textbox and the button to occupy the entire div (which is colored) only using bootstrap. Here I show you a screenshot of my screen: https://postimg.cc/yJcPtVSg. I have tried several things (put the col-12) but I have not been successful. This is my code:
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/jquery-ui.css" />
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<LINK REL=StyleSheet HREF="css2/bootstrap.css" TYPE="text/css">
</head>
<body>
<div class="container" style='height:600px;'>
<div class='row h-100 '>
<div class='col bg-danger my-auto d-flex justify-content-center alig-items-center '>
<form action="lineas.php" method="post">
<div class ='row m-3 '>
<?php echo("Elige origen: ");?>
<input type="text" id="origen" name="origen" class="form-control ">
</div>
<div class ="row m-3">
<?php echo("Elige destino: ");?>
<input type="text" id="destino" name="destino" class="form-control">
</div>
<div class ="row m-3">
Selecciona una fecha: <input type="text" id="datepicker" name="fecha" class="form-control">
</div>
<div class ="row m-3">
<input type="submit" name="enviar" value="Enviar" class="btn btn-primary btn-block">
</div>
</form>
<script src="js2/popper.min.js" type="text/javascript"></script>
<script src="js2/utilidades.js" type="text/javascript"></script>
</div>
</div>
</div>
</body>
</html>
Add this CSS.
.full-width {
width: 100vw;
position: relative;
left: 50%; /* adds left 50% to the element */
right: 50%; /* adds right 50% to the element */
margin-left: -50vw; /* it works as left: 0 */
margin-right: -50vw; /* it works as right: 0 */
}
add another div with class = "container" before form. it will work
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>
Really new with PHP. I have a login page that directs to an index page. On the index page there is a logout button. So when I click the logout, It will redirect to the login page and will unset the $_SESSION when i click the back button. But it does not destroy the session. It still redirects me to the index page. But with unset values already. Seems like session_destroy(); is not working. If anyone can help me, it would really be great. Thanks!
This is my login.php
<?php
require('session.php');
?>
<html>
<head>
<!-- CSS -->
<link rel="stylesheet" href="css/style-login.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="header">
<img src = "img/usc_logo.png">
</div>
<div class="box">
<form id="loginform" class="form-horizontal" role="form" action = "" method = "POST">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" class="form-control" name="username" value="" placeholder="ID Number" required/>
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div style="margin-top:10px" class="form-group">
<!-- Button -->
<div class="col-sm-12 controls">
<input class="submit-1" type = "submit" value = " Log in " name= "submit"/><br/><br/>
Not a member yet?
Register<br/><br/>
<center>
<span style='color:#e60000; font-size:15px;'><b><?php echo $error; ?></b></span>
</center>
</div>
</div>
</form>
</div>
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
And this is my index-admin.php
<?php
require('session.php');
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Jekyll v3.8.5">
<title>Admin DCIS</title>
<link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/album/">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<!-- Custom styles for this template -->
<link href="album.css" rel="stylesheet">
</head>
<body>
<header>
<div class="collapse bg-dark" id="navbarHeader">
<div class="container">
</div>
</div>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center">
<strong>Hello, <?php echo $_SESSION['user_role'] ?></strong>
</a>
Logout
</div>
</div>
</header>
<main role="main">
<section class="jumbotron text-center">
<div class="container">
<h1 class="jumbotron-heading">Name of Requestee</h1>
<button href="#" class="btn btn-primary my-2">Accept</button>
<button href="#" class="btn btn-secondary my-2">Reject</button>
</p>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
This is the logout.php
<?php
session_start();
session_unset();
session_destroy();
header('Location: login.php');
?>
In case needed, this is my session.php
<?php
require("dbconnector.php");
$error="";
session_start();
if(isset($_POST['submit'])){
require ('dbconnector.php');
$query = "SELECT * FROM user WHERE username = '{$_POST['username']}' AND password = '{$_POST['password']}'";
$con = mysqli_query($conn, $query);
if ($con->num_rows == 1){
$row = mysqli_fetch_assoc($con);
$_SESSION['user_role'] = $row['user_role'];
mysqli_close($conn);
if ($_SESSION['user_role'] == 'Admin'){
header('Location: index-admin.php');
}
elseif($_SESSION['user_role'] == 'Student') {
header('Location: index.php');
}
}
else{
$error = "ID Number or Password is Invalid";
header("refresh: 5");
}
}
?>
You need to properly destroy the session and the session's cookie on client side. I would recommend to not write this on the login page but rather on a specific page like logout.php that would redirect to login.html.
<?php
session_start(); // Start by calling the session.
$_SESSION = array(); // Reset the session's variables.
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]); //Invalids session's cookie.
session_destroy(); //Finally destroy it.
//If you want to redirect
header("Location: <URL>");
?>
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.