I have two files; the logic is such that if session is started i've to run a piece of code and if its not set then i have to run the else part. In any case i need to throw the page onto itself. Here's my first file
First File (file1.php)
<?php require_once('file2.php'); if(isset($_SESSION)) echo '<br>Session set!'; else { //echo '<br>Session NOT set...'; sessStart(); header("Location:file1.php"); } ?>
Second File (file2.php)
<?php function sessStart() { session_start(); //some other code here but nothing that echo's } ?> What I do here is call sessStart() method to initialize the session in the else part the first time it is run. The next time it should not go into the if section but else part.
Somehow the code doesn't redirect the file to the same file and the part where the session is set doesn't initialized. If i store something in the session in 2nd file i can retrive it in the first file so the session is started successfully but how to redirect?
What's wrong that i am doing?
session_start();on top of file1.php and forget about redirecting