There are two issues at play here. First of all you need to start your session before sending any output to the client. For example, your file should begin like so:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
If you do it the other way around (you send the DOCTYPE
and HTML
before the session is started) then PHP sends any pending HTTP headers followed by the content. By virtue of the way the HTTP protocol works, once any amount of content is sent, you cannot resend the headers. Thus a late session start (which needs to set a cookie header) will not work.
Your second issue is that you are calling a session_start()
in Get_url.php, which is then include()
ed in Next.php, which also has a session_start()
. When you call that second session_start()
it is overwriting the first session with a new session_id.
So in summary:
session_start()
before outputting data to the useronly one
session_start()
at a time. If you must include another file that could potentially have a session_start() you may want to use something like this:$sid = session_id(); if(empty($sid)) session_start();