+ Reply to Thread
Results 1 to 4 of 4

Thread: PHP Sessions

  1. #1
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    PHP Sessions

    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

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP Sessions

    remove the "exit;" from the session check.

    I think that should do the trick.

    Otherwise the code looks fine.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Re: PHP Sessions

    Thanks Neil, that's spot on

    Steve

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP Sessions

    wewt!

    That was a complete guess too. lol
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. PHP - Sessions Not Registering - Internet Explorer
    By masterjake in forum Programming Help
    Replies: 4
    Last Post: 08-31-2008, 04:53 AM
  4. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers