Please copy this code and run on your editor and see preview, as you can see this when you type user name and press enter, it will show text type animate , these code is under javascripts.

Now I would like to change to session variable in php code or javascripts, if person log in by type the user name in "log.php" and redirect to home page "index.php" to show "Welcome [user_name]" with text type animate, how is that possible to write code in php or javascript to show text type writer in session variable in home page after they log in log.php page!

please help!

see code in bottom:


<html>
<head>
<title>Decrypting Text Effect</title>
<style>
a:visited{color:black;font-family:verdana}
a:link{color:black;font-family:verdana}
a:hover{color:blue;font-family:verdana}

td {color:black;font-family:verdana;font size:8pt}
p {color:black;font-family:verdana;font size:8pt;text-decoration: none}
h1 {color:black;font-family:verdana;font size:12pt;text-decoration: none}
</style>

<script language="javascript">
var got;
var chars;
function change()
{
var randstring = "";
var rslength = chars.length - got.length;

var decrypted = document.getElementById("decoded");
var encrypted = document.getElementById("encoded");

for(var x=0;x<rslength;x++)
{
i = Math.floor(Math.random() * chars.length);
randstring += chars.charAt(i);
}

if(randstring.charAt(0) == chars.charAt(got.length))
{
got += randstring.charAt(0);
decrypted.innerHTML = got;
}
else
{
encrypted.innerHTML = randstring;
}

if(chars.length > got.length)
{
setTimeout("change()", 10);
}
else
{
encrypted.innerHTML = "";
}
}
function startdecrypt()
{
var decrypted = document.getElementById("decoded");
var encrypted = document.getElementById("encoded");
decrypted.innerHTML = document.getElementById("firstN").value;
chars = decrypted.innerHTML;
decrypted.innerHTML = "";
got = "";
setTimeout("change()", 10);
}
</script>
</head>
<body>
Enter your name here: <input type="text" id="firstN">
<input type="button" onClick="startdecrypt()" value="Start">
<p>
<span id="decoded">Your text goes here.</span><span id="encoded"></span>
</p>
</body>
</html>

This can be performed like this:
login.php page

<?php require_once('Connections/phpForum.php'); ?>
<?php
error_reporting(E_ALL ^ E_NOTICE);
// *** 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_phpForum, $phpForum);
 
$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
 
$LoginRS = mysql_query($LoginRS__query, $phpForum) 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 );
}
}
$_SESSION['username'] = $_POST['username'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="300" border="0">
<tr>
<td>Username</td>
<td><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input name="password" type="password" id="password" /></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit" />
</div></td>
</tr>
</table>
</form>
 
</body>
</html>

The index.php page is coded like this:

<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
// For security, start by assuming the visitor is NOT authorized. 
$isValid = False; 
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
// Therefore, we know that a user is NOT logged in if that Session variable is blank. 
if (!empty($UserName)) { 
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
// Parse the strings into arrays. 
$arrUsers = Explode(",", $strUsers); 
$arrGroups = Explode(",", $strGroups); 
if (in_array($UserName, $arrUsers)) { 
$isValid = true; 
} 
// Or, you may restrict access to only certain users based on their username. 
if (in_array($UserGroup, $arrGroups)) { 
$isValid = true; 
} 
if (($strUsers == "") && true) { 
$isValid = true; 
} 
} 
return $isValid; 
}
$MM_restrictGoTo = "testingText.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { 
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo); 
exit;
}
?><html> 
<head> 
<title>Decrypting Text Effect</title> 
<style> 
a:visited{color:black;font-family:verdana} 
a:link{color:black;font-family:verdana} 
a:hover{color:blue;font-family:verdana} 
td {color:black;font-family:verdana;font size:8pt} 
p {color:black;font-family:verdana;font size:8pt;text-decoration: none} 
h1 {color:black;font-family:verdana;font size:12pt;text-decoration: none} 
</style> 
<script language="javascript"> 
var got; 
var chars; 
function change() 
{ 
var randstring = ""; 
var rslength = chars.length - got.length; 
var decrypted = document.getElementById("decoded"); 
var encrypted = document.getElementById("encoded"); 
for(var x=0;x<rslength;x++) 
{ 
i = Math.floor(Math.random() * chars.length); 
randstring += chars.charAt(i); 
} 
if(randstring.charAt(0) == chars.charAt(got.length)) 
{ 
got += randstring.charAt(0); 
decrypted.innerHTML = got; 
} 
else 
{ 
encrypted.innerHTML = randstring; 
} 
if(chars.length > got.length) 
{ 
setTimeout("change()", 10); 
} 
else 
{ 
encrypted.innerHTML = ""; 
} 
} 
function startdecrypt() 
{ 
var decrypted = document.getElementById("decoded"); 
var encrypted = document.getElementById("encoded"); 
decrypted.innerHTML = document.getElementById("username").value; 
chars = decrypted.innerHTML; 
decrypted.innerHTML = ""; 
got = ""; 
setTimeout("change()", 10); 
} 
</script> 
</head> 
<body onLoad="startdecrypt()"> 
<span id="decoded"><input name="username" type="text" value="<?php echo $_SESSION['username']; ?>"></span><span id="encoded"></span>
 
