Permanent Variable

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Permanent Variable

Eggie
hey all...
i need help with something..
.
i need to save a variable during login
variable is users Username
i have login.php which leads to checklogin.php to check for username/password which finnaly leads to login_success.php...
every of those include config.php

i had in mind to save that variable in config.php....
i tried that by setting
CODE
$action='a';
for the first line in checklogin.php and including config.php after that to save that username with
CODE
if($action=='a')
$uu=$_POST['username'];

i could echo username on the login_success.php page but not on matches.php
i need to echo that username in matches.php...how do i do it?

(i think it needs to be $_SESSION[] variable or something like that,but i heard that that doesnt work,please respond as soon as posssible since i never continue my work without doing something in my mind...

 

 

 


Reply

faulty.lee
Yes, you need to use session to save and use that variable across all your pages.

Call this at the start of any page that you need access session variable
CODE
session_start();


Then, you can set the variable like this, in your checklogin.php, so that when you redirect to your login_success.php, you can retrieve the Username.
CODE
$_SESSION['action']  = 'a';
    $_SESSION['Username']  = $_POST['username'];

Well, you can't actually get your username from $_POST, even if you can, it's not recommended. Try setting that with the result from your database. Normally I would just store UsernameID, because most of the other table I had are link to the User table via UsernameID. That way, I can access any table relating to that user by just referring to the ID. Better still if you store both, one for display and one for internal use.

To retrieve the session variable, use it like any global variable
CODE
$username = $_SESSION['Username'];
    echo $_SESSION['Username'];


One last thing, do the following when you "Logout" the user
CODE
//Set $_SESSION to a new array(), overwriting the old one
    $_SESSION = array();
    //Make the cookie expired if the cookie is used when you create the session
    if (isset($_COOKIE[session_name()])) {
        //Set the time of the cookie to the past, so it will expired immediately. Can't remember why I use 42000, but It was recommended by a site
        setcookie(session_name(), '', time()-42000, '/');
    }
    //Finally destry the who session information
    session_destroy();

These are done improve security of your site. Of cause you also need to touch up other section of your site in order to be fully secure.

 

 

 


Reply

Eggie
i tried it but it only shows the variable on login_success.php i dont think its stored for other pages too
do u have msn faulty?

Reply

Eggie
SOLVED.... lol i forgot to put session_start(); at the start of matches.php
thnx for your help faulty

Reply

faulty.lee
Glad that helps. If you need to more information, head to http://www.php.net/. Better still if you download the documentation, so you can search and read offline, very useful. http://www.php.net/download-docs.php. Personally i like the chm format.

Read the comment in the documentation too, sometime it's give very good tips.

Reply

Eggie
now i need to placce tooltip to a image...but without link to a page

Reply

toby
<a href="#" title="Here">img</a> ?

Reply

Eggie
CODE
<style type="text/css">

#hintbox{ /*CSS for pop up hint box */
position:absolute;
top: 0;
background-color: lightyellow;
width: 150px; /*Default width of hint.*/
padding: 3px;
border:1px solid black;
font:normal 11px Verdana;
line-height:18px;
z-index:100;
border-right: 3px solid black;
border-bottom: 3px solid black;
visibility: hidden;
}

.hintanchor{ /*CSS for link that shows hint onmouseover*/
font-weight: bold;
color: navy;
margin: 3px 8px;
}

</style>

<script type="text/javascript">

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
        
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

</script>

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Recent Queries:-
  1. not permanent logout code in java script - 27.45 hr back. (1)
  2. not permanent logout code in php - 27.51 hr back. (1)
  3. php permanent variable - 98.80 hr back. (1)
  4. set permanent variable in access - 135.05 hr back. (1)
  5. php store permanent information - 145.11 hr back. (1)
  6. javascript permanent variables - 148.75 hr back. (1)
  7. changing session variables to permanent ones - 348.07 hr back. (1)
  8. javascript permanent variable - 368.82 hr back. (1)
  9. how to give permanent variables in php - 373.63 hr back. (1)
  10. permanent variable - 382.75 hr back. (1)
  11. how to make a variable permanent - 424.15 hr back. (1)
  12. how to set permanent user variable - 437.71 hr back. (1)
  13. permanent variables in php - 441.35 hr back. (1)
  14. how to save a variable in php after a new _post - 572.08 hr back. (1)
