-1

I have a requirement to access a sessionID variable passed through header. I need to verify the sessionID before process the request. Also please let us know how can i set a sessionID in request header. please help me to find a solution. Your help is much appreciated. Thank you

enter image description here

I have tried

$headers = apache_request_headers();

foreach ($headers as $header => $value) {
    echo "$header: $value <br />\n";
}
Dibish
  • 9,133
  • 22
  • 64
  • 106

2 Answers2

1

Use this code:

foreach (getallheaders() as $name => $value) {
    echo "$name: $value\n";
}

This will give all the information of header.

Here is more tutorial about getallheaders() function.

If you want to get only session id then use the below code:

echo session_id();
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
0

To set a session you can use, session_start();

you can use GET method in 1st page to pass the id in header. session_id($_GET['PHPSESSID']); session_start();

You can extract the session id in another page by using session_id() session_id() returns the session id for the current session else it retuns the empty string, if there is no current session.

    <?php
    $id = session_id();
    if(empty($id)) session_start();
    echo "SID: ".SID."<br>session_id(): ".session_id()."<br>COOKIE: ".$_COOKIE["PHPSESSID"];
    ?>

Hope This helps.

Abhishake Gupta
  • 2,939
  • 1
  • 25
  • 34
  • Thanks for the reply, but my requirement is to pass that session_id via header request and take it in another php page and verify. – Dibish Aug 14 '14 at 09:28
  • you can use GET method in 1st page to pass the id in header. You can extract the session id in another page by using session_id() – Abhishake Gupta Aug 14 '14 at 09:55