Reputation: 43
I am creating a photography website for a friend. Part of it is a Client Login area where clients can enter the username and password my friend has given them to view all the photos from their shoot/ wedding etc.
I have created the client login form and login.php:
$user = mysql_real_escape_string($_POST["username"]);
$pass = mysql_real_escape_string($_POST["password"]);
$clientdata = mysql_query("SELECT * FROM Users WHERE username='$user' and password='$pass'")
or die (mysql_error());
$data = mysql_fetch_array($clientdata, MYSQL_ASSOC);
if(mysql_num_rows($clientdata) == 1){
session_start();
$_SESSION['username'] = $user;
$username = $hook->getValue('username');
$pageId = 'index';
switch ($username) {
case 'Marie&Peter':
$pageId = 'MarieWeddingGallery.php';
break;
}
$landingPage = $modx->makeUrl($pageId, "", "", 'full');
$modx->sendRedirect($landingPage);
}else{header('Location: clientLogin.html');}
The switch part is supposed to redirect the user based on the username they gave, but it doesn't work. Any suggestions?
Upvotes: 0
Views: 267
Reputation: 248
First, to fully answer this question we will need to know what $modx is. It appears the problem lies in $modx->makeUrl() or $modx->sendRedirect().
A quick solution is to replace the line
$pageId = 'MarieWeddingGallery.php';
with
header('Location: MarieWeddingGallery.php');
This is the same technique you're using to redirect to the login page.
Finally, using a switch to load pages based on user name is not a good way to do this. Every new user will require you to add code to support them. You should add a field to your database for the gallery page. Other techniques could be used as well.
To load the page based on a database field you should replace the switch with
header('Location: ' . $data['targetPage']);
This expects the targetPage field in the database to contain the full name of the php file (e.g. 'MarieWeddingGallery.php').
Upvotes: 1
Reputation: 477
Why do you get $username from $hook? You already have username in variable $user.
switch ($user) {
should solve your problem.
Upvotes: 0