Jump to content

Recommended Posts

I have a form that currently sends the data entered (username/password) back to the same page as such:

<form class="login" action="" method="post">

This is so I can validate login at the top of the page etc.

 

Now what I want it to also do is to post the data to the next page AS WELL, as I want to be able to use the username on the next page (Welcome $user!) (well, more complicated than this but you get the idea)

 

Is this possible at all?

I have a form that currently sends the data entered (username/password) back to the same page as such:

<form class="login" action="" method="post">

This is so I can validate login at the top of the page etc.

 

Now what I want it to also do is to post the data to the next page AS WELL, as I want to be able to use the username on the next page (Welcome $user!) (well, more complicated than this but you get the idea)

 

Is this possible at all?

 

Not without using JavaScript.  Thankfully, what you want to do is rather simple to execute using sessions.  Google 'PHP sessions' to get started.

so what's the point in sending the data to some validation script if you want to at the same time send it straight to some other page to be used?  Send the data to your validation script. Validate it.  Put it in a session var as Night suggested. Redirect to new page.  And they lived happily ever after.  The end.

 

Hmm I'm pretty sure thats what I am doing, I just can't seem to get it out of the session. Starting to think I might be stupid! (please dont answer that hah)

 

Right, top of login.php checks to see if it's there and then uses the posted data in $pupils validate_user function.

 

if($_POST && !empty($_POST['username']) && !empty($_POST['password'])) {
$response = $pupils->validate_user($_POST['username'], $_POST['password']);		

 

and the validate_user function from pupils.php

function validate_user($user,$pass){
	$mysql = new connect();
	$ensure_credentials = $mysql->verify_user_pass($user, $pass);

	//If ensure_credentials holds true then status is authorised and user is sent to the index page
	if($ensure_credentials){
		$_SESSION['status'] = 'authorised';
		header("location: index.php");
	} else return "Please enter a correct username and/or password!";

}

 

 

Now the log in works and the athentication works, but what would I type on another page (say images.php) to use just the username from this session?

if($ensure_credentials){
         $_SESSION['status'] = 'authorised';
         $_SESSION['user'] = $user;
         header("location: index.php");
      } else return "Please enter a correct username and/or password!";

 

index.php

<?php
  session_start();
  echo $_SESSION['user'];
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.