Hi,
I am new to php. I am redirecting the page after checking the session global variable but the php is still opening the old page. the script is as follows :
<?PHP
session_start();
if ($_SESSION['Username'] != "")
{
header('Location: XXXXX.php',True);
Echo $_SESSION['Username'];
}
?>
I have inculed this script file in the top of the php page. Thanks a lot for help in advance
Redirecting the page
Moderators: egami, macek, gesf
hello,
your script is correct, try to get the value of $_SESSION['Username'] and then do testing, so that you will know the exact error for no execution, like this as given below:
i assigned the value first to session, then checked it in if condition and then it executed successfully.
and also use echo statement in lower case.
<?php
session_start();
$_SESSION['Username'] = "a";
if ($_SESSION['Username'] != "")
{
header('Location: XXXXX.php',True);
echo $_SESSION['Username'];
}
?>
your script is correct, try to get the value of $_SESSION['Username'] and then do testing, so that you will know the exact error for no execution, like this as given below:
i assigned the value first to session, then checked it in if condition and then it executed successfully.
and also use echo statement in lower case.
<?php
session_start();
$_SESSION['Username'] = "a";
if ($_SESSION['Username'] != "")
{
header('Location: XXXXX.php',True);
echo $_SESSION['Username'];
}
?>
Hi,
Thanks a lot. I have already tested it. The Script is getting the $_SESSION['Username'] variable and then after checking the condition it is also successfully Displaying the Variable value with 'echo ' Statement. But not running the header. that's really strange thing which i am facing ..
Its Displaying the $_SESSION['Username'] variable value but not redirecting with header..
Thanks a lot. I have already tested it. The Script is getting the $_SESSION['Username'] variable and then after checking the condition it is also successfully Displaying the Variable value with 'echo ' Statement. But not running the header. that's really strange thing which i am facing ..

Hi These are the two files
File1 : LandingScript.php in which i have put Include_Once on the top which call the File 2
File2 : UserloggedincheckScript.php which will called everytime the File 1 is called . In File 2 if the global Session variable is found the script then redirect it to other page. Thanks
File1 : LandingScript.php in which i have put Include_Once on the top which call the File 2
File2 : UserloggedincheckScript.php which will called everytime the File 1 is called . In File 2 if the global Session variable is found the script then redirect it to other page. Thanks
- Attachments
-
- phpScript.zip
- it is zipped file. it include both files.
- (1.97 KiB) Downloaded 37 times
One more info. The script is showing following warning ..
"Warning: Cannot modify header information - headers already sent by (output started at /home/XXXXXX/XXXXXX_html/landing.php:1) in /home/XXXXXX/XXXXXX_html/userloggedincheck.php on line 5"
Thanks a lot again for ur help
"Warning: Cannot modify header information - headers already sent by (output started at /home/XXXXXX/XXXXXX_html/landing.php:1) in /home/XXXXXX/XXXXXX_html/userloggedincheck.php on line 5"
Thanks a lot again for ur help
hello,
the script that you send, it works on my system, the only error i am getting in include php name file, as the name is not correct, the actual name is include_once('userloggedincheckScript.php'); and the filename mentioned: include_once('userloggedincheck.php');
when i execute the first file landingScript.php, it automatically redirects as the path given in userloggedincheckScript.php file within header function.
i just only declare the value of session as i am not getting from the main file.
userloggedincheckScript.php :
<?PHP
session_start();
$_SESSION['Username'] = "a";
if ($_SESSION['Username'] != "")
{
header('Location: http://www.XXXXXX.com/me.php',True);
echo $_SESSION['Username'];
}
?>
the script that you send, it works on my system, the only error i am getting in include php name file, as the name is not correct, the actual name is include_once('userloggedincheckScript.php'); and the filename mentioned: include_once('userloggedincheck.php');
when i execute the first file landingScript.php, it automatically redirects as the path given in userloggedincheckScript.php file within header function.
i just only declare the value of session as i am not getting from the main file.
userloggedincheckScript.php :
<?PHP
session_start();
$_SESSION['Username'] = "a";
if ($_SESSION['Username'] != "")
{
header('Location: http://www.XXXXXX.com/me.php',True);
echo $_SESSION['Username'];
}
?>
Great Thanks a lot for your help ... But everything seems to be screwing me up ... i am receiving the errors .. 
