Jump to content

register_globals set, but no $_SESSION variables..


burnmic

Recommended Posts

Hey everyone,

 

I've also read that any script that needs to use register variables isn't coded well, so i'm looking into alternatives, however, this won't be for a while i'm sure. The issue that seems to have suddenly cropped up is that $_SESSION seems to have stopped working.. ?

 

My hosts have told me to try setting register globals to "on", this shouldn't be the case as my phpinfo file already tells me:

"register_globals local value: On master value: On"

 

I use a form to grab variables, and then use the following code set in a "referral-variables.php" file,

 

<?php
session_start();
$_SESSION['partner'] = addslashes($_REQUEST['partner']);
$_SESSION['name'] = addslashes($_REQUEST['name']);"
?>

 

This file is then used as an include on all pages where the values are required:

 

<?php include('../partners/referral-form/referral-variables.php');
session_start();
?>

 

This was working fine yesterday, but it seems to have just suddenly stopped working, but I can't seem to figure out why this may be - almost 5 hours worth of trial and error and still no joy.

 

Any help would be appreciated!

thanks a lot

mic

 

PS: i'm using lunarpages > php version 4.4.9.

Link to comment
Share on other sites

When using sessions the session_start(); MUST be the very first thing declared in a page.So change:

 

<?php include('../partners/referral-form/referral-variables.php');
session_start();
?>

 

to:

 

<?php
session_start();
include('../partners/referral-form/referral-variables.php');
?>

 

Try that.

 

Angel

Link to comment
Share on other sites

Hey Angelcool,

 

I've actually removed the "session_start()" from the pages calling the referral-variable.php via include, as i'm told that I only need to call session_start() once, and because it's in the included file it can be removed.

 

Still seem to be getting the same error:

 

Notice: Undefined index: name in /home/michae/public_html/seoblind/partners/referral-form/referral-variables.php on line 7

Notice: Undefined index: partner in /home/michae/public_html/seoblind/partners/referral-form/referral-variables.php on line 8

 

seems like the values for the variables don't exist..

 

The form i'm using to GET these variables is:

 

<table width="60%" height="100px" border="0" cellspacing="1" cellpadding="2">
<form name="partner-referral-form" id="partner-referral-form" method="get" action="seo-partner-referral-and-affiliate-result.php" />
 <tr>
       <th scope="row" class="align-right">Your Name:</th>
       <td><input type="text" name="name" /></td>
 </tr>
 <tr>
       <th scope="row" class="align-right">Partner / Business Name:</th>
       <td><input type="text" name="partner" /></td>
 </tr>
  <tr>
  		<th scope="row"></th>
       <td><input type="submit" value="create my link!" name="submit" /></form></td>
 </tr>
</table>

 

hmmm, any more ideas?

Link to comment
Share on other sites

Well, if you remove session_start(); and try to use sessions, it will just NOT work. On every PHP page you are using sessions that MUST be the first thing declared.

 

Also in order to use sessions,  register globals are not needed, in fact it is discouraged to be used (http://us3.php.net/register_globals).

 

Read this simple 3 page tutorial:

http://php.about.com/od/advancedphp/ss/php_sessions.htm

 

Also are sessions enabled?

 

Angel

Link to comment
Share on other sites

hey angel,

 

I am still calling session_start(), but i'm only calling it once by using include('referral-variables') - this file starts with session_start().  I presume that wherever I include this file, the session_start() will now be called without needed to call it on every individual page - is that correct?

 

Thanks!

Link to comment
Share on other sites

 

I am still calling session_start(), but i'm only calling it once by using include('referral-variables') - this file starts with session_start().  I presume that wherever I include this file, the session_start() will now be called without needed to call it on every individual page - is that correct

 

No, it has to be before the include.

 

Link to comment
Share on other sites

ok I tried that.

 

I removed the start_session() from the include, so my page which needs to variables from the $_SESSION then started with:

 

<?php
session_start();
include('referral-variable.php');
?>

 

This then came back with the same error, plus a "header already sent" error.

So I modified the referral-variable.php by taking out the session_start():

 

<?php
$_SESSION['name'] = addslashes($_REQUEST['name']);
$_SESSION['partner'] = addslashes($_REQUEST['partner']);
?>

 

This still came with the same error as earlier... i'm really struggling with this!

my hosts have apparently sent this to their technical dept. but I can't help but get the feeling that's an empty promise.

 

thanks again for your support here :)

Link to comment
Share on other sites

yeah, that's the impression I was under until a couple hours ago too!

somebody explained this is not the case, and so I displayed errors, ran the page again and found this:

 

