session start

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    session start

    i am writing my own script but my only problem is getting the session started as in sid=bla bla bla

    how do i do it and if u dont do anything it logs you out is it a for loop or something

    #2
    PHP Code:
    session_start(); 
    PHP Code:
    if(isset($_SESSION['sid']))
    {
    echo 
    "Your logined in!";
    }else{
    echo 
    " your not logined in !";

    PHP Code:
    $_SESSION['id']=session_id();
    $_SESSION['sid']=$sid
    Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
    Visit: WapMasterz Coming Back Soon!
    _______
    SCRIPTS FOR SALE BY SUBZERO
    Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
    FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
    _______
    Info & Tips
    php.net
    w3schools.com

    Comment


      #3
      i keep getting your logged out , do i need to define something else
      this is how i have it what am i doing wrong please someone assist me .


      <?php
      session_start(); // session start
      ?>
      <?php
      include("conf.php"); // database setup info
      $con = mysql_connect("$dbhost","$dbuser","$dbpass");
      if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
      $_SESSION['id']=session_id();
      $_SESSION['sid']=$sid;
      if(!isset($_SESSION['sid']))
      {
      echo "Your not logged in !";
      exit();
      }
      mysql_select_db("$dbname", $con);
      $usn = $_GET[usn];
      $uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM link_users WHERE username='".$usn."'"));
      if($uinf[0]==0)
      {
      echo "<br/><img src=\"images/notok.gif\" alt=\"X\"/>UserName doesn't exist<br/><br/>";
      exit();
      }
      else{
      $sid = md5($sid);
      $usn = $_GET[usn];
      echo "Logged in successfully as $usn<br/><br/>";
      echo "<a href="inc.php?ac=main&sid=$sid">Enter</a><br/>";
      }
      ?>

      Comment


        #4
        ive already hide my own session id using $sid = $_SESSION['sid']. but my problem is how to redirect users to main page if their session still not expired?

        Comment


          #5
          it keeps saying am noy logged in , bro remeber this is not the lavalair script am writing my own things like get_userid is not apart of my script thats why i am asking all the functions i need to define to get it working .

          Comment


            #6
            so ummm if i do this


            session_start();

            if(isset($_SESSION['username']))

            {

            echo "Welcome " . $_SESSION['username'];


            //some codes here



            }else{

            echo "oops sorry your session has expire or is invalid";
            }

            What must i do to keep the user session if the user clicks a link on where it says welcome username how to make that session stay ? should i put session_start(); on all the pages?

            Comment


              #7
              the page you are showing looks like a login page to me so it would be something like this:
              PHP Code:
              <?php
              session_start
              (); // session start

              include("conf.php"); // database setup info
              $con mysql_connect("$dbhost","$dbuser","$dbpass");
              if (!
              $con)
              {
              die(
              'Could not connect: ' mysql_error());
              }

              mysql_select_db("$dbname"$con);
              $usn $_GET[usn];
              $uinf mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM link_users WHERE username='".$usn."'"));
              if(
              $uinf[0]==0)
              {
              echo 
              "<br/><img src=\"images/notok.gif\" alt=\"X\"/>UserName doesn't exist<br/><br/>"
              }else{
              $sid time() +26565*4;
              $_SESSION['sid'] = md5($sid); 
              echo 
              "Logged in successfully as $usn<br/><br/>";
              echo 
              "<a href=\"inc.php?ac=main\">Enter</a><br/>";
              }
              ?>

              Comment


                #8
                Originally posted by abipol View Post
                ive already hide my own session id using $sid = $_SESSION['sid']. but my problem is how to redirect users to main page if their session still not expired?
                few ways you can do it... delete the session in the database or
                set the session to a false session ef:
                PHP Code:
                 $_SESSION['sid'] = ""
                or unest the session:
                PHP Code:
                session_unset();
                session_destroy(); 

                Comment


                  #9
                  its not a loggin page its the main page i am wondering it is complete/ correct am using $_SESSION and i want it to say your session has expire if a user tries to enter the site without registering or loggining and also if the user session expires for real

                  Comment


                    #10
                    Originally posted by wap_king View Post
                    its not a loggin page its the main page i am wondering it is complete/ correct am using $_SESSION and i want it to say your session has expire if a user tries to enter the site without registering or loggining and also if the user session expires for real
                    ooooooh 2 nicks lol

                    you would have to check the SESSION against the session in the database. You havent given enough details like sql for it to be coded

                    An example of session checking with made up database fields:
                    PHP Code:
                    $check mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sessions WHERE sesionid='".$_SESSION['sid']."'"));

                    if(
                    $check[0]<1){
                    echo 
                    "u are nit logged in";
                    exit();

                    Last edited by something else; 29.05.10, 18:05.

                    Comment


                      #11
                      am not using sid am using $_SESSION

                      Comment


                        #12
                        i didnt use a $_GET variable i used a $_SESSION varible in my last post :P

                        the sid is just a string which i use for an example it could be anything like:

                        $_SESSION['thebigredshineygoldfish'];

                        as long as you check the variable is matching against some data eg database then you can confirm that your logged in

                        if you just use if(isset($_SESSION['sid'])) then as long as $_SESSION['sid'] has a variable in it ... it is TRUE

                        in other words i put any number in the $_SESSION I would be instantly be logged in even if im not a member of your site.

                        sorry this post might sound a little confusing lol.

                        Comment


                          #13
                          Yeah it is lol

                          Comment


                            #14
                            Originally posted by something else View Post
                            few ways you can do it... delete the session in the database or
                            set the session to a false session ef:
                            PHP Code:
                             $_SESSION['sid'] = ""
                            or unest the session:
                            PHP Code:
                            session_unset();
                            session_destroy(); 
                            thank you. but i created function LoginPage();
                            here are some of the code.
                            PHP Code:
                            if(empty($_SESSION['sid']) OR (!isset($_SESSION['sid']))){
                            echo 
                            LoginPage();
                            exit();

                            if users session still active or not expired user can access the requested page, but if users session already expired the login page will be display.
                            Last edited by abipol; 30.05.10, 15:02.

                            Comment


                              #15
                              Originally posted by abipol View Post
                              thank you. but i created function LoginPage();
                              here are some of the code.
                              PHP Code:
                              if(empty($_SESSION['sid']) OR (!isset($_SESSION['sid']))){
                              echo 
                              LoginPage();
                              exit();

                              Its not hard for me to add a session id into my browser myself .... so if i put into my browser sid=(anything) then im instantly logged into your site
                              Thats why checking the session id against a database or some other data source is so important.
                              Rather than just having if(empty($_SESSION['sid']) OR (!isset($_SESSION['sid']))){

                              Comment

                              Working...
                              X