Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-22-2004, 04:04 AM Global Variables
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Im trying to get peoples user id when they login.

There is a variable used called Username.
Just wondering if I can make it a global variable so that all pages can access the variable.

At the moment. I can display the users username on index.php and pages included in index.php.

But I cannot make it appear on any other stand alone php files.

Also, I cannot write their usernames to the database using a different php file.

Such as they fill out a form, then click send. It logs their message and their username.
I have it so the message is stored in the database but it doesnt store the usernames.

And If i declare the variable within the stand alone php file it does store the username in the database.

Thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-22-2004, 06:36 AM try setting it in a session
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
I.E

$_SESSION['user']['username'] = $username;

Of course you will have to start a session in some back end script (if you have one or just your index)

You can then build up an array of details that will be available on each page.

Ibbo
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 07-22-2004, 07:47 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
How would I go about adding that page to the session?

Thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 07-22-2004, 11:00 AM
cmonkey's Avatar
Ultra Talker

Posts: 268
Trades: 0
on your login page, if the login is successfull, start a new session:

PHP Code:
session_start();
$_SESSION['username'] = $username
Then, on each page you need to use the
PHP Code:
session_start(); 
command to make the
PHP Code:
$_SESSION['username'
variable accessable
cmonkey is offline
Reply With Quote
View Public Profile
 
Old 07-23-2004, 04:26 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thanks for your help guys.

My computer blew up for some reason... one day it was working, then the next day it wouldnt boot.. lol

So, I'll let you know how things work out

Cheers,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 07-23-2004, 11:17 AM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,611
Name: Michael (mik) Land
Location: England
Trades: 0
Lothop, you didnt by any chance have a floppy disk still in it? If not, then leave it a while (un plug everything) (a while beign a day or two) so that the memory can re-organise itself.
Did you also create a backup disk???


Mik
__________________

Please login or register to view this content. Registration is FREE
- Tumblog with thoughts, quotes, links, videos, images and my creations.

Please login or register to view this content. Registration is FREE
- The best free web browser.

Please login or register to view this content. Registration is FREE
- Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-23-2004, 12:44 PM What?
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by mik
.... leave it a while (un plug everything) (a while beign a day or two) so that the memory can re-organise itself.

Mik
What? Memory has no capacity to "reorganize" itself, particularly with the computer off.... or ever. Not sure I've ever heard advice like this before.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 07-23-2004, 01:17 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
You beat me to that one Kyrnt
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 07-26-2004, 07:25 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Try not to boot it so hard man, thems fragile things.

Ibbo
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 08-15-2004, 10:23 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Ok, I'm back

Apparently their was nothing wrong with my computer...
and that it just needed to be shipped away and to be sent back to me 2 weeks later for it to work

Annyhows..

I'm still finding it hard to get this beast to work.

Heres the lowdown.

3 files are used.

message.add.php
message.php
fuctions.php

now, it's storing the message in the database fine. But not the persons username.

Messages.php is just a simple form that people fill out.

In fuctions.php the function that is called is
PHP Code:
function addMessage($message,$username) {
        
$this->sql->Insert("INSERT INTO ".$this->TABLES['message']." SET message = '".$message."', username = '".$username."' ");
        return 
true;

  } 
message.add.php is
PHP Code:
<?php
session_start
(); 
if (
$functions->addMessage($message,$username)) { 
  
header("Location: index.php");
} else { 
  echo 
$functions->ERROR_MSG

?>
It stores the message that they typed in, but it doesn't store who wrote the message.

I can get it to display their usernames on pages, but not store it in the database. To print out their username, I have to have the code
PHP Code:
<? 
echo($_SESSION['SESS_username']);
?>
on index.php or on a page which is included into index.php.. (index.php?act=magic)

Any help would be awesome, thanks
Lothop

Last edited by lothop; 08-15-2004 at 10:26 PM..
lothop is offline
Reply With Quote
View Public Profile
 
Old 08-21-2004, 02:52 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Any help at all? Anyone? please? even if its a guess I will welcome it!

I think i have the code that cmonkey posted, placed wrong ><

Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 08-21-2004, 06:54 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
Bah, use cookies if its just for a username and password. You set them like this;

setcookie("Username",$users_username);
setcookie("Password",$users_password);

Then access them later like this;

$_COOKIE['Username']
$_COOKIE[Password]

Its simpler, cleaner, saner, and quicklyier.
All words copyright (c) webwoRRks corporation, 2004. (*cough*)
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-21-2004, 07:46 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thanks for your help, I will try
lothop is offline
Reply With Quote
View Public Profile
 
Old 08-22-2004, 02:51 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Managed to get it to work without using a session or cookie, just set the variable to the person username in the function.

Thanks for ur help
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Global Variables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43034 seconds with 12 queries