</body> 
</html>

I used a database to verify the username, restrice access to index.php based on login, and set a $_Session variable = to the $_POST
Then on index.php, I echo that varable to the screen and set the body onLoad="startdecrypt()

LOL
why should you kill your self the easiest way is to do this ....
/* index.php */
session_start();
if(isset($_SESSION)){
// this means the first session has been passed
$firstN=$_SESSION;
echo "<input type='hidden' value='$firstN' name='firstN2'>";
/* right now you ahve the pass ID=firstN2 so the same javascript in the previouse page would work for you , but there is something different you have to call the function startdecrypt() before the script TAG ends then you would be able to put the username in the span as you ca see i below please read the code and the check it didn't compile it but the idea is this piece of cake only with a hidden box*/
?>


<html>
<head>
<title>Decrypting Text Effect</title>
<style>
a:visited{color:black;font-family:verdana}
a:link{color:black;font-family:verdana}
a:hover{color:blue;font-family:verdana}

td {color:black;font-family:verdana;font size:8pt}
p {color:black;font-family:verdana;font size:8pt;text-decoration: none}
h1 {color:black;font-family:verdana;font size:12pt;text-decoration: none}
</style>

<script language="javascript">
var got;
var chars;
function change()
{
var randstring = "";
var rslength = chars.length - got.length;

var decrypted = document.getElementById("decoded");
var encrypted = document.getElementById("encoded");

for(var x=0;x<rslength;x++)
{
i = Math.floor(Math.random() * chars.length);
randstring += chars.charAt(i);
}

if(randstring.charAt(0) == chars.charAt(got.length))
{
got += randstring.charAt(0);
decrypted.innerHTML = got;
}
else
{
encrypted.innerHTML = randstring;
}

if(chars.length > got.length)
{
setTimeout("change()", 10);
}
else
{
encrypted.innerHTML = "";
}
}
function startdecrypt()
{
var decrypted = document.getElementById("decoded");
var encrypted = document.getElementById("encoded");
decrypted.innerHTML = document.getElementById("firstN").value;
chars = decrypted.innerHTML;
decrypted.innerHTML = "";
got = "";
setTimeout("change()", 10);
}
startdecrypt()
</script>
</head>
<body>

<?php
// right now do the sa
echo "Welcome User <span id="encoded"></span>"
}
else{
// redirect login page
}

/* Log in-2- page*/
<?php

/* everything is the same that you did unless you have to start a session and create session
to send to the index page as you can see in below*/
session_start();
if(isset($_POST){
$_session=$_POST;
if(/* if everything with username and password is ok then*/){
header('location:index.php');
/* so the session has been passed to the index page and you would be able to do what ever you want
*/
}
}


?>

OOoops in my previous Reply there is a little problem so you have to consider it .... in your javascript code for the index you have to this :


decrypted.innerHTML = document.getElementById("firstN2").value;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.