redirect if logged in

Status
Not open for further replies.
C

chrismitchell

Guest
Hi everyone.. trying to force a redirect if a client is logged in:

I've tried the following:

if (!isset($_SESSION['USER'])) {header('location: myfiles.php');

and things like that.. but its just not working :(

does anyone else have any ideas?

It gives me the error of a redirect loop.
 
1. Right now your code reads !isset, which seems wrong to me. Shouldn't it redirect when it is set?

2. Does your myfiles.php have a bit of code that also redirects (to itself) when logged in, thus constantly looping a redirect? Could be through an included file that checks for the login + redirect.
 
well it doesn't really have any redirect going on.. my codes is as follows:

Code:
<?phpif ( !isset ( $page_title ) )   $page_title = 'Welcome the Justupload';if ( !isset ( $content ) )      $content    = 'No content specified.';// check for unread messages$has_unread = false;if ( $UPL['USER']['logged_in'] ){    $messages =& $UPL['USER']['messages'];    reset ( $messages );    while ( list ( $i, $message ) = each ( $messages ) )    {	if ( !$message['read'] ) $has_unread = true;    }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" /><title>Welcome to Justupload</title><link rel="stylesheet" type="text/css" href="templates/default2/style.css" media="all"><script type="text/javascript" src="templates/default2/javascript.js"></script></head><body class="bg" onunload="window.open('account.php?action=logout');" ><div class="redbartop"></div>    <noscript>        <p style="text-align:center;font-size:1.2em;color:red;font-weight:bold;">Please enable Javascript to properly access this service.</p>    </noscript>	<br/>	<div id="container1">	<a href="http://www.justupload.co.uk/account.php?action=logout"><img id="logo" src="http://www.justupload.co.uk/images/justdigitallogo.png" /></a>    <?php /* If user is logged in, show this menu */ if ( $UPL['USER']['logged_in'] ) : ?>    <div id="container">    <div id="container2">			<?php /* If user is logged in, show this menu */ if ( $UPL['USER']['logged_in'] ) : ?>			<div id="top">				Welcome <span style="color:#E51B24;"><?=$UPL['USER']['name']?>!</span> <a href="account.php?action=logout" onclick="return confirm('Confirm logout?');">Please logout you are when finished</a>.			</div>			<div id="menu">				<div id="menu_links">					<div style="float:left;">						<?php /* If user is logged in, show this menu */ if ( $UPL['USER']['logged_in'] ) : ?>						<a href="myfiles.php">My Files</a>						<a href="upload.php">Upload</a>						<?php /* Otherwise, show this menu instead */ else: ?>						<a href="account.php?action=login">Login</a>						<a href="account.php?action=register">Register</a>						<?php endif; ?>					</div>					<?php /* If user is logged in, show this menu */ if ( $UPL['USER']['logged_in'] ) : ?>					<div style="float:right;">						<a href="usercp.php">User Control Panel</a>						<a href="account.php?action=logout" onclick="return confirm('Confirm logout?');">Logout</a>					</div>					<?php endif;?>				</div>			</div>			<?php /* Otherwise, show this menu instead */ else: ?>			<?php endif; ?>			<div id="message">				<div style="float:left;width:98%;" id="message_content"><!-- --></div>				<div style="float:right;width:10px;text-align:right;"><img src="templates/default2/images/close.gif" alt="" onclick="showIt('message',false);" style="cursor:pointer;" /></div>				<div class="spacer"><!-- --></div>			</div>            <div id="content">                <?=$content?>            </div>        </div>	</div>	</div>	<?php /* Otherwise, show this menu instead */ else: ?>	<div id="container3">		<div id="content">            <?=$content?>		</div>	</div>	<?php endif; ?>    <div id="credit">	<?php /* If user is logged in, show this menu */ if ( $UPL['USER']['logged_in'] ) : ?>	<p style="color:#fff;font-size:18px;">browser based - no software - no hassle</p>	<?php /* Otherwise, show this menu instead */ else: ?>	<img src="http://www.justupload.co.uk/test/templates/default2/images/Icon.png"/>	<?php endif; ?>	<br/>	<a style="color:#fff;fontsize:9px;text-align:center;font-weight:normal;" href="http://www.nemodesigns.com/webdesign.html">Pixels by Nemo Designs</a><br/>        <?php /* Show this link if user is a mod or admin */ if ( $UPL['USER']['level'] >= LEVEL_MODERATOR ) : ?>        <br /> <a href="admin.php">Go to Admin section</a>        <?php endif; ?>    </div>    <!-- post processing -->    <?php /* Show message if there are unread messages */    if ( $has_unread ) : ?>    <script type="text/javascript">    help ( 'You have a new message. <a href="usercp.php?action=pm" class="special">Click here</a> to view your messages.' );    </script>    <?php endif; ?></body></html>

For some reason when a user is logged in it shows both the normal home page and the homepage for those not logged in. (only if they are logged in and return to the main domain name) I have an image to show what happens if it helps?

Can anyone help me work this little puzzle out?
 
This is now resolved :) all it needed was a redirect in the index.php to force it elsewhere :) thead closed :)
 
Status
Not open for further replies.
Back
Top