Forums

PHP

This topic is locked

help with php login

Posted 05 Jul 2008 16:42:16
1
has voted
05 Jul 2008 16:42:16 Jaime Romo posted:
Hello there.... im new programming and with ASP i have no problems but im geting startedwith PHP and it's very difficult because i cant do a lot of things for example, im using a normal DW php login SB, and it works fine but i need to recibe on the confirmation page the username variable so i can create a recorset and retive information of the user, i have trayes with variables and with session and i still dont get the variables on the confirmation page. the regular DW php login code is

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['usuario'])) {
$loginUsername=$_POST['usuario'];
$password=$_POST['pasguer'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "Vtop.php";
$MM_redirectLoginFailed = "Nombre de usuario o contraseña incorrectos, favor de corregirlos.";
$MM_redirecttoReferrer = false;
mysql_select_db($database_marala, $marala);

$LoginRS__query=sprintf("SELECT correo, pasguer FROM maralaVendedoras WHERE correo='%s' AND pasguer='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $marala) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//declare two session variables and assign them
$_SESSION['mVentas'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
echo( $MM_redirectLoginFailed );
}
}
?>


and on the confirmatio page i just have at the top <?php session_start(); ?>

PLEASE HELP ME BECAUSE I DONT UNDERSTAND HOW TO DO IT.
THANKS.

Replies

Replied 06 Jul 2008 00:16:19
06 Jul 2008 00:16:19 Alan C replied:
Hola,

I think the first line <pre id=code><font face=courier size=2 id=code>if (!isset($_SESSION)) {
session_start();
} </font id=code></pre id=code>
has something missing, I think it should be like . . .

<pre id=code><font face=courier size=2 id=code> if (!isset($_SESSION['variable_to_test'])) {
session_start();
}</font id=code></pre id=code>

$_session is an associative array

When session_start(); is executed a session is started, this saves the session id into a cookie and the session variables into a file on the server, after that you can do something like

$_SESSION['username']='nombre';

then on the next page you should be able to do . . .

if($_SESSION['username']=='nombre') { //some action} else {//something else}

the values in $_SESSION['xxxxx'] area automatically available on all pages after you do session_start();

BUT . . .

I had a big problem with my hosting company, they turned off session support so when I created a new account for a new site the sessions did not work, I spent a whole day troubleshooting until I knew if was the session that was the problem and only when I asked the support staff did they enable the sessions and then everything worked fine.

Alan
Replied 07 Jul 2008 17:20:34
07 Jul 2008 17:20:34 Jaime Romo replied:
thanks for the help actually it work but just one time..... because when i refresh the page the sessio name didnt appear. im going to check with the hosting support teat to se if it´s the problem that you told told me
thanks.

Visit my home page
www.cancuncoral.com

Reply to this topic