Closed Thread
Results 1 to 3 of 3

Thread: PHP session and redirected domain

  1. #1
    Member Stary is an unknown quantity at this point
    Join Date
    Feb 2002
    Posts
    30

    PHP session and redirected domain

    I tried my login script using a session variables to allow some php pages to proceed or jump back to a login procedure if a session variable is not set correctly. It works fine on a host like "www.myhostprovider.com/mysubdirecory". So I redirect my domain like "www.mydomain.com" to that host and users are not bothered with unfriendly domain name at the address line of the browser.

    Unfortunatelly the session variables doesn't exist when a new php starts. It's strange that it works when I type directly the original url in the address line.

    Any ideas?

  2. #2
    Junior Member darkink is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    4
    must see your script then know

  3. #3
    Member Stary is an unknown quantity at this point
    Join Date
    Feb 2002
    Posts
    30
    Quote Originally Posted by darkink
    must see your script then know
    Ok, there are 3 scripts :


    Code:
    login.php
    <?php 
    session_start();
    header("Cache-control: private"); //IE 6 Fix
    ?> 
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <HTML>
    <HEAD>
    <TITLE>Login</TITLE>
    
    </HEAD>
    
    <BODY >
    
    
    <form method="POST" action="login_check.php">
    		
      <table width="100%">
        <tr> 
          <td width="20%"> </td>
          <td width="60%" align="center" > <BR>
            <BR>
            <BR> <table border="0" width="350">
              <tr> 
                <td bgcolor="#000080"> <p align="center"><font color="#FFFFFF" face="Arial" size="5">Login 
                    </font></td>
              </tr>
              <tr> 
                <td bgcolor="#E5E5E5"> <TABLE>
                    <TR> 
                      <TD valign="middle"> <TABLE>
                          <TR> 
                            <TD><FONT FACE="Arial" COLOR="#000080">Username:</FONT></td>
                            <td><INPUT TYPE="text" NAME="username"></TD>
                          </TR>
                          <TR> 
                            <TD><FONT FACE="Arial" COLOR="#000080">Password:</FONT></td>
                            <td><INPUT TYPE="password" NAME="password"></TD>
                          </TR>
                          <TR> 
                            <TD align="center"><INPUT TYPE="submit" name="login" VALUE="Login"></TD>
                          </TR>
                        </TABLE></TD>
                    </TR>
                  </TABLE>
                  <CENTER>
                  </CENTER>
                  </td>
              </tr>
            </table></td>
          <td width="20%"> </td>
        </tr>
      </table>
    </form>
    </BODY>
    </HTML>

    Code:
    login_check.php
    <?
    session_start();
    header("Cache-control: private"); //IE 6 Fix
    
    
    $login_username = "admin";							//Login Username
    $login_password = "admin";							//Login Password
    
    
    if($login){
    	
            if ($login_username == $username && $login_password == $password){
                    $login_ok = "yes";
    	}
    
    }
    
    if(!$login_ok){ 
            $session_login="";
            header("Location: login.php");
    	exit;
    }
    
    
    $session_login="login";
    
    session_register('session_login');
    session_write_close();
    
    header("Location: mypage.php");
    ?>

    Code:
    mypage.php
    <?
    session_start();
    header("Cache-control: private"); //IE 6 Fix
    session_register("session_login");
    if($session_login == "login"){}
       else{
            header ("Location: login.php'");
            exit;
          }
    echo "This is my page - login successfull!";
    ?>

    If you try running login.php on some original domain, there wouldn't be any problem, but if you try them as a redirected domain, it won't work.


    Thank's.

Closed Thread

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