modifying from admin panel and logging out does not save the images - php

I have a main pain where I want to modify things from the admin account
and whenever I log out of the admin account the images are not saved and it give me an undefined index error.
this is my main page php code:
<?php $src = $_SESSION['firstimgsrc'];echo "<img id='first' src='$src'>";?><!-- Direct link 1st champion -->
<?php $src1 = $_SESSION['secondimgsrc'];echo "<img id='second' src='$src1'>"; ?><!-- Direct link 2nd champion -->
<?php $src2 = $_SESSION['thirdimgsrc'];echo "<img id='third' src='$src2'>";?> <!-- Direct link 3rd champion -->
<?php $src3 = $_SESSION['forthimgsrc'];echo "<img id='forth' style='border-right: 0px;' src='$src3'>"; ?> <!-- Direct link 4th champion -->
this is the admin panel php code:
<?php
if(isset($_POST['submit'])) {
session_start();
$firstimgsrc = $_POST['firstimgsrc'];
if ($firstimgsrc == "") {
$_SESSION['firstimgsrc'] = $jk;
} else {
$_SESSION['firstimgsrc'] = $firstimgsrc;
$jk = $_SESSION['firstimgsrc'];
}
$secondimgsrc = $_POST['secondimgsrc'];
if ($secondimgsrc == "") {
$_SESSION['secondimgsrc'] = $jk1; } else {
$_SESSION['secondimgsrc'] = $secondimgsrc;
$jk1 = $_SESSION['secondimgsrc'];
}
$thirdimgsrc = $_POST['thirdimgsrc'];
if ($thirdimgsrc == "") {
$_SESSION['thirdimgsrc'] = $jk2;
} else {
$_SESSION['thirdimgsrc'] = $thirdimgsrc;
$jk2 = $_SESSION['thirdimgsrc'];
}
$forthimgsrc = $_POST['forthimgsrc'];
if ($forthimgsrc == "") {
$_SESSION['forthimgsrc'] = $jk3;
} else {
$_SESSION['forthimgsrc'] = $forthimgsrc;
$jk3 = $_SESSION['forthimgsrc'];
}
header("Location: ../egamingtv.php");
}
?>

worked, I just used unset instead of the session_destroy in my logout page

Related

How to save favorite images after logout and still see them after login?

