0

This is My PHP Code:

<?php

if (session_id() == '') {
    session_start();
}

echo session_id();

?>

When I request this code with the browser, the code works properly and there is no problem.

Code result in browser:
First time result:
// 6511A321213321DF151016C
Second time result:
// 6511A321213321DF151016C

But when I request it using Python, the IDs are different. This is my python Code:

from requests import *

for i in range(5):
    Get_Request = get('http://example.com/test.php')
    Page_Content = Get_Request.text
    print(Page_Content)

But the result in Python

Code result in python:
First time result:
// F695A321213321DF151AS65
Second time result:
// AB653132121D65A66265456
  • 1
    It looks like you are making a new request 5 times, and for each new request you're calling the page.....each new request would generate a new session id. I think you're meaning to use the [Sessions()](https://requests.readthedocs.io/en/master/user/advanced/) functionality of the request module. – Xinthral Mar 06 '21 at 19:05
  • 2
    The session id is stored in cookies. You should store the cookie sent by the server and sent it for the next requests. – Syscall Mar 06 '21 at 19:14
  • Does this answer your question? [What are cookies and sessions, and how do they relate to each other?](https://stackoverflow.com/questions/11142882/what-are-cookies-and-sessions-and-how-do-they-relate-to-each-other) – ArSeN Mar 06 '21 at 19:24
  • Can I use another method? Can I detect Python with php session? – Mahdi Khezrabadi Mar 07 '21 at 07:50

0 Answers0