久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在重定向系統(tǒng)中混淆此 cookie

confusing about this cookies in redirecting system(在重定向系統(tǒng)中混淆此 cookie)
本文介紹了在重定向系統(tǒng)中混淆此 cookie的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 PHP 工作.我想在登錄后將頁面重定向到我想訪問的最后一個頁面,但 5 小時后我仍然在這里堆棧,但我仍然沒有成功.這是架構(gòu),我有 3 個 php 文件.

I work in PHP. I want to redirect page after login to the last page that i want to visit, but I'm still stack at here in 5 hours and I still don't make it yet. This is the schema, I have 3 php file.

newest.php (before login), 
signin.php (before login), 
thread.php (after login). 

我正在使用 cookie 進行此重定向.首先我去了newest.php,然后我點擊了按鈕(去thread.php).然后thread.php看到你還沒有登錄,然后重定向到signin.php.在我填寫登錄表單后,我點擊了提交按鈕(signin.php),然后我在 signin.php 堆棧(不去任何地方)即使我已經(jīng)登錄,它應(yīng)該去 thread.php自動.

I'm using cookies for this redirecting. First i went to the newest.php, then i clicked the button (go to thread.php). Then thread.php saw that you haven't loggin yet, then redirected to signin.php. After i fill the signin form then, i clicked the submit button (the signin.php), then I'm stack at signin.php (not going anywhere) even after I've loggin in, it should be go to thread.php automatically.

這是我在 newest.php 中的代碼 &thread.php(不在 signin.php 中):

this is my code in newest.php & thread.php (not in signin.php):

$coopage='coopage';
$current_page='http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
setcookie($coopage, $current_page,time()+86400,'/');

newest.php 中的提交按鈕(它轉(zhuǎn)到 thread.php):

submit button in newest.php (it goes to thread.php):

echo "<center><button onclick="window.location='/thread/form'">add new thread</button></center>"; 

在 signin.php 中(在我點擊提交按鈕或在提交區(qū)域后,因為表單和提交后我在同一頁面中)(在頁面底部):

in signin.php (after i clicked the submit button or in submit area, because form and after submit i made in the same page) (in the bottom of the page):

if(isset($_COOKIE[$coopage])){
    $url=$_COOKIE[$coopage];
    unset($_COOKIE[$coopage]);
    header('location:'.$url);
}

注意:在 signin.php 中,我在這個 cookie 之前還有另一個 cookie 設(shè)置,這是造成這個的原因嗎?或者我在一頁中設(shè)置了 2 個 cookie 有關(guān)系嗎?另一個cookie設(shè)置是這樣的(在頁面頂部)

note: in signin.php i also have another cookie setup before this cookie, is that the cause of this? or does it matter if i have 2 cookies setup in one page? Another cookie setup is like this (at the top of the page)

$cooval2='juna';
setcookie($coousername, $cooval2, time() + (3600 * 24 * 365), "/"); // 1 year

推薦答案

我根本不會使用 cookie.

I would not use cookies at all.

方法一

一種可能的方法是將訪問的鏈接存儲到會話變量中,然后當用戶到達 login.php 頁面時,提供一個重定向到會話變量給定的 $url 的標頭.

A possible way could be to store the link visited into a session variable and then when the user reaches the login.php page, provide a header redirect to $url given by the session variable.

將此代碼粘貼到您網(wǎng)站或主容器上的所有頁面中.

Paste this code into all your pages on your website or the main container.

<?php
session_start(); 
$_SESSION['url'] = $_SERVER['REQUEST_URI']; 

對于登錄頁面,您可以:

For the login page you can have:

<?php
session_start();  // needed for sessions.
if(isset($_SESSION['url'])) 
   $url = $_SESSION['url']; // holds url for last page visited.
else 
   $url = "student_account.php"; 

header("Location: http://example.com/$url"); 

方法二

到目前為止,一個更簡單的解決方案就是擁有:

A simpler solution by far is simply to have:

<hidden name="redirurl" value="<? echo $_SERVER['HTTP_REFERER']; ?>" />

然后在他們登錄后重定向到該地址.

Then redirect to that address once they log in.

但是,這只有在每個頁面上都有一個登錄框時才有用.

