-1

Hallo,

I am trying to create session that works! This is the test admin (assign session) then afterward pass to input_image.php but I wonder why I cannot pass the index.php ?

admin.php

<?php


            //$_SESSION['banner'] = $banner;
            $_SESSION['banner'] = 'banner';

            //$_SESSION['image_id'] = $image_id;


            ?>

            <td><a href="input_image.php"><img src="images/<?php echo $data['newfilename']; ?>" height="150px" width="150px"><br><br>Lesson Class</a>              

input_image.php

<?php

// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.

session_start();


if(!isset($_SESSION['banner']))
    {
    header("location:index.php");
    exit;
    }


?>
3
Contributors
4
Replies
44
Views
2 Years
Discussion Span
Last Post by broj1
1

You should put the session_start() command on top of the admin.php script for session to work.

0

As broj1 said - you need to put session_start() at the top of your admin script to be able to assign any session variables for retrieval later. Every other page that accesses, updates, or creates $_SESSION[] variables needs to have session_start() at the top of the file (before processing any output) as well.

0

admin.php

<?php


                //$_SESSION['banner'] = $banner;
                $_SESSION['banner'] = 'banner';

                //$_SESSION['image_id'] = $image_id;


?>

input_image.php

<p><?php echo $_SESSION['banner']; ?></p>

<?php

$banner = $_SESSION['banner']; 

$result = mysql_query("SELECT * FROM image_upload ORDER BY image_id");

?>

input_image.php

Notice: Undefined variable: _SESSION in C:\xampp\htdocs\portal\administrator2\admin\input_image.php on line 73

Notice: Undefined variable: _SESSION in C:\xampp\htdocs\portal\administrator2\admin\input_image.php on line 77

How to fix the error ?

1

Repeating: You should put the session_start() command on top of the every script for session to work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.