Php Redirect Help Please - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-12-2010, 02:53 AM   #1 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 1
Unhappy Php Redirect Help Please

Hey i have a page, which i want to redirect to a login page if, the user is not logged in.

here is the code

**********************
<?

include("include/session.php");
include_once("mysql.inc.php");
$connection = @mysql_connect($host, $user, $password) or die(mysql_error());
$db = @mysql_select_db($name,$connection) or die(mysql_error());
include("include/banner.php");
?>
<div id="chatbox">
<form id="newshout" name="newshout" action="newshout.php" method="post">
Message:<br>
<input name="shout" type="text" id="Post" size="24" maxlength="50" />
<input id="submit" name="submit" type="submit" value="post" /></form>
<?

$sql = mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id`");

while($data = mysql_fetch_array($sql)){

$timestamp = $data['timestamp'];
$postedyear=substr($timestamp,0,4);
$postedmonth=substr($timestamp,5,2);
$postedday=substr($timestamp,8,2);
$postedtime=substr($timestamp,11,5);
$newpostedtime = "";
$nomilitary=substr($postedtime,0,2);


if($nomilitary >= 13){
$nomilitary = $nomilitary - 12 ;
$newpostedtime = $nomilitary ;
$newpostedtime .= ":" ;
$newpostedtime .= substr($postedtime,3,2) ;
$newpostedtime .= " pm";
}
if($newpostedtime != ""){
$postedtime = $newpostedtime;
}else{
$postedtime .= " am";
}


$shoutby = $data['shoutby'];
$shout = $data['shout'];

echo "<br><br><div id='comments'><strong>" . $shoutby . "</strong>: <br><br> " . $shout . "<br><br> <div id='posted'> Posted " . $postedmonth . "/" . $postedday . "/" . $postedyear . " at " . $postedtime . "<br></div></div>";
}
?>
</div>
<?php
include("include/footer.php");
?>

*****************************

i want it to redirect to "../login/index.php"

can anyone please help me

thanks
perception is offline   Reply With Quote
Sponsored Links
Old 07-12-2010, 07:06 AM   #2 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 9
Default Re: Php Redirect Help Please

You need to provide more information then that. What is the Users table schema ? do you have a session table or something where all logins are tracked?

I suggest googling for "tutorial php login" you will find tons of tutorials on how to accomplish that
checkWebsite is offline   Reply With Quote
Old 01-16-2012, 01:19 PM   #3 (permalink)
Junior Member
 
Join Date: Jan 2012
Posts: 1
Default Re: Php Redirect Help Please

perception, you need to modify your session.php file to check if you have an active user logged in and if not, execute this code:

Code:
header("Location: ../login/index.php"); exit();
More info about this here:

php.net/manual/en/function.header.php

phpredirection.com
daveq1122 is offline   Reply With Quote
Old 05-16-2012, 05:16 AM   #4 (permalink)
Regular User
 
Join Date: May 2012
Location: usa
Posts: 18
Default Re: Php Redirect Help Please

Quote:
Originally Posted by daveq1122 View Post
perception, you need to modify your session.php file to check if you have an active user logged in and if not, execute this code:

Code:
header("Location: ../login/index.php"); exit();
More info about this here:

php.net/manual/en/function.header.php

phpredirection.com
this code is correct . howerver u can use
PHP Code:
<?php
echo '<script type="text/javascript">
     location.href=\'../login/index.php\';
</script>'
;
?>
y8games2012 is offline   Reply With Quote
Reply

Tags
code , help please , login , php , redirect

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:55 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting