PHP Sessions

stevet70

New Member
Messages
35
Reaction score
0
Points
0
I'm attempting to create a page that can switch between 2 sets of content, using Sessions and a form button.

Eventually it'll be used in a CMS to switch between an initial preview of how the page content looks and an editable version, but for now I'm just trying to get a basic functioning page I can build on.

Above the doctype I have

<?php
if (array_key_exists('edit', $_POST)) {
session_start();
$_SESSION['authenticated'] = 'Edit';
}
if (isset($_SESSION['authenticated'])) {
$view = 'Editable';
exit;
}
else {
$view = 'Preview';
}
?>

then in the body of the page is a form button 'Edit' and some simple PHP to test if the page works

<?php
if ($view == 'Editable') {
echo "Edit Mode";
} else {
echo "Preview Mode";
}
?>

When the page loads in it shows the Edit button and "Preview Mode", but when you click on Edit it returns a blank page

I'm obviously missing something important, but what?
Or am I going about this completely wrong?

Any help much appreciated
thanks
Steve
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
remove the "exit;" from the session check.

I think that should do the trick.

Otherwise the code looks fine.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
wewt!

That was a complete guess too. lol
 
Top