Simple Header code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Simple Header code

Post by AliasBDI »

I have this code on my login page:

Code: Select all

$sitepath = "www.domainname.com"
$domain = $_POST['domain'];
$redirect = $sitepath . "/" . $domain;

header("Location: $redirect");
I don't think I'm doing it correctly. Should this work? Basically, someone sends a form with the field "domain" which contains something like "domain.com" in it. I want it to redirect them to a url built by the variables.

Following the code above the variable redirect should read:
Should this work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you probably need to add a protocol to be compatible with more browsers.. (http:// or whatever...)
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Sorry.

Post by AliasBDI »

Yea I have that in the $sitepath. It reads like this instead: $sitepath = "http://www.domainname.com";

Sorry to leave that out. But everything else should work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

as long as "domain.com" generates a response from the server.. I don't see a problem..
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Alright!

Post by AliasBDI »

Did some twinking and got it working. Here is the code for anyone to use. It basically redirects a person after a post form of fields "domain" and "password".

Code: Select all

<?php
/* Check User Script */
session_start();  // Start Session

include 'connection_db.php';

// Convert to simple variables
$domain = $_POST['domain'];
$password = $_POST['password'];

$sitepath = "http://www.domainname.com";

if((!$domain) || (!$password)){
	include 'loginAgain.php';
	exit();
}

// Convert password to md5 hash
$password = md5($password);

// check if the user info validates the db
$sql = mysql_query("SELECT * FROM user_info WHERE domain='$domain' AND password='$password' AND active='Y'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
	while($row = mysql_fetch_array($sql)){
	foreach( $row AS $key => $val ){
		$$key = stripslashes( $val );
	}
		// update last login
		$last_login = "UPDATE user_info SET date_lastlogin = NOW() WHERE domain = '$domain' AND password = '$password'";
		mysql_query($last_login) or die(mysql_error()); 
		
		// Register some session variables!
		session_register('domain');
		$_SESSION['domain'] = $domain;
		session_register('email');
		$_SESSION['email'] = $email;
		session_register('level');
		$_SESSION['level'] = $level;
		session_register('date_created');
		$_SESSION['date_created'] = $date_created;
		session_register('id');
		$_SESSION['id'] = $id;
		session_register('password');
		$_SESSION['password'] = $password;
		session_register('active');
		$_SESSION['active'] = $active;
		
		$redirect = $sitepath . "/client_" . $domain; 

		header("Location: $redirect");
	}
} else {
	$msg = "You could not be logged in! Either the username and password do not match or you have not been activated!  Please try again!<br />";
	include 'loginAgain.php';
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]session_register[/php_man] wrote:If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
Post Reply