ryanwood4 Posted February 27, 2009 Share Posted February 27, 2009 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 { ?> Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/ Share on other sites More sharing options...
runnerjp Posted February 27, 2009 Share Posted February 27, 2009 ok hows ur profile page look.. if its www.site.com/profile and there profile then just get there profile name from the db and in the url do something like www.site.com/$username Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772706 Share on other sites More sharing options...
ryanwood4 Posted February 27, 2009 Author Share Posted February 27, 2009 I'd like it to redirect to a URL ending with the persons nickname - which they chose when they registered. So would it simply be www.rawtees.co.uk/$nickName.php ? Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772713 Share on other sites More sharing options...
runnerjp Posted February 27, 2009 Share Posted February 27, 2009 ah ok so i take it u havent got it so u just typoe www.rawtrees.co.uk/ryan Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772728 Share on other sites More sharing options...
ryanwood4 Posted February 27, 2009 Author Share Posted February 27, 2009 ah ok so i take it u havent got it so u just typoe www.rawtrees.co.uk/ryan I don't get this, that won't help at all! I want users to redirect to their OWN page, a custom page for every single person. Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772769 Share on other sites More sharing options...
premiso Posted February 27, 2009 Share Posted February 27, 2009 You want to take a look into .htaccess and mod_rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772778 Share on other sites More sharing options...
laffin Posted February 27, 2009 Share Posted February 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772797 Share on other sites More sharing options...
ryanwood4 Posted February 27, 2009 Author Share Posted February 27, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772913 Share on other sites More sharing options...
laffin Posted February 27, 2009 Share Posted February 27, 2009 <?php // replace with login/username validation $user='joe'; if(empty($user)) $userpage='login.php'; else $userpage="User-$user.php"; header( 'Location: http://www.yoursite.com/'.$userpage ) ; ?> simple redirection. Quote Link to comment https://forums.phpfreaks.com/topic/147195-php-login-redirect-to-user-profile-help-please/#findComment-772940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.