Problem:
So when I login, a user can go to the browse.php to add images to the favorites.php, and the photos will appear on that page.
When I log out and log back in, the images are gone (not saved).
Question:
How do I save it after I logout so on next login I get to see the favorite'd images from that particular user using cookies or other methods (can't use database because I'm not allowed to)?
My favorites page
<?php
session_start();
require_once 'favoritesfunction.php';
if (isset($_GET["fileName"])) {
$fileName = $_GET["fileName"];
addToFavorites($fileName);
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
$title = "Travel Photos - View Favorites";
?>
<link rel="stylesheet" href="viewfavorites.css" />
</head>
<body>
<main class="container">
<h1 class="favheader">Favorites</h1>
<div class="content">
<?php
if (isset($_SESSION['favorites']) && isset($_SESSION['email'])) {
$favorites = $_SESSION['favorites'];
if (count($favorites) > 0) {
?> <ul class="ul-favorite"> <?php
foreach ($favorites as $f) {
echo '<img class="displayPic" src="https://storage.googleapis.com/assignment1_web2/square150/' . $f . '">';
}
?>
</ul>
<p id="removeall"><button class="button"><span><a target="" href="services/removefavorites.php?remove=all">Remove All</a></span></button></p>
<?php
}
} else {
?>
<div class="nofavorites">
<p>No favorites found.</p>
</div>
<?php
}
?>
</div>
</main>
</body>
<script type="text/javascript" src="main.js"></script>
</html>
My add to favorites function php
<?php
function addToFavorites($fileName)
{
//Checks if the session favorites exists
if (isset($_SESSION['favorites'])) {
$favorites = $_SESSION['favorites'];
} else {
$favorites = array();
$_SESSION['favorites'] = $favorites;
}
// add item to favourites
$item = $fileName;
$match = false;
//Loop below checks for duplicates
$i = 0;
while ($i < count($favorites)) {
if ($favorites[$i] == $item) {
$favorites[$i] = $item;
$match = true;
}
$i++;
}
//if match equals false, that means its not in the favorites list of the user
//so it is added to the user's favorites array
if ($match == false) {
$favorites[] = $item;
}
$_SESSION['favorites'] = $favorites;
$_SESSION['favorites'] = $favorites;
}
My approach:
I tried doing something like setting $name = $_SESSION['email'] and $value="<img src=...>" then setcookie($name, $value) and then if(isset($_COOKIE[$value])) echo $value
I know this is totally wrong, I tried looking everywhere online to try to solve this, if I could get some help that would be great thanks!

PHP pageName pulling from other page

I'm working on my script site I have the url setup like this with PHP.
movies.php?pages=action
But every time a member goes to the url it pulls the page name from movies.php how can I fix this issue I have pasted my code down below.
<?php
// StreamPlex Page System - Play Page
DEFINE("IN_STREAMPLEX", 1);
$pageName = "All Movies";
require_once('inc/config.php');
require_once('inc/header.php');
$action = $_GET['action'];
$pages = $_GET['pages'];
if(isset($pages)) {
require_once("{$pages}.php");
} else {
?>
Then at the bottom of the page I have finished off with this code here
<?php include 'inc/footer.php'; ?>
<?php } ?>
Can somebody please help me in telling me what I'm doing wrong.
I have fix the issue i had change around the code at the top of the page from
<?php
DEFINE("IN_STREAMPLEX", 1);
$pageName = "All Movies";
require_once('inc/config.php');
require_once('inc/header.php');
$action = $_GET['action'];
$pages = $_GET['pages'];
if(isset($pages)) {
require_once("{$pages}.php");
} else {
?>
To this
<?php
// StreamPlex Page System - Play Page
DEFINE("IN_STREAMPLEX", 1);
$action = $_GET['action'];
$pages = $_GET['pages'];
if(isset($pages)) {
require_once("{$pages}.php");
} else {
$pageName = "All Movies";
require_once('inc/config.php');
require_once('inc/header.php');
?>
Now it works in loads with no problems.

userbased content from session php

I'm looking to setup a group field for my custom user script. How can I go about only showing certain content to certain groups
Example:
admin (all content)
moderator (extended content)
user (user content)
guest (general overview)
4 group id's 0 - 4
4 banned
3 admin
2 moderator
1 user
0 guest
Example of the PHP in use
// Keep reminding the user this account is not active, until they activate
if($row['group_id'] == 4) { //display all
echo
'<div class="info">
This account is at risk of being banned Please obey the site rules.
</div>';
} else {
exit();
}
Example of the PHP MySQL session
/* Displays user information and some useful messages */
session_start();
// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
$_SESSION['message'] = "You must log in before viewing your profile page!";
header("location: http://localhost/login-system/error.php");
}
else {
// Makes it easier to read
$first_name = $_SESSION['first_name'];
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email'];
$active = $_SESSION['active'];
$group_id = $_SESSION['group_id'];
}
You can do this with this example:
Lets say in this is a blog.
<?php
// 0 = Banned
// 1 = User
// 2 = Admin
if($_SESSION['group_id'] == 0) {
?>
<h1>You Are Banned</h1>
<?php
} elseif($_SESSION['group_id'] == 1) {
?>
<p>Welcome to my blog.</p>
<?php
} elseif($_SESSION['group_id'] == 2) {
?>
<p>Welcome to my blog.</p><button>Delete Post</button>
<?php
}
Or you can do this by a second method:
<p id="1">Welcome To My Blog!</p><button id="2">Delete Content</button>
<h1 id="3">You are banned from this website!</h1>
<?php
if($_SESSION['group_id'] == 0) {
echo '<style>
#2 {
display:none;
}
#3 {
display:none;
}
</style>';
} elseif ($_SESSION['group_id'] == 1) {
echo '<style>
#1 {
display:none;
}
#3 {
display:none;</style>';
} elseif ($_SESSION['group_id'] == 2) {
echo '<style>
#1 {
display:none;
}';
}
Hope this helps!

Displaying nav if path equals path

