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
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session handling

    How do i add link to an account in mydatabase by sesion ?
    Like this : I have a login form and after user login i'll check if the user is admin or not , if admin then go to admin page by using javascript function window.location = "admin.php???????????????" the ??????????? can be the sesion or not ( i don't know yet ) . But i did try using window.location = <? echo "admin.php".session_id() ?> but no use . I did put the session_start() at the top of my page .
    When i set window.location = "admin.php" it does not know the username of the admin .It just display HTML , that is without any variable i want it to display from the database . How do i solve this ? please help .

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you put

    "admin.php".session_id();

    it probably wont work, as you dont have the ? mark, or the variable.

    Try

    PHP Code:

    <? 
    $SESSID 
    session_id();
    echo 
    "admin.php?sessionid=".$SESSID;
    ?>
    Hope that works for you

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Well before you validate ppl, you'd select which user is admin, so maybe you'd create the $_SESSION['admin']. All you'd have to do is

    PHP Code:
    if($_SESSION['admin']){
      include(
    "adminpage.php");
    }else{
      if(
    $_SESSION['normaluser']){
        include(
    "normaluser.php");
      }else{
        echo 
    "I ain't goin on no plane foo'!";
      }


  • #4
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are u serious ? I am using php with javascript , when i the tag <script>
    i put Var target = <? ----phpcode----?> it return nothing , but when i don't use <?----- ?> it works normally , How can this be solve ?
    i want the page to direct to another page and also using some variable of the first page .
    I am telling this again because i don't understand the var $_session , is there any clearer doc for me , plz tell me where is that document .

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you sure you have short tags enabled. Try using

    <?php

    and then and then your code.

  • #6
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is foe sure that my system has the short tag enabled . I coded in sgort tag all the time and there is no problem until i used it with the javascript as i told above .

  • #7
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It seems like it should work. Can you post the code please.

    If not, you could try getting PHP to echo the script.

  • #8
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I just did this

    I just completed an authentication system, where after a user logins in it assigns an access level and that is used in a switch statement. The switch statement allows me to load what page I want as an include and then exits teh script.
    PHP Code:
    echo "Your Access Level is <strong>"$_SESSION['user_level']."</strong> This allows you the following options: <br /><br />";
        switch(
    $_SESSION['user_level']){
            case 
    "255":
                include 
    '255.php'// Access 255!
                
    mysql_free_result($manufacturer);
                exit();
            case 
    "1":
                include 
    '1.php'//  Access 1!
                
    mysql_free_result($manufacturer);
                exit();
            default:
                include 
    '1.php'//  Access 1!
                
    mysql_free_result($manufacturer);
                exit();
        }
    ?> 

  • #9
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks all men !
    Actually i have another way to solve this now , but this is still something interesting to discuss on . I solved this with the session handles too , but not using the way of sending the session ID to the url , just register the var and use it again .

    If u want my code then i'll post it below , don't care abot the other file i am using , it just a class for display in the HTML , and the words with strange character are the UNICODE words of my language ,Vietnamese .
    PHP Code:
    <?
        session_start
    ();
        require(
    "functions.php");
        require(
    "page.inc");
        
        
    $error1 "";
        
        
    $login = new page("Trang đăng nhập ");
        
        if(
    $submit)
        {
            
    $db=mysql_connect("localhost","admin","password");
            
    mysql_select_db("test",$db);

            
    $result1 mysql_query("SELECT username FROM user WHERE username='$username'");
    #kiem tra ket qua truy van 
            
                            # Gap loi 
            
    if(!$result1)   
            {
                
    $error1 "<font color = red size=4>Query error </font>";
            }
                            
    # THANH CONG 
            
    else 
            {
    #Ton tai user 
                
                
    if (mysql_fetch_row($result1)>0)
                {        
                    
    $result2 mysql_query("SELECT username,password FROM user WHERE username='$username' AND password=password('$password')");
                    
                
    #Kiem tra truy van lan` 2 
                    
    if(!$result2)   
                    {                    
                        
                        
    $error1 $error1."<font color = red size=4>Query error </font>";
                    }
                        
    #THANH CONG 
                    
    else 
                    {
    # SAI  PASSWORD        
                        
    $result2 mysql_query("SELECT username,password FROM user WHERE username='$username' AND password=password('$password')");
                        
                        if(
    mysql_fetch_row($result2)==0)
                        {
                                
                            
    $error1 $error1."<br><font color=red size=4>Sai password </font> ";
                            
                            
    $login->Displayabove_Menu();
                            
    $login->DisplayMenu($this->buttons);
                            
    $login->DisplaybelowMenu();
                            
    $login->content2 $error1."<br><p> Bạn hãy đăng nhập với tên và mật khẩu đã đăng ký trước đó . Nếu chưa đăng ký thì bạn hãy <a href =\"register.php\"><font color=red>Ấn vào đây </font></a>."
                                            
    ."<br><form method=\"post\" action =\"<? echo $PHP_SELF ; ?>\" >"
                                            
    ."<p>"
                                            
    ."Tên truy cập :<input type=text name=username size=20><br>"
                                            
    ."Mật khẩu &nbsp;&nbsp;&nbsp;&nbsp;:<input type=password name=password size=20><br>" 
                                            
    ."<p>"
                                            
    ."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                                            
    ."<input type=submit name=submit value=\"Đăng nhập\" >";
                                
                            
    $login->DiplayContent("Trang đăng nhập ","$this->content2");
                            
    $login->Display_Right();     
                            
                        }
                    
    #username va password DUNG
                        
    else 
                        {
                                
    $valid_user $username;
                                
    session_register("valid_user");
                    
    ?>
                                <form name="redirect">
                                  <center>
                                  <table border="5" bgcolor="#6B9AAD">
                                  <tr>
                                      <td>
                                          <b><font size =6>Tài khoản của bạn đã hợp lệ   </FONT>
                                          <br> Bạn sẽ được đưa đến quản lý của các thành viên  trong vòng </b><input type="text" size="3"  name="redirect2">    giây
                                        <br/><br/>Nếu bạn không muốn đợi thì hãy  <a href="member.php" title="Trang dành cho các thành viên !">ấn vào đây  </a>.
                                    </td>
                                </tr>
                                </TABLE>
                                
                                </center>
                        </form>
        
                        <script>
                        <!--

                        var targetURL="member.php"
                        var countdownfrom=5

                        var currentsecond=document.redirect.redirect2.value=countdownfrom+1
                        function countredirect(){
                            if (currentsecond!=1){
                            currentsecond-=1
                            document.redirect.redirect2.value=currentsecond
                            }
                            else{
                            window.location=targetURL
                            return
                            }
                            setTimeout("countredirect()",1000)
                            }

                            countredirect()
                        //-->
                        </script>
    <?
                        
                        
    }
                    }
                }
                

                else  
    #khong ton tai user 
                
    {
                    
    $error1 $error1."<font color = red size=4>Không tồn tại tài khoản có tên truy cập  là $username</font>";
                    
    $login->Displayabove_Menu();
                    
    $login->DisplayMenu($this->buttons);
                    
    $login->DisplaybelowMenu();
                    
    $login->content2 $error1."<br><p> Bạn hãy đăng nhập với tên và mật khẩu đã đăng ký trước đó . Nếu chưa đăng ký thì bạn hãy <a href =\"register.php\"><font color=red>Ấn vào đây </font></a>."
                                
    ."<br><form method=\"post\" action =\"<? echo $PHP_SELF ; ?>\" >"
                                
    ."<p>"
                                
    ."Tên truy cập :<input type=text name=username size=20><br>"
                                
    ."Mật khẩu &nbsp;&nbsp;&nbsp;&nbsp;:<input type=password name=password size=20><br>" 
                                
    ."<p>"
                                
    ."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                                
    ."<input type=submit name=submit value=\"Đăng nhập\"  >";
                                
                    
    $login->DiplayContent("Trang đăng nhập ","$this->content2");
                    
    $login->Display_Right();     
                    
                }
            }
            
        }
    #CHo hien trang chinh     
        
    else 
        {
            
    $login->Displayabove_Menu();
            
    $login->DisplayMenu($this->buttons);
            
    $login->DisplaybelowMenu();
            
    $login->content2 "<p> Bạn hãy đăng nhập với tên và mật khẩu đã đăng ký trước đó . Nếu chưa đăng ký thì bạn hãy <a href =\"register.php\"><font color=red>Ấn vào đây </font></a>."
                                
    ."<br><form method=\"post\" action =\"<? echo $PHP_SELF ; ?>\" >"
                                
    ."<p>"
                                
    ."Tên truy cập :<input type=text name=username size=20><br>"
                                
    ."Mật khẩu &nbsp;&nbsp;&nbsp;&nbsp;:<input type=password name=password size=20><br>" 
                                
    ."<p>"
                                
    ."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                                
    ."<input type=submit name=submit value=\"Đăng nhập\" >";
                                
            
    $login->DiplayContent("Trang đăng nhập ","$this->content2");
            
    $login->Display_Right();     
            
        }
        
    ?>

    the javascript send the user to member.php , in this file i will check the session registered var and use it later


  •  

    Posting Permissions

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