4 Replies - 625 Views - Last Post: 03 March 2012 - 05:31 PM Rate Topic: -----

#1 heresh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

how do i make some page only available to logedin users

Posted 03 March 2012 - 03:22 AM

hi as the title says how do make some pages only available to logedin users I want to make a members page this is the login I wrote and I am a newbie. so some help would be greatly appreciated



<?php
session_start();
$connect = mysql_connect("******","******","******");
if(!connect){
echo 'Could not connect';
}
if(isset($_POST['username']) && !empty($_POST['username'])){
$username = $_POST['username'];
mysql_select_db("b7_10303729_dbzbattles");
$query = "SELECT * FROM users WHERE username='$username'";
$rows = mysql_query($query);
}

else{
echo 'please fill in all fields';
}

if($now = mysql_fetch_array($rows)){
$username1 = $now['username'];
$id = $now['id'];
header('Location: main.php');

}

else{
echo 'username not found please register below';
}
?>
<form action="loginform.inc.php" method="POST">
<p>Username:</p><input type="text" name="username">
<input type="submit" value="login">
</form>	
<a href="reg.php">Register</a>


This post has been edited by JackOfAllTrades: 03 March 2012 - 03:54 AM
Reason for edit:: Removed database credentials


Is This A Good Question/Topic? 0
  • +

Replies To: how do i make some page only available to logedin users

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: how do i make some page only available to logedin users

Posted 03 March 2012 - 03:55 AM

Jeez...STOP putting your database credentials in your posted code! We keep having to remove them. Do you think it's smart to post your database username and password on the Internet???

There are 600 million tutorials on this subject, including here are Dream.In.Code. Start reading them.
Was This Post Helpful? 1
  • +
  • -

#3 heresh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: how do i make some page only available to logedin users

Posted 03 March 2012 - 04:19 AM

thank you and sorry I forgot it will not happen again
Was This Post Helpful? 0
  • +
  • -

#4 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

Re: how do i make some page only available to logedin users

Posted 03 March 2012 - 01:23 PM

Make a sesison virable up for logged in users e.g username the check if its empty or not ( guest will be empty )


<?php
		
		if(empty($_SESSION['dream'])){

/// If the user is not logged in send them to this page under this
		header('Location: http://www.example.com/');  
		

}
		?>




So when the user is logged in make a Session virable called what ever you like then on the pages you don't want the guests not to see just put that code and edit the username to what ever session virable uve made

And if you are wondering how to make a session virable up its like so



$_SESSION['dream'] = "Your logged in";



The session virable can have what ever in it has long has its being set. Remember to put
session_start();
at the top of the page to start the session

This post has been edited by rpgmaker: 03 March 2012 - 01:25 PM

Was This Post Helpful? 1
  • +
  • -

#5 heresh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: how do i make some page only available to logedin users

Posted 03 March 2012 - 05:31 PM

thank you very much it worked :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1