I have a php page with two navs. One is an admin nav, the other is public. using the code below I'm trying to determine the directory i'm in and depending on that show the proper nav. I feel like this php snippet should work.
<?php
$public = APP_PUBLIC_PATH;
$admin = APP_ADMIN_PATH;
if(is_dir($public)) {
$publicnav = "showme";
$adminnav = "hideme";
}
else if (is_dir($admin)) {
$publicnav = "hideme";
$adminnav = "showme";
}
?>
<nav class="<?php echo $publicnav; ?">
<nav class="<?php echo $admin; ?">
I've also tried the following:
<?php
$public = APP_PUBLIC_PATH;
$admin = APP_ADMIN_PATH;
if(is_dir($public)) {
$publicnav = "showme";
$adminnav = "hideme";
}
else {
$publicnav = "hideme";
$adminnav = "showme";
}
?>
<nav class="<?php echo $publicnav; ?>">
<nav class="<?php echo $admin; ?>">
is_dir only checks to see if the path you provided is a directory or not. Your goal is to check whether the current path is for the admin or for a regular user?
Look into the $_SERVER superglobal variable on how to get the current URI. I believe something like this.
$currentPath = $_SERVER['REQUEST_URI'];
if ($currentPath == $public) {
// do logic
} else if ($currentPath == $admin) {
// other logic
}

javascript for onClick not executing?

ok maybe i must put all my code:
<?php
include('header_application.php');
$obj_clean->check_user();
$limit = 10;
if(!isset($_GET['page']))
$page = 1;
else
$page = $_GET['page'];
$from = (($page * $limit) - $limit);
$msg = "";
if (isset($_GET['unblock']))
{
$code = $obj_clean->unblockUser($_GET['unblock'],$_GET['code']);
if ($code == "error")
{
$msg = "Could not delete message!";
}
else
{
$msg = "You have unblocked ".$code;
}
}
//Get dynamic data required for this page from the database
$users = $obj_clean->getContacts($_SESSION['user_id'], $from, $limit);
$rows = $obj_clean->getContactsCount($_SESSION['user_id']);
include ("header.php");
?>
<div class="innerContainer">
<head>
<script type="text/JavaScript">
function yesnolist(val)
{
var e = confirm('Do you want to send a free chat request?');
if (e == true)
{
window.location.href = "http://www-rainbowcode-mobi/confirmfreechat.php";
//window.location('http://www-rainbowcode-mobi/confirmfreechat.php');
return true;
}
else
return false;
}
</script>
</head>
<span class="headings2">CONTACTS</span>
<?php if (isset($msg) && !empty($msg)) echo "<br/><font color='red'>".$msg."</font>"; ?>
<br/><br/>
<?php
if (count($users) > 0)
{
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
foreach ($users as $user)
{
//Breaks the unique code into 3 parts so that the numeric part can be a different colour
$codeLength = strlen($user['unique_code']);
$firstPartLength = $codeLength - 5;
$uniqueCode3 = substr($user['unique_code'], -2);
$uniqueCode2 = substr($user['unique_code'], -5, 3);
$uniqueCode1 = substr($user['unique_code'], 0, $firstPartLength);
echo '<tr>';
echo '<td>';
echo '<a class="charcoal_link" style="line-height: 20px;" href="'.ADDRESS.'view_profile.php?id='.$user['profile_id_contact'].'">'.$uniqueCode1.'<span class="pink_text">'.$uniqueCode2.'</span>'.$uniqueCode3.'</a>';
$requestor_id = $_SESSION['user_id'];
$profile_id = $user['profile_id_contact'];
$rel1 = $obj_clean->hasRelation($requestor_id,$profile_id);
$rel2 = $obj_clean->hasRelation($profile_id,$requestor_id);
if($rel1 && $rel2)
{
echo " ";
//echo 'Free Chat';
echo 'Free Chat';
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "You have no contacts yet";
}
?>
</div>
<?php include("footer.php"); ?>
hope this will help better
Free Chat
should be:
Free Chat
try this:
function yesnolist()
{
if (confirm('Do you want to send a free chat request?'))
window.location = "http://www-rainbowcode-mobi/confirmfreechat.php";
}
.
.
.
<a href="#" onClick="yesnolist()">
I'd assume changing the URLs to valid domains might help things, so try:
window.location.href = "http://www.rainbowcode.mobi/confirmfreechat.php";
window.location('http://www.rainbowcode.mobi/confirmfreechat.php');
function yesnolist()
{
var e = confirm('Do you want to send a free chat request?');
if (e == true)
{
window.location = "http://www-rainbowcode-mobi/confirmfreechat.php";
return true;
}
else
return false;
}
and
<label onClick="return yesnolist();">Free Chat</a>
You can not pass onclick event on (a href="") tag because href part redirects the page and after that the javascript redirect part is called.
Or
(a href="#" onclick="return yesnolist();")Free Chat(/a)

Categories