seadog Posted April 27, 2008 Share Posted April 27, 2008 so im workin on a project and the base code i need to use is PHP. now i dont know much about php and i have a question. My project is quiet similar to myspace but much much much much smaller. I want the users to be able to register, set up a profile, then have their profile set up in the URL. ex. website.com/usersprofile ex2. website.com/myprofileusername Im having no troubles yet with inputting data. displaying it im still learning. but im baffled as to how once the user sets up their profile it can be viewed by URL. can anyone help me out with this system? Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/ Share on other sites More sharing options...
DeanWhitehouse Posted April 27, 2008 Share Posted April 27, 2008 u need to use sessions on the login, there make dynamic links using there sessions. here is an example <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; if ($_SESSION['is_valid'] == true){ $user_id = $_SESSION['user_id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } else { echo "Please login to view this page."; } ?> and a members page, <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; if ($_SESSION['is_valid'] == true){ if (isset($_GET['id'])) { if ((int) $_GET['id'] > 0) { $user_id = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $userprofname = $row['user_name']; $profemail = $row['user_email']; echo "$userprofname<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$profemail'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } exit(); } else { echo "Invalid user ID passed to page! <br />"; echo "<a href=\"members.php\">Return to user list</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT user_id, user_name FROM $user"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { echo "User List:<br />"; while ($row = mysql_fetch_assoc($result)) { echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />'; } } } else { echo "Please login to view this page."; } ?> this is my user profile link <br><a href='user_profile.php?id=<?php echo $_SESSION['user_id']; ?>'>User Profile</a><br> Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528086 Share on other sites More sharing options...
seadog Posted April 27, 2008 Author Share Posted April 27, 2008 well this is the setup i have now. i have a login a registration page and a members page. but could u tell me if by using this is what i want to do possible. i have a premade template and a small scenario setup http://fpsroster.freehostia.com/ Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528091 Share on other sites More sharing options...
DeanWhitehouse Posted April 27, 2008 Share Posted April 27, 2008 well, with this you will get dynamic links that show user_profile?id=1 etc. this is my login code, showing how to add the sessions, and yes this will get you what you want <?php require_once 'includes/db_connect.php'; if ($_SESSION['is_valid'] == false){ if (isset($_POST['login'])){ $user_name = mysql_real_escape_string($_POST["user_name"]); $user_password =mysql_real_escape_string($_POST["user_password"]); $cookiename = forumcookie; $verify_username = strlen($user_name); $verify_pass = strlen($user_password); if ($verify_pass > 0 && $verify_username > 0) { $userPswd = md5($user_password); $userpwsd = sha1($userPswd); $sql = "SELECT * FROM $user WHERE user_name='$user_name' AND user_password='$userpwsd' LIMIT 1;"; $result = mysql_query($sql) or die(mysql_error(). " in $sql"); if (mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($result); $user_level = $row['userlevel']; if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); $_SESSION['username'] = $row['user_name']; $_SESSION['user_password'] = $row['user_password']; $_SESSION['user_level'] = $row['userlevel']; $_SESSION['user_id'] = $row['user_id']; header("Location:http://".$_SERVER[HTTP_HOST]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['user_password'], time()+60*60*24*100, "/"); } } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); $_SESSION['username'] = $row['user_name']; $_SESSION['user_password'] = $row['user_password']; $_SESSION['user_level'] = $row['userlevel']; $_SESSION['user_id'] = $row['user_id']; header("Location:http://".$_SERVER[HTTP_HOST]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['user_password'], time()+60*60*24*100, "/"); } } } else{ echo "Login failed. Username and Password did not match database entries."; } } else { echo "Form was not completed. Please go back and make sure that the form was fully completed."; } } ?> <html> <table bgcolor='#999999' align='right'><form action="<?php $_SERVER['PHP_SELF']; ?>" method='POST'> <tr><td>Username: </td><td><input type='text' name='user_name' /><br /></td></tr> <tr><td>Password:</td><td> <input type='password' name='user_password' /><br /></td></tr> <tr><td><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr> <tr><td><input type="checkbox" value="1" name="remember"> Remember Me </td></tr><tr><td><a href="register.php">[Register]</a></td></tr><tr><td><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table> </form> </html> <?php mysql_close(); } else { header("Location:http://".$_SERVER[HTTP_HOST]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528093 Share on other sites More sharing options...
seadog Posted April 27, 2008 Author Share Posted April 27, 2008 thank you allot blade. i will figure out how to use this and ill post again if i need any more assistance. thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528094 Share on other sites More sharing options...
DeanWhitehouse Posted April 27, 2008 Share Posted April 27, 2008 ok, if you get any errors post the code aswell as the error and i will try and help Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528096 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 The all idea of this is having a table with every user detail as column. So consider: table 'users' ----------- id | username | password | name | surname | email | gender | birthday | registered When the user registeres he completes all the required info and if everything validates, is added to the db as a new row. Using sessions or cookies will keep track of his logged in state in all the site. For a profile page, profiles.php?user=seadog will do it, and the script gets the "user" url variable and queries the database for the related info. To make it profiles.php/seadog or even seadog.mysite.com u need to use htaccess to rewrite urls. There are a lot of tutorials about that, but this one ive found particulary interesting. Dont know what other questions u have, so feel free to ask them. EDIT: Was writing this before Blade's code, but maybe u can still find it interesting. Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528097 Share on other sites More sharing options...
seadog Posted April 27, 2008 Author Share Posted April 27, 2008 cool ill give this stuff a shot. then ill report back =) -edit- could i actually edit the htaccess to make the url just mysite.com/usersprofile Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528165 Share on other sites More sharing options...
seadog Posted April 27, 2008 Author Share Posted April 27, 2008 bump -edit again =\- could u actualyl show me how i would go about making the URL profile.mysite.com Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528567 Share on other sites More sharing options...
DeanWhitehouse Posted April 27, 2008 Share Posted April 27, 2008 thats a subdomain, not created by PHP(i don't think) but created on the host Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528574 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 PHP hasnt such privileges actually. As far as i know, it can be done with htaccess, but as ive never experimented with such a technique, im not going to give my personal thoughts. Instead im giving two links where probably u'll find some good information: link1 and link2. Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-528589 Share on other sites More sharing options...
seadog Posted April 29, 2008 Author Share Posted April 29, 2008 i noticed you gave me a login script and a members profile script. Does this mean that it doesnt matter how i register the user. as long as the information gets in there? Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-529844 Share on other sites More sharing options...
DeanWhitehouse Posted April 29, 2008 Share Posted April 29, 2008 erm, yer (please anyone correct me if i'm wrong) Quote Link to comment https://forums.phpfreaks.com/topic/103093-help-with-my-project/#findComment-529854 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.