Jump to content

PHP Login - redirect to user profile *Help Please*


Recommended Posts

Hiya,

 

I am trying to redirect users when they login to their own custom profile page.

I am guessing I need to change the link when users login, but I am not sure what to change it too, for it to work.

 

The current link is 'members.php' - however this is a general page.

 

The database records a unique 'ID' for each user, so I guess this is something that is included.

 

My code is

<?php 
// Connects to your Database 
mysql_connect("localhost", "private", "private") or die(mysql_error()); 
mysql_select_db("private") or die(mysql_error()); 

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))

//if there is, it logs you in and directes you to the members page
{ 
$email = $_COOKIE['ID_my_site']; 
$password = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) 
{
if ($password != $info['password']) 
{
}
else
{
header("Location:members.php");

}
}
}


//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted

// makes sure they filled it in
if(!$_POST['email'] | !$_POST['password']) {
die('You did not fill in a required field.');
}
// checks it against the database

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error());

//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=www.rawtees.co.uk/loginpage.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check )) 
{
$_POST['password'] = stripslashes($_POST['password']);
$info['password'] = stripslashes($info['password']);

//gives error if the password is wrong
if ($_POST['password'] != $info['password']) {
die('Incorrect password, please try again.');
}
else 
{ 

// if login is ok then we add a cookie
$_POST['email'] = stripslashes($_POST['email']); 
$hour = time() + 3600; 
setcookie(ID_my_site, $_POST['email'], $hour); 
setcookie(Key_my_site, $_POST['password'], $hour);	

//then redirect them to the members area 
header("Location:members.php"); 
} 
} 
} 
else 
{	

?> 

Then question becomes how are you saving their profiles?

 

either file or db based.

if u store their pages/profiles in a db, than its just a simple matter of formatting the page

if u have a file based system (either filebased username.html or folderbased username/index.html), u can simply include the file from the profile page.

 

but u should have a system, to validate the pages. Safe javascript, no php scripts, etc, or use a custom markup language. otherwise ya will get a few users who will attempt to use em in a bad way.

 

 

Ok, more details:

 

If user A logs in I want them to be directed to www.sitename.co.uk/userA.php

If user B logs in I want them to be directed to www.sitename.co.uk/userB.php

 

All profile information and user info is stored in a database.

 

Is there not a simple way of re-directing users to different pages from the login?

 

If not, thanks for the help, and do you know of any other ways?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.