However, this is only good if you have a login box on every page.

$_SERVER['REQUEST_URI'] 只會保存當前頁面.你想要做的是使用 $_SERVER['HTTP_REFERER'].因此,將 HTTP_REFERER 保存在表單的隱藏元素中,但還要注意,在處理表單的 PHP 中,如果登錄失敗,您將需要一些邏輯來重定向回登錄頁面,但還要檢查引用者是否實際上是您的網(wǎng)站,如果不是,則重定向回主頁.

$_SERVER['REQUEST_URI'] will simply hold the current page. What you want to do is use $_SERVER['HTTP_REFERER']. So save the HTTP_REFERER in a hidden element on your form, but also take note on that in the PHP that processes the form you will need some logic that redirects back to the login page if login fails but also to check that the referer is actually your website, if it isn't, then redirect back to the homepage.

方法三

另一種常見的方法是通過 $_GET 變量將用戶的當前頁面?zhèn)鬟f到登錄表單.

Another common way to do this is to pass the user's current page to the Login form via a $_GET variable.

更改您的腳本,以便讓登錄頁面記住您的位置:

change your script so that is also tells the login page to remember where you are:

注意:$_SERVER['REQUEST_URI'] 是您當前的頁面

Note: $_SERVER['REQUEST_URI'] is your current page

header("Location:login.php?location=" . urlencode($_SERVER['REQUEST_URI']));

現(xiàn)在檢查它是否已填充,然后將用戶發(fā)送到:登錄.php

Now check if it is populated, then send the user to this: login.php

echo '<input type="hidden" name="location" value="';
if(isset($_GET['location'])) {
    echo htmlspecialchars($_GET['location']);
}
echo '" />';
//  Will show something like this:
//  <input type="hidden" name="location" value="previousPage.php" />

登錄檢查.php

session_start();

//  our url is now stored as $_POST['location'] (posted from login.php). If it's blank, let's ignore it. Otherwise, let's do something with it.
$redirect = NULL;
if($_POST['location'] != '') {
    $redirect = $_POST['location'];
}

if((empty($username) OR empty($password) AND !isset($_SESSION['id_login']))) {
    $url = 'login.php?p=1';
    // if we have a redirect URL, pass it back to login.php so we don't forget it
    if(isset($redirect)) {
        $url .= '&location=' . urlencode($redirect);
    }
   header("Location: " . $url);
   exit();
}
elseif (!user_exists($username,$password) AND !isset($_SESSION['id_login'])) {
    $url = 'login.php?p=2';
    if(isset($redirect)) {
        $url .= '&location=' . urlencode($redirect);
    }
   header("Location:" . $url);
   exit();
}
elseif(isset($_SESSION['id_login'])) {
    // if login is successful and there is a redirect address, send the user directly there
    if($redirect)) {
        header("Location:". $redirect);
    } else {
        header("Location:login.php?p=3");
    }
    exit();
}

這篇關(guān)于在重定向系統(tǒng)中混淆此 cookie的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 精品产国自在拍 | 欧美日韩一区在线 | 中文字幕视频在线 | 午夜电影网 | 国产综合久久 | 欧美一级毛片在线播放 | 国偷自产av一区二区三区 | 亚洲精品麻豆 | 一区二区免费视频 | 亚洲九九色 | 中文字幕91 | 毛片区 | 免费能直接在线观看黄的视频 | 一级网站 | 成人水多啪啪片 | 91久久精品国产91久久 | 91日韩| 久久伊 | 97超碰中文网 | 黄色在线播放视频 | 怡红院成人在线视频 | 国产真实精品久久二三区 | 午夜在线免费观看 | 精品乱码一区二区三四区 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | av在线成人| 国产女人第一次做爰毛片 | 国产高清久久久 | 亚洲在线电影 | 波多野结衣先锋影音 | 国产一区二区三区在线看 | 精品一区二区三区免费视频 | 超级黄色一级片 | 综合久久综合久久 | 麻豆久久久久久久久久 | 国产亚洲精品美女久久久久久久久久 | 一道本不卡视频 | 伊人热久久 | 国产精品1区 | 交专区videossex农村 | 国产一级一级毛片 |