Results 1 to 7 of 7

Thread: two Problems with SESSION

  1. #1
    Join Date
    Mar 2012

    two Problems with SESSION

    I got a problem with sessions desribed as following

    when i established a login form and verified username and password obtained by this form with these stored into Data base using php code then if both username and password are ok comparing to these saved into database i establish a session for the user but this last step dosen,t work and no session established although it was working in my last website i emlemented but not working with this website i,m doing right now i tried much with the code but it did not work
    here is the code i,m using
    PHP Code:
    /*getting login variables */
    $username strip_tags(@$_POST['username']);
    $userpass strip_tags(@$_POST['password']);
    $submit =@$_POST['usersubmit']; (when user press submit button )
            if (
    /* Data base connection */
    include ("config.php");
    /* check for username and password*/
    if (!$username==""){
            if (!
    //convert obtained pass into MD5 to compare it with the stored one 
    $userpass md5(strip_tags(@$_POST['password']));
    $query mysql_query("SELECT * from commercial_members WHERE username='$username'") or die("couldn,t connect");
    $num mysql_num_rows($query);
            if (
    $row mysql_fetch_assoc($query)){
            if (

    //this( yes yes yes )is for test and i can see it printed when username and password are correct
    echo" yes yes yes ";
    // this is the session and it was and still working in my previous sites i emplemented before but not with this site and it was written the same way you can see 

    // i tried it also this way but it did not work 

    }else {echo 
    " <font color='red'><b>Sorry wrong password   </b></font>";}
    }else {echo 
    " <font color='red'><b>this user name is not registered  </b></font>";}
    }else {echo 
    "  <font color='red'><b> you did not enter password </b></font>";}
    }else {echo 
    "  <font color='red'><b> you did not Enter user name </b></font>";}

    that was the code and all i can see when the username and password are correct is this ( yes yes yes ) that i ordered to echo it just for test
    i,m sure this problem is related with php.ini and if there was something wrong with this file ( suppose it was modified by a hacker for example or by any mistake how can i correct it

    i also have anothe problem with session is that when i loging into any of my previous sites with a username and a password and establish a session and see a username printed ( welcome - username !) when i move to another page i don,t see this session although the session is started in this page and all pages that need to start session and this problem happened to the last website i had

    waiting for your replies
    Thank you
    Last edited by NogDog; 04-15-2014 at 02:10 PM. Reason: changed [color] tags to [php] tags

  2. #2
    Join Date
    Aug 2004
    Do you have a session_start() somewhere before (a) you reference $_SESSION in any way and (b) generate any output (which sends HTTP headers)?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Feb 2014
    First time I've seen that syntax but why are you placing a @ before $_POST and $_SESSION variables?

    Assuming the session variables contain information and are not null, then you probably are missing a session_start() at the top of your page.

  4. #4
    Join Date
    Aug 2004
    "@" suppresses many warnings/notices. IMO, it's a lazy way to avoid doing a little defensive coding, while making it more difficult to debug.

    You can save yourself maintenance grief with:
    PHP Code:
    $username null;
    $_SESSION['username'])) {
    $username $_SESSION;

    That's probably the easiest to read/maintain, but if you just abhor typing multiple lines in spite of it being easy to quickly read and debug, then there's always the ternary operator:
    PHP Code:
    $username = isset($_SESSION['username']) ? $_SESSION['username'] : null
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  5. #5
    Join Date
    Mar 2012
    when i see the web site from my local host ( from laptop ) it goes ok but when i see it from cpanel ( online ) i see this message

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ansaferc/public_html/index.php:3) in /home/ansaferc/public_html/header1.php on line 4

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ansaferc/public_html/index.php:3) in /home/ansaferc/public_html/header1.php on line 4

  6. #6
    Join Date
    Apr 2014
    You seem to have some white space (spaces, tabs, line breaks, ...) at the beginning of the file.
    Please delete all the characters before <?PHP and add ob_start(); before session_start(); to be safe.
    If you use UTF-8, be sure to save the file without BOM.

  7. #7
    Join Date
    Mar 2012
    as i said b4 when i run this website from pc (local host ) it is ok and i can see the session in all pages
    but when i run it online (www.the domain name.com ) i see the session only in the main page when i sign in then if i move to any other page i get these message i mentioned the web pages are uploaded into the public_html and i uploaded some pages at the (/home/ ) could this be the reason ?
    this is my first time i upload web page using cpanel and there may be something wrong i did dand i don,t know i,m not an expert with cpanel

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10340 seconds
  • Memory Usage 2,930KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates