I have two files:
html
php
where html file is calling the php file to do something.
Now i would like to get the PHP session ID (php code) into both my html file as well as my php file.
I would like to know how would I do so so that both html file and php file have the same PHP session ID.
Thanks for your help in advance.
You can’t have PHP sessions in HTML files. Best to just change the HTML file to a PHP file.
As mentioned in the comments – make sure you start the session at very top of the file before any spaces before the opening php tags.
To retrieve the session ID use php function session_id() but if the both files are on same domain you just need to call session_start at the very top and it’ll just use same session across.
EDIT
To answer your qs in comments below –
Yes, a PHP file can just have HTML code but no PHP code at all or add PHP where required. e.g.
Myfile.php
so you just open and close php tags where you needed php stuff to go.
To print session ID – just use somewhere in the HTML of PHP file.
Yes, session_id() will give you the same session ID in php2 file – again, make sure you call session_start function at the very top in the php2 file too.