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;
    }


?>

Recommended Answers

All 4 Replies

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

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.

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 ?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.