"Notice: A session had already been started - ignoring session_start() in /home/michae/public_html/seoblind/partners/referral-form/referral-variables.php on line 6"

 

since then I've taken the session_start() out of the page calling the include, but just to be 100% sure I've just tried this again, and got the following error:

 

Notice: A session had already been started - ignoring session_start() in /home/michae15/public_html/seoblind/partners/referral-form/referral-variables.php on line 6

 

It seems the variable is being passed onto the form action page, but never stored to the actual session...

Link to comment
Share on other sites

Sorry Angelcool, but you are wrong on a few points in this thread. session_start() doesn't have to be at the very start of the script, it just has to be before any $_SESSION declarations, and before any HTML output. It can also exist inside of an include with no problem. So the OP had it right in the first place, as can be seen by the error he is getting now from trying to call it twice.

 

Link to comment
Share on other sites

To the OP - you should really turn off register_globals. It's a big risk. Next, try changing your code to this:

 

<?php
session_start();
$_SESSION['partner'] = addslashes($_GET['partner']);
$_SESSION['name'] = addslashes($_GET['name']);
?>

 

And see how it works. Let us know what errors come up if any.

Link to comment
Share on other sites

Hi Haku,

 

thanks for clearing that up - nice to have some clarity there :)

 

ok, so i've taken your advice, turned register globals off (although this has probably broken another project I'm sure, haha).

 

I've double checked my phpinfo and they are definitely off.

 

Also, I've change REQUEST to GET, and get the same error:

 

Notice: Undefined index: name in /home/michae15/public_html/seoblind/partners/referral-form/referral-variables.php on line 7

Notice: Undefined index: partner in /home/michae15/public_html/seoblind/partners/referral-form/referral-variables.php on line 8
echo variables here: name = | partner = 

 

The complete code for the referral-variables.php is now:

 

<?php
//reporting on errors
ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();
$_SESSION['name'] = addslashes($_GET['name']);
$_SESSION['partner'] = addslashes($_GET['partner']);
echo "echo variables here: name = ". $_SESSION['name'] ." | partner = ". $_SESSION['partner'];
?>

 

the help has been great so far, just seems none of it has resolved the issue!

I'm learning though, so grateful for that :)

 

hmm, any other ideas?

Link to comment
Share on other sites

Ok, well here is the problem. It's looking in your URL for a value of

 

?name=____&partner=____

 

And not finding them. Can you double check your URL?

 

As to why that is happening - are you sure that your are submitting your form to this page?

Link to comment
Share on other sites

Haku,

 

The form to submit is on this page: http://www.seoblind.com/partners/referral-form/seo-partner-referral-and-affiliate-information.php

 

The form action is "seo-partner-referral-and-affiliate-result.php" (which contains the include to the referral-variable.php file)

 

So on form submit you're taken to http://www.seoblind.com/partners/referral-form/seo-partner-referral-and-affiliate-result.php and at this point the variables are in the URL, and should be stored into the $_SESSION - at least that's my understanding.

 

hmm... the idea is that I want to allow partners to be able to refer traffic to my site.

 

1. A partner generates their unique link (http://www.seoblind.com/partners/referral-form/seo-partner-referral-and-affiliate-information.php).

2. They send that link to one of their clients/leads, and as a result, their client visits my site.

3. As the variable for my partner is in the url, this should then be saved to the clients session.

4. If/when that particular client then registers their interest (ie, submits their details on one of the service forms > http://www.seoblind.com/products_ser...timisation.php), there are two hidden fields, one for each variable, which are submitted with that leads.

 

This way I can track who has referred who, and reward them with their referral fees.

 

The code used to pull the value from the session variable in all lead generation forms is:

 

<input type="hidden" name="partner" value="<?php echo $_SESSION['partner']; ?>" />
<input type="hidden" name="name" value="<?php echo $_SESSION['name'] ;?>" />

 

Again, really appreciate you taking the time to look into this!

 

Link to comment
Share on other sites

I get what you are saying with all that, and I submitted something just to see what happens. The values are set in the URL and I'm not seeing the error, so I'm not sure what the problem is! It looks to be working to me.

 

Nice looking site by the way. Don't see a lot of that around here!

 

As a side point, if you have the data already included as $_SESSION variables, then you don't need to use hidden form elements. I actually never use them, because malicious users can change their values. But that's not really related to the problem at hand.

Link to comment
Share on other sites

I don't see the afore mentioned error either.

 

If this started working after register_globals were turned off, it is because all the same name program/post/get/session variables are cross-populated and overwrite each other when register_globals are ON. If one of these exists but did not have a value and it was earlier in the order in which php cross-populates the remaining variables, you end up with all empty variables with the same name.

Link to comment
Share on other sites

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.