session not initialising or destroying when initialised
Posted: Fri Jan 16, 2015 3:12 am
hi,
im a php noob trying to echo session variable based on what the user name is but neither is the session initialising nor is it destroying as i can go from index to home page by typing it in the browser with out the user input can any one help me with this(pardon my english) my code is as follows(if im missing something please tutor me on that too as that wud b helpful becoz web resources on sessions r not helpful)
code in home.php:
note that it isn't also echoing any session variable too then here is my session stop page:
were am i going wrong???
here is my 1.1php code:
and 1.php code:
im a php noob trying to echo session variable based on what the user name is but neither is the session initialising nor is it destroying as i can go from index to home page by typing it in the browser with out the user input can any one help me with this(pardon my english) my code is as follows(if im missing something please tutor me on that too as that wud b helpful becoz web resources on sessions r not helpful)
code in home.php:
Code: Select all
<?php
include '1.1.php';
include '1.php';
ob_start();
session_start();
$_SESSION['uname']=$s1||$b1;
?>
<!DOCTYPE html>
<html>
<head>
<title>fetch-array</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</script>
<link href="css/hello.css" rel="stylesheet">
<script type="text/javascript" src="tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector: "textarea#elm1",
theme: "modern",
width: 500,
height: 150,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code media insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
],
content_css: "css/content.css",
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons",
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
]
});
</script>
</head>
<body>
<header> <div align="left"><a href="session_stop.php">logout</a></div></header>
<br>
<div id="container">
<div class="Container-left">
<?php echo $_SESSION['uname'];?>
</div>
Code: Select all
<?php
session_start();
session_unset();
session_destroy();
if(session_destroy()==1){
setcookie('', NULL, time()-100,'/');
header('location:index.php');}here is my 1.1php code:
Code: Select all
<?php
include 'config.php';
error_reporting(E_ALL ^ E_NOTICE);
$b1= stripslashes($_POST['uname']);
$b2= stripslashes($_POST['pass']);
$e1=mysqli_real_escape_string($conn,$b1);
$e2=mysqli_real_escape_string($conn,$b2);
$sql2= "SELECT * FROM turfregister1 WHERE uname='$e1' and pass='$e2'";
$query2 = "SELECT id, uname FROM turfregister1 WHERE uname = '$e1'";
if (isset($_POST['button1'])&& mysqli_query($conn,$sql2)) {
session_start();
header('location: home.php');
}
else {
echo mysqli_error($conn);
}
Code: Select all
<?php
include 'config.php';
include 'session_start.php';
error_reporting(E_ALL ^ E_NOTICE);
$s1=stripslashes($_POST['uname']);
$s2=stripslashes($_POST['pass']);
$s3=stripslashes($_POST['no']);
$s4=stripslashes($_POST['ei']);
$s5=stripslashes($_POST['gender']);
$s6=stripslashes($_POST['fname']);
$s7=stripslashes($_POST['lname']);
$a1= mysqli_real_escape_string($conn,$s1);
$a2=mysqli_real_escape_string($conn,$s2);
$a3=mysqli_real_escape_string($conn,$s3);
$a4=mysqli_real_escape_string($conn,$s4);
$a5=mysqli_real_escape_string($conn,$s5);
$a6=mysqli_real_escape_string($conn,$s6);
$a7=mysqli_real_escape_string($conn,$s7);
$sql="INSERT INTO turfregister1 (uname,pass,no,ei,gender,fname,lname) VALUES ('$a1', '$a2' ,$a3,'$a4','$a5','$a6','$a7') ";
if (isset($_POST['submit']) && mysqli_query($conn,$sql)) {
echo "data inserted";
session_start();
header ('location: home.php');
}
else {
echo mysqli_error($conn);
}
mysqli_close($conn);