2017-02-09 2 views
0

I Zufallszahl im post_ads() Verfahren erzeugen dann speichern Sie es in $_SESSION['temp_id'], nur einfach die post_as_offline() Methode aufrufen redirect('ads/post_as_offline', 'refresh') verwenden, die $_SESSION['temp_id'] geändert und durch neue Zufallszahl ersetzt. Warum nach der Umleitung, rand() aufgerufen und neu generieren und neuen Wert speichern?

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
    class ads extends CI_Controller { 
    private $Data; 
    public function post_ads() 
    { 
    $this->common_data(); 
    $rand = rand(); 
    $_SESSION['temp_id'] = $rand ; // example $_SESSION['temp_id'] = 1000 ; 
    if(iSset($_POST['add'])) 
     { 
     // some code 
     redirect('ads/post_as_offline' , 'refresh'); 
     } 
     else 
     { 
     $this->load->view('add_ads_step2' , $this->Data); 
     } 

    } 
    public function post_as_offline() 
    { 
     $this->common_data(); 
     // will be $_SESSION['temp_id'] = 52635 ; rand() regenerat value after redirect 
     $this->load->view('post_as_offline_step',$this->Data); 
    } 

    } 

Antwort

1

Möglicherweise wird Ihre Sitzung nach der Aktion geändert. versuchen Sie dies:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
    class ads extends CI_Controller { 
    private $Data; 
    public function post_ads() 
    { 
    $this->common_data(); 
     if(iSset($_POST['add'])) 
     { 
     // some code 
     redirect('ads/post_as_offline' , 'refresh'); 
     } 
     else 
     { 
     $rand = rand(); 
     $_SESSION['temp_id'] = $rand ; // example $_SESSION['temp_id'] = 1000 ; 

     $this->load->view('add_ads_step2' , $this->Data); 
     } 

    } 
    public function post_as_offline() 
    { 
     $this->common_data(); 
     // will be $_SESSION['temp_id'] = 52635 ; rand() regenerat value after redirect 
     $this->load->view('post_as_offline_step',$this->Data); 
    } 

    } 
0

Als ich vor und nach der Umleitung zufällig geprüft sind gleiche .Sie leicht, indem sie in URL überprüfen, den Sitzungswert .Ich Ihren Code auf meiner Testseite von nur nur das Entfernen gemeinsame Daten Methode geprüft. Bitte überprüfen Sie, ob Sie etwas in Ihrer geposteten Frage verpasst haben. Beispiel: -

private $Data; 
public function post_ads() 
    { 
     $rand = rand(); 
     $_SESSION['temp_id'] = $rand ; // example $_SESSION['temp_id'] = 1000 ; 
     if(isset($_SESSION)) 
     { 
      redirect('test/post_as_offline?code='.$_SESSION['temp_id'] , 'refresh'); 
     } 
     else 
     { 
      $this->load->view('add_ads_step2' , $this->Data); 
     } 

    } 
    public function post_as_offline() 
    { 
     print_r($_SESSION);die; 
     $this->load->view('post_as_offline_step',$this->Data); 
    }