Honesty Rocks! truth rules.

Permanent Variable

HOME      >>       Programming


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

for the first line in checklogin.php and including config.php after that to save that username with
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...


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


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.
$_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
$username = $_SESSION['Username']; echo $_SESSION['Username'];

One last thing, do the following when you "Logout" the user
//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.


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


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


Glad that helps. If you need to more information, head to http://php.net/. Better still if you download the documentation, so you can search and read offline, very useful. http://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.


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


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


<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 (dynamicdrive.com;* This notice MUST stay intact for legal use* Visit http://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 neededvar vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.var ie=document.allvar ns6=document.getElementById&&!document.allfunction 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)*-1if (whichedge=="rightedge"){var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40dropmenuobj.contentmeasure=dropmenuobj.offsetWidthif (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-18dropmenuobj.contentmeasure=dropmenuobj.offsetHeightif (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=menucontentsdropmenuobj.style.left=dropmenuobj.style.top=-500if (tipwidth!=""){dropmenuobj.widthobj=dropmenuobj.styledropmenuobj.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>