Jump to content

Recommended Posts

I create a session $_SESSION['RYXQeab7']="test"......inside a function but i can't access the session from anyother page.....however if i set that same session outside the function all is well.....is there some sort of scope issues with a function....i don't know if it helps or not but the function in question is brought onto the page via a include statement........what is my problem? Thanks for your time.

Link to comment
https://forums.phpfreaks.com/topic/184719-session-inside-function-not-being-set/
Share on other sites

all the code is several hundred lines i put the relevent cod that starts the session below.

 

function setname($id){

//select username from page0.page0 where id = $id;

$_SESSION['RYXQeab7']="test";

 

$getname = mysql_query("select username from page0.page0 where activ = $id")

or die(mysql_error());

$row = mysql_fetch_array($getname);

$uname = $row['username'];

 

 

mysql_query("INSERT IGNORE INTO page0.payroll (username)VALUES('$uname')")

or die(mysql_error());

 

 

}

sorry, just combed over your post.  just assumed it was another "you just need to add session_start(); to the top of the script".

 

$_SESSION is a superglobal which means it has a global scope.  you need to make sure that the function is being called/executed for the $_SESSION to be set, and that session_start() is at the top of each script.

well it was session start the scope for session_start was weirding me out the include file has sesssion_start but i had to call it again in page that calls the function in th include file......just take me word for it it was weird and had everything to do with the way i stucture my document thanks guys..

Your code is either not calling the function to set the value (have you tried echoing something inside of the function as confirmation), is overwriting the value (have you echoed it right after the function call), you have something like a session_write_close() statement before the point where the function is being called (what is you code doing that could affect the existence of that session variable), register_globals are on (I hope not, but you should be aware if they are on and what the ramifications are of them being on) and you have a get/post/cookie or program variable by that same name, short open tags are being used in your code so that some of the php code is not really php code, your including code using a URL instead of a file system path so the results are not really what you think they are, or ...

 

There are literally a couple dozen different possible causes for the symptom, so you would really need to post the full code involved, with any included files and showing the php tags being used, for both the page you are setting the variable and the page where it does not contain the expected value.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.