Similar Topics

Keywords : permanent, variable

  1. Send Php Variable To Javascript
    (5)
  2. Unexpected Error
    Undefined variable??? (2)
    Is this script correct? index.php : CODE     if (isset($_COOKIE ))           $_GET =
    $_COOKIE ;     else         setcookie("disp_name", Anonymous, date()+99); ?>              
    Display Name - DZN                                                                   
                    Dislpay Name: name="name" />                                                
         proccess.php : CODE      Proccessing Request...           Please wait...
        setcookie("disp_name", $_GET , date()+99); ?> main.php : CODE     function customErr....
  3. Php Any Variable In String.
    (1)
    OK well I am making a new php program and I am trying to add bbcode to it. Anyway I was going to
    replace each thing by it self, but that could cause errors. Anyway is there a way to make a variable
    be anything? Here is an example: CODE This is the bbcode: Hey In my php: $bbcode = array(" ");
    $html = array( " "); $topic_content = str_replace($bbcode, $html, $posted_bbcode); So I want $a
    to be any variable but the same variable as used before. Do you get what I am saying? It is a little
    confusing but basicly what is the best way to make bbcode? It may not even inv....
  4. Quickly Create Form Variables
    simple form, variable creation, referer check, safe guard variables (5)
    The reason I wanted to share this is I've seen so many people do this with their forms when
    using PHP. CODE $username = $_POST ; $password = sha1($_POST ); $another_var = $_POST ; ...
    and so on, just imagine if you had a large number of form inputs, do you really want to create each
    and every variable name? Why people do this, is probably due to most of the examples I've seen
    on the web, that does not show an easier and much quicker way of doing it. Though my way might be
    much easier and quicker, it does introduce security concerns which I've tried....
  5. Variable From Line Further Then Current Line?
    (13)
    Hello, Is it in some way possible to load a variable that further then the current line in the
    script? I don't know if you know what i mean so I'll try to point it out in the script
    below. CODE 1 2      echo $var1; 3      # $var1 needs to be loaded from foo.php 4     # Lets
    say i want $var1 to be echoed in $var1 5       - - - -       bla bla bla 55      - - - -
    56      switch($_GET ) { 57          case "foo": 58              include("foo.php");
    59              #- - - - from foo.php - - - - 60                   $var1 = "what ever you want";
    61           ....
  6. How To Reset The Server Variable Php_auth_user
    (9)
    Hi, i'm developing a web application which obviously requires a log in/log out script that i
    just implementing but i dont know why the log out script dont work fine. The problem is related
    with the server variable $_SERVER which remains set even when in the log out script i unset it with
    the unset() function. Does someone knows how can i reset or clear the server variable $_SERVER ???
    Best regards, ....
  7. Help: $_post Variable For Options From Select Types?
    (6)
    I want to know if there is a way to get the variables in $_POST for the options (not just the
    selected ones, but the unselected ones as well) of a type. Objective: Creating an application for
    my school. Issue: I am successful in receiving all the variables from the forms except the ones
    added to the options of a type. Just wanted to know what is the variable to access the options of
    types. Here is what I am trying to do with it: View Page If the server is down or unable to
    load file, here is the script: CODE      Malden High School va....
  8. Php Variable Concatenation
    Something New I learned Today! :P (7)
    I was coding one of my php page today, when I realized that I had to add multiple values to a
    variable (now that I think of it, a solution with arrays is possible too). But, the problem is that
    I have to add them in different parts of the code, so the new line that defines the variable will
    cover up the previous one. I played around with the code, and I finally got this solution:
    $message = "test1"; $message .= "test2"; $message .= "test3"; echo $message; By adding a dot in
    front of the = sign, I could concatenate the previous value with the new one and put them i....

    1. Looking for permanent, variable






*SIMILAR VIDEOS*
Searching Video's for permanent, variable
advertisement




Permanent Variable