Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Redirecting the page

Links for php scripts

Moderators: macek, egami, gesf

Redirecting the page

Postby SonuSingh » Mon Jan 23, 2012 10:53 pm

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
SonuSingh
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jan 23, 2012 10:49 pm

Re: Redirecting the page

Postby rupali » Mon Jan 23, 2012 11:32 pm

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'];
}
?>
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Redirecting the page

Postby SonuSingh » Tue Jan 24, 2012 9:31 am

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..
SonuSingh
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jan 23, 2012 10:49 pm

Re: Redirecting the page

Postby rupali » Wed Jan 25, 2012 3:15 am

ok,
where have you written this code, at the beginning? or can you please send your script?
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Redirecting the page

Postby SonuSingh » Wed Jan 25, 2012 5:45 am

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
Attachments
phpScript.zip
it is zipped file. it include both files.
(1.97 KiB) Downloaded 27 times
SonuSingh
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jan 23, 2012 10:49 pm

Re: Redirecting the page

Postby SonuSingh » Wed Jan 25, 2012 5:37 pm

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
SonuSingh
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jan 23, 2012 10:49 pm

Re: Redirecting the page

Postby rupali » Wed Jan 25, 2012 7:11 pm

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'];
}
?>
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Redirecting the page

Postby SonuSingh » Sun Jan 29, 2012 10:37 am

Great Thanks a lot for your help ... But everything seems to be screwing me up ... i am receiving the errors .. :(
SonuSingh
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jan 23, 2012 10:49 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.