2012-01-11 12 views
1

私が働いているウェブサイトでは、セッション変数を登録するために2回ログインする必要があります。私はあなたがヘッダーのリダイレクトを行うときに起こったと読んだ。あなたが設定または任意のセッション変数にPHPログインコードはリダイレクトのため2回ログインする必要があります

+0

ここで、session_start()は何ですか? – j08691

+0

私のクラスファイルをインクルードしてloginメソッドを実行する前に、セッション開始が私のファイルにありますか、それとも私のクラスファイルにインクルードする必要がありますか? – Yamiko

答えて

2
ALWAYS

session_start()は、すべてのクライアントにいくつかのJavaScriptを送信することです!

www.yamikowebs.comのDNSエントリをテストします。テストのためにクライアント上でIPを解決していることを確認してください!

+0

クラスをインクルードしてメソッドを実行する前に、私のファイルでセッション開始を使用します。クラスファイルにもそれを持たせる必要がありますか? – Yamiko

+0

あなたはそれを必要とします –

0

一つの解を得る前に

function login() 
{ 
    // secure data 
    $email  = mysql_real_escape_string(htmlentities($_POST['email'])); 
    $password = md5(mysql_real_escape_string(htmlentities($_POST['password']))); 
    // sql statment 
    $tbl=$this->tbl; 
    $sql="SELECT id, admin, email FROM $tbl WHERE email='$email' AND password='$password'"; 
    $result=$this->query($sql, true); 
    // check if user exist 
    $numRow=mysql_num_rows($result); 
    if($numRow==1) 
    { 
     // login 
     while($row = mysql_fetch_array($result)) 
     { 
      $_SESSION['id']=$row['id']; 
      $_SESSION['admin']=$row['admin']; 
     } 
     // problematic redirect. http redirect erases session data? 
     header('Location: http://www.website.com/'); 
     return true; 
    } 
    $this->error="logint"; 
    return false; 
} 
0

リダイレクトが別のドメインにあるとします。

制約は、データを別のドメインに保持することです。

あなたのデータベースに情報を蓄積するには、文字列としてのこの転送専用のチケットを作成し、それに関数md5()を使用します。たとえば、長い文字列の中間の位置にある日付のincludeを使用します。セキュリティのために1分の遅れでデータベースに保管してください。

ヘッダ

$tt= new DateTime(); 
$tt->format('Y-m-d/H:i:s'); 
$astring = "On a website I am working on you have to login in twice for the session variables to register. from the suggested questions I have read it is caused when you do a header redirect. possible php solutions(if none I can echo a javascript redirect"; 
$arandom = rand(0, (strlen($astring) - 19)); 
$astring = substr_replace($astring,$tt->format('Y-m-d/H:i:s'),$arandom,19); 
$code = md5($astring).crc32($astring); 

// use $code to remember all information of your client in the database et reuse on demand of script associated with client0002 
echo "<script language=\"javascript\"> 
    window.location.assign('http://www.yamikowebs.com/test/client0002?acces=$code')</script>"; 

を置き換えるために、これを含めるには良い一日を。

関連する問題