...

View Full Version : Sessions?



RawliJr
06-20-2006, 12:30 AM
if(!$_SESSION['logged_in'] {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}


what im to do is trying to make it so people can just go to http://www.thugkillin.urlshort.com/base.php without being signed in!?


Rawli:thumbsup:

lavinpj1
06-20-2006, 12:31 AM
You need another ) and you should probably use isset, i.e.


if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}

RawliJr
06-20-2006, 12:47 AM
<?php
if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}
?>


didnt work it says a warning!

Warning: Cannot modify header information - headers already sent by (output started at /home/thug/public_html/base.php:2) in /home/thug/public_html/base.php on line 4


and this is the script of the top?
for my base.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}
?>

Spookster
06-20-2006, 01:16 AM
You cannot send a header to the client after you have sent anything else. That means you need to call the header function before any HTML gets sent to the client browser.

Mwnciau
06-20-2006, 08:46 AM
you have to put
session_start()at the top of the page before any echos or html

RawliJr
06-20-2006, 03:23 PM
<?php
session_start()
if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Main Menu</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
background:#000;
color:#FFF;
}
.eric {
height: 400px;
width: 200px;
border: 3px solid red;
background: blue;
color:#FFF;
float:left;
}
.rawli {
height: 400px;
width: 200px;
border: 3px solid red;
background: blue;
float: right;
}
a:link {color: #FF0000;background-color:inherit;}
a:visited {color: #00FF00;background-color:inherit;}
a:hover {color: #FF00FF;background-color:inherit;}
a:active {color: #0000FF;background-color:inherit;}
</style>
</head>
<center><img src="/images/THUGKILLIN.jpg" border="0" width="444" /></a></center>
<?php
$link = mysql_connect("localhost","xxx","xxx") or die("No connection");
mysql_select_db("xxx",$link) or die("Bad Database");
$rec_query = "SELECT * FROM users WHERE username='$thisusername'";
$rec_res = mysql_query($rec_query) or die(mysql_error());
$rec = mysql_fetch_array($rec_res);
$getid = $rec['id'];
echo "$getid";
echo "$rec_query";
?>
<body>
<div class="eric">
<a href="turntrick.php">Turn Tricks</a>
<br><br>
<a href=">forums.php">Forums</a>
<br><br>
<a href="getturns.php">Buy Turns</a>
<br><br>
<a href="attackrank.php">Attack Ranks</a>
<br><br>
<a href="cityr.php">City Ranks</a>
</div>
<div class="rawli">
<a href="naranks.php">National Ranks</a>
<br><br>
<a href="store.php">Corner Store</a>
<br><br>
<a href="faqs.html">Faqs</a>
<br><br>
<a href="logout.php">Log out</a>
</div>
</body>
</html>

^that is my base.php^:thumbsup:

and that doesnt work?

it says on the browser
Parse error: syntax error, unexpected T_IF in /home/thug/public_html/base.php on line 3

lavinpj1
06-20-2006, 06:08 PM
This is SIMPLE stuff! Just look over your code before posting. You missed a ; after session_start().

~Phil~

RawliJr
06-21-2006, 12:33 AM
But now it still doesnt work, like it when i try adn login at the main menu page...it just wont load?



<?php
session_start();
if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}
?>

then if i take out all the php it works fine?

not sure what is wrong?And all of it is at the top of my script so ?:confused:

cheers
rawli

due
06-21-2006, 12:47 AM
try this

<?
session_start();
$_SESSION['logged_in']=0;
header("Location: http://www.thugkillin.urlshort.com/base.php");
?>

RawliJr
06-21-2006, 12:50 AM
nope

thanx anyways

RawliJr
06-21-2006, 04:33 AM
like would anybody know the code that if your not logged in, you can visit that page?

That would be very much help full if you do!:thumbsup:

beacuse this isnt working, or im missing something


<?php
session_start();
if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}
?>

Cheers
Rawli

Spookster
06-21-2006, 05:54 AM
With the code you have there if the session variable logged_in has not yet been set then the user will be redirected to the file base.php. You want them to go to base.php when they are not logged in correct? As for logging in you are actually giving the logged_in session variable a value in your code that authenticates the login correct?

jeddi
06-21-2006, 09:27 AM
Is it possible that you are coming in on a different page ?
ALL pages would need to have that code, not just your "base page"
--
just a thought :)

RawliJr
06-21-2006, 03:36 PM
You want them to go to base.php when they are not logged in correct?


no im trying to do , is that when people arnt logged in they cant go passed the index.php, and when they log in it takes them to the base.php, SO people cant just go to the BASE (http://www.thugkillin.urlshort.com/base.php) with out being logged in..?

and i dont know how to do that?:cool:

cheers
rawli

paulley
06-25-2006, 02:39 PM
like would anybody know the code that if your not logged in, you can visit that page?

That would be very much help full if you do!:thumbsup:

beacuse this isnt working, or im missing something


<?php
session_start();
if(!isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
}
?>

Cheers
Rawli

what i can see here, if you want the user to go to http://www.thugkillin.urlshort.com/base.php if they are logged in then i think its should be the code below, because i believe the above code is saying if they aint logged in go to http://www.thugkillin.urlshort.com/base.php


<?php
session_start();
if(isset($_SESSION['logged_in'])) {
header("Location: http://www.thugkillin.urlshort.com/base.php");
} else {
header("Location: http://www.thugkillin.urlshort.com/login.php");
?>

but i could be wrong

paulley



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum