Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Carry Variable Across Pages

Featured Replies

Hi All,

 

After a user logs into my website, i would like to echo there name.

 

I know you post and get from one page to another, but i have a page in the middle that validates there login.

 

this is my logon form so far:

 

<form action="<?php echo $loginFormAction; ?>" method="post" id="authorisation-check">
	<table width="400" border="0" align="center" cellpadding="3" cellspacing="0" class="table" id="table">
	  <tr>
		<th class="aligncenter whitetext" colspan="2">Please Enter Your Username And Password</th>
	  </tr>
	  <tr>
		<th align="right" class="spec">Username:</th>
		<td align="left"><input type="text" name="username"  id="username" /></td>
	  </tr>
	  <tr>
		<th align="right" class="specalt">Password:</th>
		<td align="left"><input name="password" type="password" id="password" /></td>
	  </tr>
	  <tr>
		<th align="right" class="spec"> </th>
		<td align="left"><input name="Submit" type="submit" class="button" value="Login" /></td>
	  </tr>
	</table>
  </form>

 

If their login details are correct it forwards them to a menu.

You could send the username in the URL and then use the $_GET method on the other page to find out what the username is.

On the page where you process their log in , assign session variables for that user. You can then access the $_SESSION array on other pages.

  • Author

i lied there is only two pages:

 

login.php and menu.php

 

but instead of the form on login.php posting to menu.php it does the following:

 

<form action="<?php echo $loginFormAction; ?>" method="post" id="authorisation-check">

 

$loginFormAction is on the same page.

 

<?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['username'])) {
 $loginUsername=$_POST['username'];
 $password=$_POST['password'];
 $MM_fldUserAuthorization = "";
 $MM_redirectLoginSuccess = "index.php";
 $MM_redirectLoginFailed = "login.php";
 $MM_redirecttoReferrer = false;
 mysql_select_db($database, $connection);

 $LoginRS__query=sprintf("SELECT username, password FROM users_tbl WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

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

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

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

header("Location: ". $MM_redirectLoginFailed );
 }
}
?>

just set a session somewhere

 

 

$_SESSION['name'] = $_POST['name'];

 

 

 

 

echo $_SESSION['name']

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.