0

hi, i'm new to php...
i have created a login page -- login.html, where user can enter username & password.
when they submit the form, leads to a validation page -- login.php

if login succes it forwards to 3rd page. Suppose if it fails, then again redirects to login.html where i need a display a error message in a div as "Invalid Credentials" (div have been constructed already with css for that class display: none; )

i just need while redirecting to login.html that message should display by changing the css attributes.

3
Contributors
11
Replies
13
Views
7 Years
Discussion Span
Last Post by mangel.murti
Featured Replies
  • in your validating php if fails u can redirect to login page..... other wise to successfull page... u can set varibale value when redirecting ...just like below [CODE] <?php session_start(); if(!$_SESSION['id'] || !$_SESSION['name']){ header("Location: ./?error=1"); exit(); }?> [/CODE] and catch this error varibale value to your login.html page and show … Read More

1

in your validating php if fails u can redirect to login page..... other wise to successfull page... u can set varibale value when redirecting ...just like below

<?php session_start();
if(!$_SESSION['id'] || !$_SESSION['name']){
header("Location: ./?error=1");
exit();
}?>

and catch this error varibale value to your login.html page and show it....i hope this will work

0

i have coded like this...

if($count==1)                                 // If result matched $myusername and $mypassword, table row must be 1 row  
{
	session_register("$mymemberid");                // Register $mymemberid
	header("location:viewprofile.php");    // redirect to file "login_success.php"
}
else {
	header("location:login.html?login=failure");
}

how to get the parameter in login.html page?
is it enough to send parameter like this?

0

u can set variable values as below but for this u have to change login.html page to login.php page beacuse we have to capture url variable value....if u want login.html then u have to capture url varibale value through javascripts and then u can alert to user....

Most of the server-side programming languages that I know of like PHP, ASP, or JSP give you easy access to parameters in the query string of a URL. Javascript does not give you easy access. With javascript you must write your own function to parse the window.location.href value to get the query string parameters you want.

i am putting number to url variable u can put your value ......

<?php 

if($count==1)                                 // If result matched $myusername and $mypassword, table row must be 1 row  
{
	session_register("$mymemberid");                // Register $mymemberid
	header("location:viewprofile.php");    // redirect to file "login_success.php"
}
else {
	header("location:login.html?login=1");
}
?>

in your login.php page just add these lines.. u can show error message as u can like...

<?php 
if($_GET['error']==1)
{
	$mess_l="Invalid Credentials";
}
if($_GET['error']==2)
{
	$mess_l="Session Expire-Relogin Required";
}
?>

Edited by mangel.murti: n/a

0

Now my pages were,
login.php
for validation it goes to loginvalidation.php
if success then to viewprofile.php
else to login.php (here i wish to display an error message)

<?php
if($_GET['error']==1)
{
$mess_l="Invalid Credentials";
}
if($_GET['error']==2)
{
$mess_l="Session Expire-Relogin Required";
}
?>

whenever the login.php page laods it displays like this...

Notice: Undefined index: error in C:\wamp\www\SalemProject_2.0_30_12_2009_5am\SalemProject_2.0\login.php on line 2

Notice: Undefined index: error in C:\wamp\www\SalemProject_2.0_30_12_2009_5am\SalemProject_2.0\login.php on line 6

0

now my pages were
login.php for form
loginvalidation.php for validation
if succes viewprofile.php
else to loginpage.php (where i wish to display error message)

loginvalidation.php

$count=mysql_num_rows($result);               // mysql_num_rows will count no:of rows

if($count==1) {                               // If result matched $myusername and $mypassword, table row must be 1 row  

	session_register("$mymemberid");     // Register $mymemberid
	header("location:viewprofile.php");    // forwarded to this page
}
else {
	header("location:login.php?login=1"); // if fails in validation
}

login.php

<?php

if($_GET['login']==1)
{
	$mess_l="Invalid Credentials";
}
if($_GET['login']==2)
{
	$mess_l="Session Expire-Relogin Required";
}
?>

i'm getting warnings like this...

Notice: Undefined index: login in C:\wamp\www\SalemProject_2.0_30_12_2009_5am\SalemProject_2.0\login.php on line 3

Notice: Undefined index: login in C:\wamp\www\SalemProject_2.0_30_12_2009_5am\SalemProject_2.0\login.php on line 7

0

for login.php?login=1
and login.php?login=2 it works fine but for login.php where there is no variables passed at url there i gets problem

0

i got solution "rohitrohitrohit" thanks for your help...
the liks you send helped much more...

thanks to JRM...

i done like this...

<?php
if(isset($_GET['login'])) 
{
	if($_GET['login']==1)
	{
		$mess_l="Invalid Credentials";
	}
	if($_GET['login']==2)
	{
		$mess_l="Session Expire-Relogin Required";
	}
	echo $mess_l;
}
?>

Edited by nadnakinam: n/a

0

we use those variable for only display error...if direct login.php page call from browser i think it should process without error...
are u getting those error which u write above or something else....?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.