Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Session is not working.........why?

    hi friends,
    i wrote a simple login script. i created 3 pages login.php,loginck.php and welcome.php.........first the user enters into login.php. he should press the submit button when he fills out the username and password fields........after that, the page redirects to loginck.php........validations are done here.........i received the field values by $_POST['xxxx'];........then i have stored that value in a session(in loginck.php).........on successful login,page redirects to welcome.php.......in this page i want to display the user name.......i tried echo $_session['xxxx'];.....but it is not working.........why.....pls help me ........its urgent.......
    coding for welcome.php___________
    <?php
    @session_start();

    ?>


    <html>

    <head>
    <title>WELCOME</title>

    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

    welcome<?php

    echo $_session['xxxx'];

    ?>

    </body>

    </html>
    pls help me........but i created 2 pages which a string is stored in session at first page then it s displayed in the second page........it s working........but.......wat happen to the above program?

    give me one sample script which gets a value from a text field in first page and then to display that value in the third page through second page(not directly from first).....
    Last edited by mds8000; 08-02-2007 at 10:12 PM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post the code for loginchk.php and login.php

    Also learn to start typing proper sentences. This ... stuff makes it hard to understand you.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy code for login.php and loginck.php......

    sorry for my awkward sentences. yesterday i was very tensed due to this session issue. that's the reason which made me crazy to find out the solution.
    again sorry for that. go through the codes.........
    login.php

    <!doctype html public "-//w3c//dtd html 3.2//en">

    <html>

    <head>
    <title>Login</title>

    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

    <form action='loginck.php' method=post name="form2">
    <table border='0' cellspacing='0' cellpadding='0' align=center>
    <tr id='cat'>
    <tr> <td ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;Login ID &nbsp; &nbsp;
    </font></td> <td align='center'><font face='verdana, arial, helvetica' size='2' >
    <input type ='text' class='bginput' name='userid' ></font></td></tr>

    <tr> <td ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;Password
    </font></td> <td align='center'><font face='verdana, arial, helvetica' size='2' >
    <input type ='text' class='bginput' name='password' ></font></td></tr>

    <tr> <td colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
    <input type='submit' value='Submit'> <input type='reset' value='Reset'>
    </font></td> </tr>


    <tr> <td ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;<a href='signup.php'>New Member Sign UP</a></font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' >
    Forgot Password ?</font></td></tr>

    <tr> <td colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
    &nbsp;</font></td> </tr>


    </table></center></form>

    </body>

    </html>


    loginck.php
    <?php
    @session_start();

    $dbservertype='mysql';
    $servername='localhost';
    // username and password to log onto db server
    $dbusername='root';
    $dbpassword='sa';
    // name of database
    $dbname='signup';

    connecttodb($servername,$dbname,$dbusername,$dbpassword);
    function connecttodb($servername,$dbname,$dbuser,$dbpassword)
    {
    global $con;
    $con=mysql_connect ("$servername","$dbuser","$dbpassword");
    if(!$con){die("Could not connect to MySQL");}
    mysql_select_db("$dbname",$con) or die ("could not open db".mysql_error());
    }

    ?>

    <html>

    <head>
    <title>Login</title>
    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?php
    $userid=mysql_real_escape_string($userid);
    $password=mysql_real_escape_string($password);

    if($rec=mysql_fetch_array(mysql_query("SELECT * FROM login WHERE userid='$userid' AND password =

    '$password'"))){
    if(($rec['userid']==$userid)&&($rec['password']==$password))
    {
    $_session['id']=session_id();
    $_session['userid']=$_POST['userid'];
    echo $_session['userid'];


    print "<script>";
    print " self.location='welcome.php';"; // auto-redirect
    print "</script>";

    }
    }
    else {

    echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid

    and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";

    }
    ?>
    <p class=data> <center>Successfully,Logged in<br><br><a href=welcome.php>Click here if your browser is

    not redirecting automatically or you don't want to wait.</a><br></center>
    </body>

    </html>

    welcome.php
    <?php
    @session_start();
    if(isset($_SESSION['userid']))
    {
    echo "session is open. Welcome";
    echo $_session['userid'];
    }
    else
    {
    echo "session is not open";
    }



    ?>


    ---------------------------------------

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    Variable names are case sensitive. You have an inconsistent mix of $_SESSION['userid'] and $_session['userid']. Only $_SESSION[...] refers to an actual session variable.

    Don't suppress error reporting using an @, especially on session_start(). If it is failing due to an error, it won't work and you will never know the reason why.
    Last edited by CFMaBiSmAd; 08-03-2007 at 06:28 PM. Reason: fixed spelling of word
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy showing two warning's------

    it is showing two warning's on two pages (loginck.php , welcome.php), when i removed "@" before session_start() (also removed "session" with "SESSION")

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\loginck.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\loginck.php on line 2

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\loginck.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\loginck.php on line 2


    i'm using latest version of APACHE.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Make sure there is no whitespace above the <?php part in loginchk and welcome.php.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy no whitespace.....pls check the warning....

    there is no whitespace above <?php part...........

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    It is likely that the files are being saved in a Unicode/UTF-8 format, in which case some non-printing/binary characters are being output prior to the <?php. Check your editor "save as" file type setting for those files and make sure it is ANSI/ASCII.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #9
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thanks dude.......

    thank you soooooooooo much CFMaBiSmAd.now it is perfectly working.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •