JeanieTallis Posted April 1, 2009 Share Posted April 1, 2009 <? /* Requested Username error checking */ $req_user = trim($_GET['user']); if(!$req_user || strlen($req_user) == 0 || !eregi("^([0-9a-z])+$", $req_user) || !$database->usernameTaken($req_user)){ die("Username not registered"); } /* Logged in user viewing own account */ if(strcmp($session->username,$req_user) == 0){ echo "<h1>My Account</h1>"; } /* Visitor not viewing own account */ else{ echo "<h1>User Info</h1>"; } /* Display requested user information */ $req_user_info = $database->getUserInfo($req_user); /* Display Username */ echo "<b>Username: ".$req_user_info['username']."</b><br>"; /* Display Email */ echo "<b>Email:</b> ".$req_user_info['email']."<br>"; if(strcmp($session->username,$req_user) == 0){ echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>"; } ?> However, I modified the code to the following (this involves the htm so look out for the php mainly) <? /** * UserInfo.php * * This page is for users to view their account information * with a link added for them to edit the information. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 26, 2004 */ include("include/session.php"); if(strcmp($session->username,$req_user) == 0){ ?> <title>MyVee! User Info</title> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <link href="Style2.css" rel="stylesheet" type="text/css"> <div id="wrapper"> <div id="Layer4"> <div style="color:WHITE;"> <script type="text/javascript"> var d=new Date() var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") document.write(weekday[d.getDay()] + " ") document.write(d.getDate() + ". ") document.write(monthname[d.getMonth()] + " ") document.write(d.getFullYear()) </script> </div></div> <div id="Layer2"></div> <div id="Layer1"></div> <div id="Layer3"> <p> <? echo "<h1>My Account</h1>"; /* Display requested user information */ $req_user_info = $database->getUserInfo($req_user); /* Username */ echo "<b>Username: ".$req_user_info['username']."</b><br>"; /* Email */ echo "<b>Email:</b> ".$req_user_info['email']."<br>"; /** * Note: when you add your own fields to the users table * to hold more information, like homepage, location, etc. * they can be easily accessed by the user info array. * * $session->user_info['location']; (for logged in users) * * ..and for this page, * * $req_user_info['location']; (for any user) */ /* If logged in user viewing own account, give link to edit */ echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>"; ?> </p> <p>[ <a href="http://www.myvee.co.uk">back</a> ] </p> </div> </div> <?php } else { header("index.php"); } ?> This displays to all users, including the user visiting there own page just the [ back ] link, which sends you back to index.php, when initially, as set at the top, if the user is viewing there OWN ACCOUNT DETAILS, it shows the page with account details, else, which is at the bottom redirects users to index.php. The first codde displayed, (the html isn't included) this shows the user logged in viewing there account details, the "edit account details" link, aswell as the heading "MY ACCOUNT" if user isn't viewing there own account details, the heading is "USER INFO" and does not display "edit account details" link. I want the userlogged in viewing there own account details to be able to view there account details, as for everyone else, if they aint viewing there own account details, they dont find out the users details, so they get redirected back to index.php. I want to know what is wrong with the second code, and repairing. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/152102-solved-if-user-isnt-viewing-own-page-to-redirect-problems/ Share on other sites More sharing options...
JeanieTallis Posted April 1, 2009 Author Share Posted April 1, 2009 sorry about not using proper PHP tags, its just became a habbit to do short tags. Anyone know the problem. Quote Link to comment https://forums.phpfreaks.com/topic/152102-solved-if-user-isnt-viewing-own-page-to-redirect-problems/#findComment-798828 Share on other sites More sharing options...
JeanieTallis Posted April 1, 2009 Author Share Posted April 1, 2009 I take it nobody wants to help x.x Kay, ill try sort it out I don't know the problem tho thats the thing, if i knew I might be able to fix it ,but whats wrong with the if statement tho :/ Quote Link to comment https://forums.phpfreaks.com/topic/152102-solved-if-user-isnt-viewing-own-page-to-redirect-problems/#findComment-798980 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.