473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Rewrite profile URL with username.

In this code with mod_rewrite I can visit the profile of any user by typing his username after domain like example.com/john this will take us to john's profile. This works well however if I type any name which is not a username for existing user in my database like example.com/notauser I still get redirected to a empty profile page, though it has no profile pic or other info but all other buttons and links like followers, friends etc are still available. In such a case I want to redirected to login page or echo message user does not exist, but can't figure out how to do that.

profile.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(!empty($_GET['username'])) { 
  3. $username = $_GET['username'];
  4. }
  5. else if(!empty($_SESSION['username'])) { 
  6. $username = $_SESSION['username'];
  7. }
  8. else { 
  9. header("Location: login.php"); 
  10. die();
  11. }
  12. ?>
.htaccess file
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
Oct 31 '15 #1
1 1107
Dormilich
8,658 Expert Mod 8TB
if your database query returns an empty result, redirect to the login/error page.
Nov 2 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: kehmka | last post by:
Hello, I need to understand the full scope of changing the Profile.UserName property when a user goes from anonymous to authenticated. It's read-only and essential to acquiring profile...
1
by: Keith Patrick | last post by:
Currently, if I declare an asp:Login control on a page and login, on both OnAuthenticate and OnLoggedIn, this.Profile.UserName is still null, even though the user does get authenticated and shows...
0
by: James Woody | last post by:
Hi. Kinda stuck. Newbie. Can youi help thanks
4
by: Marco Assandri | last post by:
Hi everybody, I have a problem with this code. 'An anonymous username copied from the Username column of Aspnet_Users table with IsAnonymous = True dim SurelyAnonymousUsername =...
0
by: Jesse Johnson | last post by:
I have this block of code below, but when ran it only creates the member it doesnt fill in his profile data. Is there something I am missing? Please let me know what I can do, just trying to...
2
by: Seb | last post by:
User.Identity.Name or Profile.UserName? whats the difference and which am I suppose to use? best regards
3
by: Oriane | last post by:
Hi there, I would like to open my Asp.Net project as a "Web Application" rather than as a "Web Site" in Visual Studio. But the thing is that I use the System.Web.Profile and the auto-generated...
3
by: shapper | last post by:
Hello, I am working with an ASP.NET MVC Web Application and I am using the following custom profile provider: ...
2
by: shapper | last post by:
Hello, I know that only authenticated users has a UserName. In Anonymous users there is an ID. If I am not wrong when getting a profile of a user, if the user is authenticated the UserName is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.