Unstoppable Domains

New to PHP ... coming from ASP

Spaceship Spaceship
Watch

timmaay

Established Member
Impact
22
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
PHP:
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)
 
0
•••
It ain't difficult :blink:
PHP:
<?php
session_start();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
?>
 
0
•••
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
 
0
•••
Well you need to have session_start(); on every page (that you need the variables), but the variables will still be saved.
 
0
•••
sdsinc said:
It ain't difficult :blink:
PHP:
<?php
session_start();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
?>

thanks very much because i was having a great problem and you solved it
 
0
•••
Glad you switched
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back