I have an iframe on my webpage:
<iframe name="crm_frame" id="crm_frame" src="<?php echo $iframe_src; ?>" width="100%" frameborder="0"></iframe>
and i have tried to add a session variable for the requested_uri
session_start();
if($_SERVER['REQUEST_URI'] == 'index.php')
{
$_SESSION["iframe_page"] = 'dashboard.php';
}
else
{
$_SESSION["iframe_page"] = $_SERVER['REQUEST_URI'];
}
and then set the $iframe_src variable for to echo in the SRC of the iframe code
if($_SESSION["iframe_page"] == '')
{
$iframe_src = 'dashboard.php';
}
else
{
$iframe_src = $_SESSION["iframe_page"];
}
but its not saving the sesison variable.
any ideas?
Related
I've got a login script that does not close the session when the user goes to another site or returns to the login page. My question is, how do I destroy the session when they navigate away from the site or outside of the directory? Would I need to add a timeout argument when the user starts the session? Would I need to use cookies instead of session?
login.php
require("../includes/header.php");
if($_SERVER["REQUEST_METHOD"] == "POST"){
$p_num = $_POST["username"];
$pwd = $_POST["password"];
$query = "SELECT * FROM $user_table";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result)){
$user_id = "{$row['user_id']}";
$user_name = "{$row['user_name']}";
$password = "{$row['password']}";
$image = "{$row['image']}";
$email = "{$row['email']}";
$program = "{$row['program']}";
$role = "{$row['role']}";
if(($user_id == $p_num) && ($pwd == $password)){
$_SESSION["id"] = $user_id;
$_SESSION["user"] = $user_name;
$_SESSION["program"] = $program;
$_SESSION["pass"] = $password;
$_SESSION["image"] = $image;
$_SESSION["email"] = $email;
$_SESSION["role"] = $role;
header("Location: ../pages/instructor.php");
}
else{
header("Refresh: 1; URL=../index.php");
}
}
}
instructor.php
<?php require("../includes/header.php"); ?>
<title></title>
<link href="../css/style.css" rel="stylesheet/less" type="text/css">
<script src="../js/jquery.2.0.3.js"></script>
<script src="../js/script.js"></script>
<script src="../js/less-1.7.4.min.js"></script>
</head>
<body>
<div id="page">
<header>
<div id="logo" class="logo_bg"></div>
<div id="fsi_logo" class="logo_bg"></div>
</header>
<div id="main">
<div id="instructor">
<?php
echo "<img id=instructor_image src=" .$_SESSION["image"] .">";
echo "<h1>" .$_SESSION["user"] ."</h1>";
echo "<span><p>" .$_SESSION["program"] ."</p> - <h2>" .$_SESSION["role"] ."</h2></span>";
echo "" .$_SESSION["email"] ."";
?>
</div>
<div id="bleg">
<h1>BUILD SCENARIO</h1>
<h1>SEARCH SCENARIOS</h1>
<h1>VIEW SCENARIOS</h1>
</div>
<?php require("../includes/footer.html"); ?>
logout.php
session_start();
session_unset();
session_destroy();
script.js
$(window).on('beforeunload', function(e){
e.preventDefault();
ajax = new XMLHttpRequest();
ajax.open("../php/logout.php", "POST", true);
ajax.send();
})
Do it with javascript
window.onbeforeunload = function (e) {
e.preventDefault(); //Not even sure what the default action does, but oh well
ajax = new XMLHttpRequest();
ajax.open("killsession.php","POST",true);
ajax.send();
}
killsession.php will of course be where the session is killed
Write a jquery/JS event handler for unload doc and send a request to ExpireSession.php expiring the session
As said "It depends on what constitutes "leaving""
$count = $_SESSION['count'];
if($count === 1) {
unset ($_SESSION['count']);
}
else (empty($_SESSION['count'])) {
$_SESSION['count'] = 1;
}
update :
The problem now is after using firebug I found out that the first element gets the title attribute and other elements don't and after hovering on any link the title attribute of the first link disappears any ideas?
I have a which page opens when I click on a link like this:
<a class="pictures" href="#" onClick="MM_openBrWindow('content_image.php','images','menubar=yes,scrollbars=yes,resizable=yes,width=650,height=700')" title="Images"></a>
This page has images stored in a folder:
$open = opendir($path);
while($images = readdir($open)){
if ($images != "." && $images != "..") {
$allimages[] = $images;
}
}
foreach($allimages as $val){
?>
<div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>
<form><img src="images/delete.gif"/> <textarea name='text_area' rows=1 cols=20 >../content_img/<?php echo $val; ?></textarea> <input type='button' value='select path' onClick='javascript:this.form.text_area.focus();this.form.text_area.select();'> Copy path and paste in image path field </form></div>
<?php
}
closedir($open);
?>
I am trying to delete images using a regular link with href to the page with the following attributes:
?do=delete&img=<?php echo $val; ?>
and then unlink() the image. However, the image is deleted as soon as I hover on the link without clicking. I don't know why.
I tried to do it using AJAX:
$(document).ready(function(e) {
$("div.uploaded_image").on("click","a.del_img",function(e){
e.preventDefault();
var img = $(this).attr("title");
var qst = "?img="+img+"&path=content_img";
var ajax = false;
ajax = new XMLHttpRequest();
ajax.open("post","del_image.php"+qst);
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
}
}
ajax.send(null);
setTimeout(ref,1500);
});
});
function ref(){
window.location = "content_image.php"
}
and this PHP code work uses AJAX to delete:
$img = $_REQUEST['img'];
$path = $_REQUEST['path'];
unlink("../".$path."/".$img);
When I click on the delete link for the first time it doesn't work. I have to click again to delete the image. Any help please?
$open = opendir($path);
while($images = readdir($open)){
if ($images != "." && $images != "..") {
$allimages[] = $images;
}
}
foreach($allimages as $val){
?>
<div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>
<form><img src="images/delete.gif"/> <textarea name='text_area' rows=1 cols=20 >../content_img/<?php echo $val; ?></textarea> <input type='button' value='select path' onClick='javascript:this.form.text_area.focus();this.form.text_area.select();'> Copy path and paste in image path field </form></div>
<?php
}
closedir($open);
?>
replace code with this code
change
$("div.uploaded_image").on("click","a.del_img",function(e){
e.preventDefault();
to
$("div.uploaded_image a").click(function(e){
e.preventDefault();
...
I am not very good at php but I want to detect if a user is in the home of the website such as;
<?php
if (current path = http://website.com/ || website.com)
{?>
<div>We are in home</div>
<?php } else { ?>
<div>do something</div>
<?php } ?>
Someone help me please thanks
$pageName = $_SERVER['PHP_SELF'];
if($pageName == 'http://website.com'){
echo '<div>We are in home</div>';
} else { do something };
I'm trying to make Jquery delete function, here is the code, that I wrote -
$("a.delete").click(function(){
var target = $(this).attr("id");
var c = confirm('Do you really want to delete this category?');
if(c==true) {
$(target+"ul").delay(3000).fadeOut(200);
}
else {
return false;
}
});
Okay now to problem, when I press, button a with class delete, it correctly, shows up the dialog (and the id is correct), but after I press yes, it will delete it with php, without jquery fadeOut effect.
My php code -
public function deleteCategory() {
if(isset($_GET['action']) && $_GET['action'] == 'delete') {
$id = (int)$_GET['id'];
$sql = "DELETE FROM `categories` WHERE `id` = '".$id."'";
mysql_query($sql);
}
}
Not sure where is the problem but I think it's inside $(target+"ul"), since I'm not sure, if it will add the target value and ul together.
In additional, how can I prevent the delete, if I press no? Currently, if I press no, it will still delete the category.
If you need any other information - ask.
Full code -
public function showCategories() {
if(isset($_SESSION['logged_in']) && isset($_SESSION['user_level']) && $_SESSION['user_level'] == 'admin') {
$sql = "SELECT * FROM `categories`";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0) {
?>
<div class="recentorders" style="display: none;" id="categoryBox">
<h5 class="colr">Categories</h5>
<div class="account_table" style="width: 688px;">
<ul class="headtable" style="width: 680px;">
<li class="order">ID</li>
<li class="action" style="width: 430px;">Category Name</li>
<li class="action nobordr">Options</li>
</ul>
<?php
while($row = mysql_fetch_array($q)) {
?>
<ul class="contable" style="width: 680px;" id="cat<?php echo $row['id']; ?>ul">
<li class="order"><?php echo $row['id']; ?></li>
<li class="action" style="width: 430px;"><?php echo $row['name']; ?></li>
<li class="action nobordr">Edit<a class="delete" id="cat<?php echo $row['id']; ?>" href="?action=delete&id=<?php echo $row['id']; ?>#">Delete</a></li>
</ul>
<?php
}
?>
</div>
</div>
<?php
}
else {
// No categories created, please create one first.
}
}
else {
header('location: account.php');
}
}
public function deleteCategory() {
if(isset($_GET['action']) && $_GET['action'] == 'delete') {
$id = (int)$_GET['id'];
$sql = "DELETE FROM `categories` WHERE `id` = '".$id."'";
mysql_query($sql);
}
}
If you're searching by ID you need to prefix your selector with a "#":
100% working sample on jsFiddle:
http://jsfiddle.net/E7QfY/
Change
$(target+"ul").delay(3000).fadeOut(200);
to
$('#' + target+"ul").delay(3000).fadeOut(200);
OR
$(this).closest('ul').delay(3000).fadeOut(200);
I would also modify the code to this:
$("a.delete").click(function(event){
if(confirm('Do you really want to delete this category?') == true){
$(this).closest('ul').delay(3000).fadeOut(200);
window.location.href = $(this).attr('href'); //OR use AJAX and do an event.preventDefault();
}
else
event.preventDefault();
});
It's because you are using an anchor tag that is causing a postback to the server which makes your page refresh before you see the animation. Make sure your anchor tag has an href defined as "#" to stop the postback from happening.
You should use something else than A tag e.g. span or div. And then after clicking this element make your fadeout and after it redirect to the PHP script that deletes your object:
$("SPAN,DIV.delete").click(function(){
var target = $(this).attr("id");
var c = confirm('Do you really want to delete this category?');
if(c==true) {
$(target+"ul").delay(3000).fadeOut(200);
window.location.href = URL TO PHP FILE
}
else {
return false;
}
});
My image roll over works... But only one way.
function heartOver(id)
{
if(document.getElementById('heart' + id).src == 'images/heart.png');
{
parent.document.getElementById('heart' + id).src = 'images/unheart.png';
}
if(document.getElementById('heart' + id).src == 'images/unheart.png');
{
parent.document.getElementById('heart' + id).src = 'images/heart.png';
}
}
<img src="images/heart.png" id="heart'.$row['id'].'" alt="Love! width="16" height="16" border="0" onmouseover="heartOver'."('$row[id]')".'; return true;" onmouseout="heartOver'."('$row[id]')".'; return true;">
If i comment out either of the IF statements the other will work but they wont work together...
Note: Tried this with a else if no luck.
Figured it out... Duh: i have if ( ) ; No ; after if...
Put an else between them - otherwise when the first if evaluates as true, it will cause the second if to be evaluated as true also!
Here's a simplified example which also checks the assumption that the img element even exists:
var img=document.getElementById('heart' + id);
if (img)
{
if(img.src == 'images/heart.png')
{
img.src = 'images/unheart.png';
}
else if(img.src == 'images/unheart.png')
{
img.src = 'images/heart.png';
}
}
else
{
alert("Ooooh! No heart"+id+" element found!");
}
Is this correct?
<img src="images/heart.png" id="heart'.$row['id'].'" alt="Love! width="16" height="16" border="0" onmouseover="heartOver'."('$row[id]')".'; return true;" onmouseout="heartOver'."('$row[id]')".'; return true;">
Try with this:
<img src="images/heart.png" id="heart<?php echo $row['id']; ?>" alt="Love!" width="16" height="16" border="0" onmouseover="heartOver(<?php echo $row['id']; ?>)" onmouseout="heartOver(<?php echo $row['id']; ?>)">