Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Permanent Variable
Eggie
post Sep 26 2008, 01:57 AM
Post #1


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 177
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



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...
Go to the top of the page
 
+Quote Post
faulty.lee
post Sep 26 2008, 03:52 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 500
Joined: 5-November 06
Member No.: 17,016
myCENTs:NEGATIVE[-20.12]



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.
Go to the top of the page
 
+Quote Post
Eggie
post Sep 26 2008, 02:50 PM
Post #3


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 177
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



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?
Go to the top of the page
 
+Quote Post
Eggie
post Sep 26 2008, 03:00 PM
Post #4


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 177
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



SOLVED.... lol i forgot to put session_start(); at the start of matches.php
thnx for your help faulty
Go to the top of the page
 
+Quote Post
faulty.lee
post Sep 26 2008, 03:40 PM
Post #5


Super Member
Group Icon

Group: [HOSTED]
Posts: 500
Joined: 5-November 06
Member No.: 17,016
myCENTs:NEGATIVE[-20.12]



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.
Go to the top of the page
 
+Quote Post
Eggie
post Sep 26 2008, 03:51 PM
Post #6


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 177
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



now i need to placce tooltip to a image...but without link to a page
Go to the top of the page
 
+Quote Post
toby
post Sep 26 2008, 06:44 PM
Post #7


Super Member
Group Icon

Group: Members
Posts: 540
Joined: 29-September 06
Member No.: 16,228



<a href="#" title="Here">img</a> ?
Go to the top of the page
 
+Quote Post
Eggie
post Sep 27 2008, 10:59 AM
Post #8


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 177
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



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>
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Reset The Server Variable Php_auth_user(9)
  2. Variable From Line Further Then Current Line?(13)
  3. Quickly Create Form Variables(5)
  4. Php Any Variable In String.(1)
  5. Unexpected Error(2)
  6. Send Php Variable To Javascript(5)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 03:15 PM