Showing different links depending on who is logged in - html

I'm trying to create a few links that change depending on who is logged in, for example when a user logs in, log in changes to log out, just started making the if statements but they dont seem to recognise the sessions. Can anyone see an issue? Excuse the poor layout, been playing around.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="skeleton.css" />
<link rel="stylesheet" type="text/css" href="normalize.css" />
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Assignment1</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<?php
if (isset($_SESSION['userlogged']))
{
?>
<div class="container">
<div class="row">
<center><h4>Basic Requirements</h4>
<pre>
Logout Registration Contact Search
</pre>
</div>
</center>
</div>
<?php
}
else if (isset($_SESSION['adminlogged']))
{
}
else
{
?>
<div class="container">
<div class="row">
<center><h4>Basic Requirements</h4>
<pre>
Logout Registration Contact Search
</pre>
</div>
</center>
</div>
<?php
}
?>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>
Loginsubmit.php
<?php
session_start();
?>
<font face="ClearSans-Thin">
<font color="lightgray">
<?php
include 'connection.php';
include 'loginform.php';
?>
<center>
<?php
if (isset($_POST['submit']))
{
$user = $_POST['username'];
$pass = $_POST['password'];
//Counts up how many matches there are in the database
$query = "SELECT COUNT(*) AS cnt FROM users WHERE Username ='" . mysqli_real_escape_string($connection, $user) . "'AND Password='" . mysqli_real_escape_string($connection, $pass). "'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
/*$queryadmin = "SELECT COUNT(*) AS cnt FROM admin WHERE Username ='" . mysqli_real_escape_string($connection, $user) . "'AND Password='" . mysqli_real_escape_string($connection, $pass). "'";*/
/*$resultadmin = mysqli_query($connection, $queryadmin);*/
/*$rowadmin = mysqli_fetch_assoc($resultadmin);*/
//If count is more than 0, log user in.
if ($row["cnt"] > 0)
{
$_SESSION["userlogged"] = $user;
echo "Logged in - Press the home button to return to the homepage";
}
else if ($rowadmin["cnt"] > 0 )
{
$_SESSION["adminlogged"] = $user;
echo "Logged in - Press the home button to return to the homepage";
}
else
{
echo 'Not a valid login';
}
}
?>

your index page needs the session_start(); to read session variables
session_start();
echo $_SESSION['userlogged'];

Related

problem with redirect page on Facebook login

I am trying to use Facebook login on my website with inserting Facebook user data on my database.
I have those files as shown below :
index.php:
session_start();
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/preload.css?ve=5"/>
<title>Myexpect</title>
</head>
<body>
<?php
if ($_SESSION['FBID']):
require_once('connections/connect.php');
?> <!-- After user login -->
<div id="warper">
<div class="logo">
<img width="150px" height="150px"src="images/Logo - Copy.png">
</div>
<div class="welcome">
<h2>Welcome to our website</h2>
</div>
<div class="preload">
<img width="50" height="50px"src="loading.gif">
</div>
</div>
<?php
echo '<meta http-equiv = "refresh" content = "3; url = games.php" />'
?>
<?php else: ?> <!-- Before login -->
<div class="container">
<div><img src="images/fb-login-btn.png" ></div>
</div>
<?php endif ?>
</body>
</html>
fbconfig.php :
<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
require 'dbconfig.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication( 'xxxxxxxxxxxx','xxxxxxxxxxxxxx' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('https://xxxxx/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
$check = mysqli_query($connection,"select * from Users where Fuid='$fbid'");
$check = mysqli_num_rows($check);
if (empty($check)) { // if new user . Insert a new record
$query = "INSERT INTO Users (Fuid,Ffname,Femail) VALUES ('$fbid','$fbfullname','$femail')";
mysqli_query($connection,$query);
} else { // If Returned user . update the user record
$query = "UPDATE Users SET Ffname='$ffname', Femail='$femail' where Fuid='$fuid'";
mysqli_query($connection,$query);
/* ---- header location after session ----*/
header("Location: index.php");
} } else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
?>
The problem i have is when user try to login successfully it is not redirect to index.php file but fbconfig.php with a code :
https://xxxx/fbconfig.php?code=AQAAuanQBQ9lmXsAgbCuRB3aYy3YEEhrd81VBMMjih5oHo4dK_C7zMkQPZnuX5EdVvRJ2v4ybyAQ3EZ7qTzIrK9Oo-uY0KWiA6ZjNVh_4I6J7_AZDsJ12f7LGfc8EAGwgAfWwAm2Scwkx0UON9Vpjj75SBg7TX7n....etc
when i click back it work correctly and index.php work
how can i solve this
Sorry it was variables name mistake
this code is wrong :
$query = "UPDATE Users SET Ffname='$ffname', Femail='$femail' where Fuid='$fuid'";
i changed it to :
$query = "UPDATE Users SET Ffname='$fbfullname', Femail='$femail' where Fuid='$fbid'";
and it is work now

