2015-11-04 63 views
-2

如果CO已完成,我的站點會發送包含用戶鏈接的電子郵件。如果用戶未登錄,PHP重定向 - Yii2

如果用戶沒有登錄,用戶必須首先進入登錄頁面,並且只有當用戶登錄後,他們纔會被重定向到url。

現在,如果用戶登錄他們直接去的網址,但沒有登錄去登錄頁面,他可以登錄,但他不直接到網址任何人都可以幫助嗎?

此網頁網址一些參數是發送給用戶的鏈接

<?php 
if(isset($_SESSION['ssid']) && $_SESSION['ssid'] == session_id()) 
{ 
     // do you staff, after login confirm 
}   
else { 
    // redirect to loginPage.php 
} 
use yii\helpers\Html; 
use yii\helpers\Url; 
use yii\widgets\ActiveForm; 
use yii\widgets\Pjax; 
use kartik\grid\GridView; 
use backend\models\Item; 
use backend\models\Respond; 
use kartik\time\TimePicker; 
use backend\models\RespondItem; 
use backend\models\RequestItem; 
use backend\models\DistributorHasItemCode; 
?> 
<?php 
$check = null; 
$checknow = null; 
$checkfield = null; 
$today = date('Y-m-d'); 
$date = date("Y-m-d H:i:s", time()); 
$date1 = new DateTime($date); 
$date2 = new DateTime($model->end_date.' '.$model->end_time); 
if(empty($model->end_date)) 
{ 
    $model->end_date = $today; 
} 

if (Yii::$app->user->identity->ref_table =="sales_rep") 
{ 
    $sales_rep = Yii::$app->user->identity->ref_id; 
    $respond = Respond::find()->where(['sales_rep_id'=>$sales_rep,'customer_order_request_id'=>$model->id])->one(); 

    if (!empty($respond) && $respond->status == 'Finalized and customer Notified' || $date1>=$date2) 
    { 
     $check = "disabled='disabled'"; 
    } 

    if ($model->status == 'Finalized and Sales Rep Notified') { 
     $checknow = "disabled='disabled'"; 

    } 

}else { 
    if ($model->status == 'Finalized and Sales Rep Notified') { 
     $check = "disabled='disabled'"; 
    } 
} 
?> 
    <?= Yii::$app->session->getFlash('success') ?> 
    <div class="customer-order-request-form"> 

<?php $form = ActiveForm::begin(['id'=>'cor']); ?> 

<fieldset <?= $check?> > 
<fieldset <?= $checknow?> > 
<div class="row"> 
    <div class="col-lg-4"> 

     <?= $form->field($model, 'code')->textInput(['maxlength' => 10,'readonly'=>TRUE]) ?> 
    </div> 
    <div class="col-lg-2" disabled> 
    <?= $form->field($model, 'end_date')->widget(\yii\jui\DatePicker::classname(), [ 
      'dateFormat' => 'yyyy-MM-dd', 
      'clientOptions'=> ['defaultDate'=>$today,'minDate' =>$today,], 
      'options'=>[ 
       'class'=> 'form-control', 

      ], 
      ]) 
    ?> 
    </div> 
    <div class="col-lg-2"> 
     <?= $form->field($model, 'end_time')->widget(TimePicker::classname(), [ 
      'pluginOptions' => 
      [ 
       'showMeridian' => true, 
      ], 

      ]); 
     ?> 
    </div> 

    <div class="col-lg-4"> 
     <?= $form->field($model, 'status')->textInput(['readonly'=>TRUE]) ?> 

    </div> 
</div> 
<div class="row"> 
    <div class="col-lg-12"> 
     <?= $form->field($model, 'description')->textarea(['rows'=>3]);?> 
    </div> 
</div> 
</fieldset> 
<div class="form-group"> 
    <?= Html::submitButton((Yii::$app->user->identity->ref_table =="sales_rep")?'Save':'Update', ['class' =>'btn btn-success']) ?> 
    <?= Html::button((Yii::$app->user->identity->ref_table =="sales_rep")?'Finalize & Notify Customer':'Finalize & Notify Sales Reps', ['class' => 'btn btn-primary finalize']) ?> 
</div> 

</fieldset> 
<?php ActiveForm::end(); ?> 

+4

燦你與我們分享你的代碼?你試過什麼了 ? – Nirnae

+0

我將添加網址目標代碼。你需要什麼想法對接問題? – learnwhat

+1

https://stackoverflow.com/questions/33514216/how-to-redirect-user-to-particular-link-after-login-in-php/33514268#33514268 https://stackoverflow.com/questions/768431/如何使一個重定向在PHP – Jameson

回答

0

應該使用會議處理登錄。

假設你的網址是http://somedomain.com/somepage.php?token=some_tokan。 因此,在somepage.php,使用會話檢查登錄確認,如:

<?php 

    ob_start(); 
    session_start(); 

    if(isset($_SESSION['ssid']) && $_SESSION['ssid'] == session_id()) 
    { 
      // do your stuff, after login confirm 
    }   
    else { 
     // redirect to loginPage.php 
     // With "header('Location:yoururl'); for example 
    } 

而且在loginPage.php,成功登錄憑據後,分配$_SESSION['ssid']值,如:

ob_start(); 
    session_start(); 
    // if login credentials are verified. 
    $_SESSION['ssid'] = session_id(); 
相關問題