How can you check if a PHP session exists?

前端 未结 11 1332
孤独总比滥情好
孤独总比滥情好 2021-02-04 06:11

Just wondering how to check if a PHP session exists... My understanding is that no matter what, if I am using sessions, I have to start my files with session_start() to even acc

11条回答
  •  一整个雨季
    2021-02-04 06:41

    I solved this three years ago, but I inadvertently erased the file from my computer.

    it went like this. 3 pages that the user had to visit in the order I wanted.

    1) top of each php page enter code heresession start();enter code here 2) first page: a) enter code here$_session["timepage1"] = a php date function; time() simple to use b) enter code here$_session["timepage2"]= $_session["timepage1"]; b) enter code here$_session["timepage3"]=$_session["timepage1"]; 3) second page: a) enter code here$_session["timepage2"] = a php date function; time() simple to use b) enter code here$_session["timepage3"]= $_session["timepage3"]; 3) third page: a) enter code here$_session["timepage3"] = a php date function; time() simple to use

    the logic: if timepage3 less than timepage3 on page 2 {the user has gone to page 3 before page 2 do something}

    if timepage2 on page 2 less than timepage1 {the user may be trying to hack page two we want them on page 1 do something}

    timepage1 should never equal timepage2 or timepage3 on any page except page1 because if it is not greater on pages two or three the user may be trying to hack "do something"

    you can do complex things with simple arithmetic with the 3 timepage1-2-3 variables. you can either redirect or send a message to say please go to page 2. you can also tell if user skipped page 2. then send back to page 2 or page one, but best security feature is say nothing just redirect back to page1.

    if you enter code hereecho time(); on every page, during testing, you will see the last 3 digits going up if you visit in the correct order.

提交回复
热议问题