SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Intergrating scripts

    I have got 2 different php scripts running on the same database and tables but im trying to have it when im logged into 1 script im logged into the other script aswell, does anyone know how to do that?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    take a look at your scripts.
    see what variables and conditions satisfy the "logged in" status of each script. your job is to satisfy those conditons.

    maybe they both use sessions, so you can just set a few session variables.

  3. #3
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You somehow need to run the code from another script which logs in user. You will probably need to modify both codes to do that. For example:
    Log in use in one script
    Redirect to another passing variables which are needed for logging in and passing one more variable which will indicate that you have came from first script
    Login user in another script
    Redirect user to first one if he came from there.
    Hope this makes sense
    -- Jelena --

  4. #4
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    they both are using sessions

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good. that might make it a lot easier.

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If they both use the same session variable(s) to denote login status then that is probably your problem solved.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    they both use sessions and 1 of the scripts i login and it says im not logged on in the other 1 but i logout on that 1 and login to the other one and it says im logged into the other script but im trying to have it the other way around anyoen know what is different in them both?

  8. #8
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry - my psychic abilities to get inside your mind, use your eyes and see your code are somewhat on the wane today.
    Ian Anderson
    www.siteguru.co.uk

  9. #9
    SitePoint Addict Clenard's Avatar
    Join Date
    Sep 2004
    Location
    USA
    Posts
    337
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru
    Sorry - my psychic abilities to get inside your mind, use your eyes and see your code are somewhat on the wane today.
    LOL

    What he's trying to say is: Where's the code? You're not doing anybody any favors by just asking questions... let us see some code and we can help you

  10. #10
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the login html code that is the 1 i want to be intergrated with both scripts:
    PHP Code:
    <?
    include "theme.php";
    $username $_POST['username'];
    ?>
    <html>
    <body>
    <b>Login</b>
    <form name="authenticate" method="post" action="loginpro.php">

    Username:  <input name="username" type="text" value="" size="20"/><br>

    Password:  <input name="password" type="password" value="" size="20"/><br>

    Remember me?</b></td><td><input type='checkbox' name='remember'><br>

    <input type="submit" name="submit" value="Login"/>

    <input type="reset" name="reset" value="Reset"/>

    </form>
    </body>
    </html>
    This is the login process code:
    PHP Code:
    <?php
    session_start
    ();
    include 
    "theme.php";
    include 
    "db_connect.php";
    $date date("D d M Y");
    $ip $_SERVER['REMOTE_ADDR'];
    if (isset(
    $_POST['submit'])) // name of submit button
    {
        
    $username=$_POST['username'];
        
    $password=$_POST['password'];
        
    $password=($password);
        
    $query "select * from b_users where username='$username' and password='$password'"
        
    $result mysql_query($query) or die("Could not query") ;
        
    $result2=mysql_fetch_array($result);
        if(
    $result2)
        {         
          
    $_SESSION['user']=$username;
          if(
    $_POST['remember'])
          {
            
    $memberid=$result2[userID];
            
    $passkey=$result2[password];
            include 
    "admin/var.php";
            
    $cookie1="[0]";
            
    $cookie2="[1]";
            
    $cookie3="$cookiename$cookie1";
            
    $cookie4="$cookiename$cookie2";
            
    setcookie("$cookie3","$memberid",time()+7776000) ;
            
    setcookie("$cookie4","$passkey",time()+7776000) ;
          }      
          print 
    "You have successfully logged in, redirecting you to your control panel.";
          print 
    "<META HTTP-EQUIV = 'Refresh' Content = '0; URL =cpanel.php'>";
        }
        else
        { 
          print 
    "Invalid username or password";?><br>
    <a href="login.php">Try again</a> <a href="forgotpass.php">Forgot password</a>
    <?
        
    }
    }
    include 
    "dcheck.php";

    ?>
    This is the script code that works with both scripts but i want the one i posted above to work the same:
    PHP Code:
    <?php
        defined
    ("INCLUDED") or die("Direct access not allowed.");
        
        
    OpenTable("",false,"770");
                    
        if(isset(
    $_POST['submit'])) {
            
    $submit $_POST['submit'];
        }
        if(!isset(
    $submit)) {
            echo 
    "<form action=\"?page=login\" method=\"POST\">";
            echo 
    "<div align=\"center\">\n";
            echo 
    "  <table border=\"0\" align=\"center\" width=\"284\" height=\"65\" cellspacing=\"5\" cellpadding=\"0\">\n";
            echo 
    "    <tr>\n";
            echo 
    "      <td width=\"163\" height=\"11\">Username</font></td>\n";
            echo 
    "      <td width=\"191\" height=\"11\">\n";
            echo 
    "        <p align=\"right\"><input type=\"text\" name=\"user\" size=\"27\"></td>\n";
            echo 
    "    </tr>\n";
            echo 
    "    <tr>\n";
            echo 
    "      <td width=\"163\" height=\"15\">Password:</font></td>\n";
            echo 
    "      <td width=\"191\" height=\"15\">\n";
            echo 
    "        <p align=\"right\"><input type=\"password\" name=\"pass\" size=\"27\"></td>\n";
            echo 
    "    </tr>\n";
            echo 
    "    <tr>\n";
            echo 
    "      <td width=\"306\" height=\"15\" colspan=\"2\">\n";
            echo 
    "       <p align=\"right\"><input type=\"submit\" value=\"Login\" name=\"submit\"></form></td>\n";
            echo 
    "    </tr>\n";
            echo 
    "  </table>\n";
            echo 
    "</div>\n";
        } elseif(
    $submit == "Login") {
            if(
    $_POST['user'] != "" && $_POST['pass'] != "") {
                
    $pass md5($_POST['pass']);
                
    $result mysql_query("SELECT * FROM ".$GLOBALS['mysql_prefix']."_user WHERE user = '".$_POST['user']."'");
                if (!
    $result) {
                    die(
    'Invalid query: ' mysql_error());
                }
                
    $row mysql_fetch_array($resultMYSQL_NUM);
                if(
    $row[1] == $pass) {
                
                    
    $_SESSION['admin'] = $row[2];
                    
    $_SESSION['log'] = "1";
                    
    $_SESSION['user'] = $row[0];
                    
    $_SESSION['pass'] = md5($_POST['pass']);
                    
                    
    $result mysql_query("UPDATE ".$GLOBALS['mysql_prefix']."_user SET loginip = '".$_SERVER['REMOTE_ADDR']."' WHERE user = '".$_POST['user']."'");
                    
                    echo 
    "<center>You have successfully logged in<br><br>\n";
                    echo 
    "You will shortly be redirected. If you do not wish to wait, <a href=\"?page=main\">click here</a>.\n";
                    echo 
    "<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=?page=main\">";
                } else {
                    
    $_SESSION['log'] = "0";
                    echo 
    "<center><strong>Invalid Password</strong>";
                    echo 
    "<br><br><a href=\"?page=login\">Go Back</a>\n";
                }
            }
        }
        
    CloseTable();
    ?>

  11. #11
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  12. #12
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The fundamental process you should employ is ...
    Code:
    session_start();
    Check if login session exists
        Yes - redirect to logged in page/show logged in data
        No - redirect to login page/show login form
    This could generically be like ...
    PHP Code:
    session_start();
    if ( 
    $_SESSION['LoggedIn'] == 'YES' && isset ($_SESSION['UserName']) ) {
        
    // show info
    } else {
        
    // show login form

    Ian Anderson
    www.siteguru.co.uk

  13. #13
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks i worked it out


Bookmarks

Posting Permissions

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