[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 12-17-2006, 06:11 PM   #1 (permalink)
NamePros Regular
 
timmaay's Avatar
 
Join Date: Dec 2005
Location: up north
Posts: 578
48.35 NP$ (Donate)

timmaay is just really nicetimmaay is just really nicetimmaay is just really nicetimmaay is just really nicetimmaay is just really nice

Child Abuse
new to PHP ... coming from ASP

well i am new to PHP and have a quick question

in ASP you have a global.asa which you can set and reference a session var.

for example:

sub session_onstart()
session("ip") = request.servervariables("REMOTE_ADDR")
end sub

now whenever someone hits any page on my site i have a session("ip") variable i can reference.

I need to do this same thing in php.
(ie) i only want to load this variable once from whatever page user enters on and be able to reference it on any subsequent pages.

keep in mind: I am a novice at php

thanks in advance

Tim
__________________
Wisconsin Apartment Listings
timmaay is offline  
Old 12-17-2006, 06:15 PM   #2 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
PHP Code:
session_start();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
So anywhere within PHP, you could do echo $_SESSION['ip']; and it would have the IP stored in it. (I'm not sure what the sub stuff is, so I don't know if this does everything you asked. :x)
Dan is offline  
Old 12-17-2006, 06:15 PM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
 
Join Date: Aug 2005
Location: Web 1.0
Posts: 6,285
1,095.94 NP$ (Donate)

sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute

Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer
It ain't difficult
PHP Code:
<?php
session_start
();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
?>
__________________
Buy now - MassDeveloper.com $500
sdsinc is online now  
Old 12-17-2006, 06:20 PM   #4 (permalink)
NamePros Regular
 
timmaay's Avatar
 
Join Date: Dec 2005
Location: up north
Posts: 578
48.35 NP$ (Donate)

timmaay is just really nicetimmaay is just really nicetimmaay is just really nicetimmaay is just really nicetimmaay is just really nice

Child Abuse
basically asp has a special file called global.asa
this file has a few functions in it and one of them is
Sub session_onstart()

this function runs whenever someone first comes to the site

ex)
person A google searches and clicks on a link to mypageA.asp
then goes to mypageB.asp ...
before he hits mypageA.asp -> session_onstart() function runs.
when he then goes to mypageB.asp session_onstart() function doesn't run because it was invoked before mypageA.asp already.

basically it makes it so i don't need to include a file on top of every page
__________________
Wisconsin Apartment Listings
timmaay is offline  
Old 12-17-2006, 06:33 PM   #5 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
Well you need to have session_start(); on every page (that you need the variables), but the variables will still be saved.
Dan is offline  
Old 01-03-2007, 11:54 AM   #6 (permalink)
Account Closed
 
shahzad11's Avatar
 
Join Date: Nov 2006
Location: Lahore
Posts: 297
86.65 NP$ (Donate)

shahzad11 is on a distinguished road


Quote:
Originally Posted by sdsinc
It ain't difficult
PHP Code:
<?php
session_start
();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
?>
thanks very much because i was having a great problem and you solved it
shahzad11 is offline  
Old 01-03-2007, 04:19 PM   #7 (permalink)
NamePros Regular
 
Noobie's Avatar
 
Join Date: Feb 2006
Location: Montreal, Quebec, Canada
Posts: 324
66.75 NP$ (Donate)

Noobie is on a distinguished road


Glad you switched
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:41 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85