simple CSS switcher and save cookie

I want to create a button that can switch between stylesheets (example below) and I would like for it to create a cookie so that the browser remembers and saves the setting.
<button id="style1">Light</button>
<button id="style2">Dark</button>
<link rel="stylesheet" type="text/css" href="style1.css">
<link rel="stylesheet" type="text/css" href="style1.css">
The simpler the code the better. Thank you!
You can use PHP to set and get the cookie and change the style based on that.
switch1.php
<?php
setcookie("s", "1");
header("Location: index.html");
?>
switch2.php
<?php
setcookie("s", "2");
header("Location: index.html");
?>
index.html
<link rel="stylesheet" type="text/css" href=
<?php
if isset($_COOKIE["s"]))
echo '"style' . $_COOKIE["s"] . '.css"';
else
echo '"style1.css"';
?>
>
<button id="style1">Light</button>
<button id="style2">Dark</button>

No video with supported format and mime type in my php code

alert('Your Comment is added!')";
}
else{
echo "alert('Cannot Comment')";
}
}
?>
<!doctype html>
<meta charset="UTF-8">
<meta name="description" content="" >
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compaign Shack </title>
<link rel="shortcut icon" type="image/png" href="img/fevicon.png"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1
/jquery.min.js">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4
/js/bootstrap.min.js">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<style>
#comment{
border-bottom-left-radius:5px;
border-bottom-right-radius:5px;
border-top-left-radius:5px;
border-top-right-radius:5px;
box-shadow: 10px 10px 5px #888888;
}
<div class="container">
Advetising Agency :
".$agency." , Brand Name : ".$row['br_name'].""; ?>
Television
Image
Outdoor
Print
Digital
radio";
?>
'>
" type="video/mp4">
" type="video/ogg">
" type="video/webm">
"
style='width:60%; height:60%'>
"
style='width:60%; height:60%'>
"
style='width:60%; height:60%'>
" style='width:60%;
height:60%'>
"
style='width:60%; height:60%'>
</div>
Other Details
Other Details :
"; ?>
Creative Team : $cr
";
echo "Month : $row[month]
";
echo "Advertising Agency :
$row[ad_agency]";
echo "Account Team : $a_t ";
echo "Brand Name : ".$b_name."
Campaign Slogan : ".$c_slo ."
Media Release : ".$m_r ."
Account Leader : " . $a_l ."
Production : ". $pr ."
Research Agency : ". $r_a ."
Additional Credit : ". $a_c."
Media : TV,Radio,Outdoor,Digital,Print
";
}
?>
2014-03-06 7:37 am
hallo, please help me, i get invalid
article id, i already follow all the instruction and no such
php?id=1 at my page, im using phpadmin v 5.1,
without article id, nothing i can progress. tq
-->
Wanna Comment ?? Login here";
}
else{
echo "
";
}
?>
";
echo ''.$rrrr[3].'';
echo "
2014-03-06 7:37 am";
echo "".$rrrr[2]."
";
$na=$rrrr[3];
if($na==$una){
echo "";
}
echo "
";
}
/*
echo "";
$qqq="select * from comment where post_id=".$_GET['id'];
$rrr=mysqli_query($con,$qqq);
while($rrrr=mysqli_fetch_array($rrr))
{
$na=$rrrr[3];
echo "
$rrrr[3]
$rrrr[2]
";
if($una==$na){
echo " delete
";}
else{
echo "";
}
echo "
";
}
?>
*/
?>
| Login
| Register
Campaign Shack News
Have you ever stumbled across a Pakistani advertisement and
wondered about the people and agencies behind the advertising campaign? The
creative minds who have attempted to communicate some brand related message to
you?
Or about the ad work that was done in a
particular time frame?
Have you ever stumbled across a Pakistani advertisement and wondered
about the people and agencies behind the advertising campaign? The creative
minds who have attempted to communicate some brand related message to you?
Or about the ad work that was done in a
particular time frame?
Space for Google Adds
</div>
<?php include("footer.php"); ?>
<div id="picture_view" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×
<h4 class="modal-title">View</h4>
</div>
<div class="modal-body">
<img src='img/1.png '/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
</div>
</div>
</div>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/custom.js"></script>
When i upload a video individually from FTP it will play and when i'll upload form a website it show the mime type or something remove type error
Here is the Link:
http://campaignshack.com/subarchives.php?id=85
Firstly, you see the semi-colon in
$row=mysqli_fetch_array($res);{
^ right there
that is killing your script and tells it to end the statement.
Nothing in there will executed.
Remove it.
$row=mysqli_fetch_array($res){
However, that should be a while loop.
while($row=mysqli_fetch_array($res)){...}
as in:
while($row=mysqli_fetch_array($res)){
$img1=$row['image'];
$video=$row['video'];
$show="/vdo/".$video;
$lom=$row['lo_med'];
$agency=$row['ad_agency'];
}
Also make sure that $_GET['id'] is indeed an int and not a string.
Add or die(mysqli_error($con)) to mysqli_query().
If it is a string, then you will need to modify your query, such as:
$id = $_GET['id'];
$query="select * from archives where id='".$id."'";
But this method is open SQL injection, use mysqli with prepared statements, or PDO with prepared statements, they're much safer.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.

Crazy 403 Forbidden Error on Wordpress Site

Just installed a new theme on my site: www.rivertam.co
For some reason I keep getting this 403 Forbidden error at the top of it.
I've tried removing the htaccess file like some have suggested, nothing happens. Really no idea why it's there.
Can anyone give me any suggestions?
Happy to paste any PHP you may need. Just let me know!
Header.php code:
<!DOCTYPE html>
>
>
>
>
<title><?php wp_title( ' ', true, 'right' ); /* filtered in libraries/filers.php */ ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="shortcut icon" href="<?php echo get_template_directory_uri(); ?>/favicon.gif" />
<link rel="apple-touch-icon" href="<?php echo get_template_directory_uri(); ?>/apple-touch-icon.png" />
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<?php
// See functions.php for CSS / JAVASCRIPT information
wp_head(); // do not remove this
?>
>
<div id="branding_wrap">
<header id="branding">
<div class="container">
<?php
// Grab the column settings from theme settings to determine the logo/menu container sizes
$logo_columns = $menu_columns = "eight";
$header_layout = cudazi_get_option( 'header_layout', 'eight|eight' );
$header_layout = explode('|', $header_layout);
if ( is_array( $header_layout ) ) {
$logo_columns = $header_layout[0];
$menu_columns = $header_layout[1];
}
?>
<hgroup class="<?php echo $logo_columns; ?> columns">
<h1 id="logo"><?php echo cudazi_get_logo(); ?></h1>
<?php if ( ! cudazi_get_option( 'disable_tagline', false ) ) { ?>
<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
<?php } ?>
</hgroup>
<nav class="<?php echo $menu_columns; ?> columns" id="navigation" role="navigation">
<?php wp_nav_menu( array( 'menu_class' => 'sf-menu clearfix', 'theme_location' => 'primary', 'fallback_cb' => 'cudazi_menu_fallback' ) ); ?>
<?php echo cudazi_alternate_menu( array( 'menu_name' => 'primary', 'display' => 'select' ) ); ?>
</nav>
</div><!--//container (skeleton) -->
</header><!--//header-->
</div>
<section id="main">
Do you include any other files programmativally? (AJAX?)
If yes I would first check permissions! Files have to be world-readable (in normal setups) to be delivered through web...

Switching to Codeigniter HMVC - Undefined functions?

I have setup a fresh install of codeigniter 2x and modular extensions (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home)
It is my first time using HMVC, the decision to move from MVC to HMVC was to give myself more control of my login, admin, and members areas.
I have created my first controller in HMVC like so....
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MX_Controller {
function __construct()
{
parent::__construct();
$this->load->model('Content_model');
}
public function index()
{
$this->load->view('includes/template');
}
}
and a view like:
<?php echo doctype(); ?>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $pagecontent['seo_title']; ?></title>
<meta name="description" content="<?php echo $pagecontent['seo_description']; ?>" />
<meta name="keywords" content="<?php echo $pagecontent['seo_keywords']; ?>" />
<meta name='robots' content='all' />
<link rel="icon" type="image/ico" href="<?php echo base_url("images/favicon.png"); ?>" />
<?php echo link_tag('css/style.css'); ?>
<script type="text/javascript" language="javascipt" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="<?php echo base_url("js/jquery.validate.min.js"); ?>"></script>
<script type="text/javascript" language="javascript" src="<?php echo base_url("js/main.js"); ?>"></script>
</head>
<body>
<?php $this->load->view('includes/notify'); ?>
<div id="topbar">
<?php $this->load->view('includes/topbar'); ?>
When I try and view the page in my browser I get the following error:
Fatal error: Call to undefined function doctype() in C:\xampp\htdocs\mintfifty\application\modules\site\views\includes\template.php on line 1
The code has worked in all my previous codeigniter (mvc) projects but not (hmvc) why is it not working in HMVC? What am I doing wrong?
This issue is not likely to be caused by HMVC. doctype() function is defined in html helper and it seems that You have not loaded it (Unless you have auto-loaded it). Just load the html helper in your controller and it should work fine.
public function index()
{
$this->load->helper('html');
$this->load->view('includes/template');
}