How to write php session on html page

Discussion in 'PHP' started by asit.ashmit, Jan 6, 2009.

  1. #1
    HI,

    Please suggest me that "How to write PHP session in html page?"

    My question is "suppose a.htm page when loading at that time it will check session id , If it is found then go to b.htm page neither if not found session id then it will back.".

    Please suggest me how to do this. It's very urgent for me.

    Thanks
    Asit
     
    asit.ashmit, Jan 6, 2009 IP
  2. drew22299

    drew22299 Guest

    Messages:
    76
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To use php code you will need to save the page as a .php file instead of .htm

    Try this code:

    <?php
    session_start(); // Start the session
    if(isset($_SESSION['value']))
    {
       header("Location: http://www.website.com/pagename.htm/"); // Redirect to page if session is found
    } 
    else 
    {
       
    $ref = $_SERVER['HTTP_REFERER'];
    header( 'refresh: 10; url='.$ref);
    
    }
    ?>
    PHP:
     
    drew22299, Jan 6, 2009 IP
  3. asit.ashmit

    asit.ashmit Banned

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    I put your code i'm getting this error
    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Inetpub\vhosts\impacterp.com\httpdocs\a.php:2) in D:\Inetpub\vhosts\impacterp.com\httpdocs\a.php on line 3

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Inetpub\vhosts\impacterp.com\httpdocs\a.php:2) in D:\Inetpub\vhosts\impacterp.com\httpdocs\a.php on line 3

    Warning: Cannot modify header information - headers already sent by (output started at D:\Inetpub\vhosts\impacterp.com\httpdocs\a.php:2) in D:\Inetpub\vhosts\impacterp.com\httpdocs\a.php on line 12

    Kindly check it.
     
    asit.ashmit, Jan 6, 2009 IP
  4. joomliste2000

    joomliste2000 Guest

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This code should placed at the beginning of the page.
     
    joomliste2000, Jan 6, 2009 IP