Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Darrell3831
Worker
Worker



Joined: Feb 18, 2004
Posts: 244

PostPosted: Fri Feb 09, 2007 4:51 pm Reply with quote

Hi,

I'm trying to pass a value from one function in a file (index.php) right back to the same file like this:

Code:
echo ("<tr><td><a href=\"index.php?op=2&amp;did=$did\">$division_name</a></td></tr>");



At the top of index.php I'm switching based on the value in $op like this:

Code:
if (!isset($op)) {

   $op=1;
}


switch ($op) {
   case 1:
      division_menu();
      break;
   case 2:
      branch_menu($did);
      break;
   case 3:
      station_menu($bid);
      break;
   case 4:
      station_report($sid, $number);
      break;
   default:
      division_menu();
      break;
}


It randomly works, and then all of a sudden dosent work.... The value held in $op is not reliably set as I would expect.

Apperantly I am not doing something right.

Could someone explain to me how to pass this value reliably from a function back like I'm trying to do.. Or tell me another way perhaps?

Maybe there is some sort of global keyword or something that I must set to catch the $op?

Thanks for any help that will point me in the right direction.

Darrell

_________________
http://www.psy-center.com 
View user's profile Send private message Visit poster's website
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Feb 09, 2007 6:04 pm Reply with quote

Well, you have to look at each of those functions and how is the value of op getting valued on your link. For example, if it is hard-coded within each of the functions, then this would be working. However, if say you had a variable called $opValue that was being used, you have to trace back where that is getting set. It either must be set in your function, passed within the function call, OR declared within the function as global.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Darrell3831







PostPosted: Fri Feb 09, 2007 6:30 pm Reply with quote

I don't know what I'm doing. lol

They are hard coded... It says op=2.... But that isent the variable itself.

Must they also be set independantly? $op=2; ?

at the top of each individual function I have this:

global $db, $op;


thanks!
 
Darrell3831







PostPosted: Sat Feb 10, 2007 7:02 am Reply with quote

This is the smallest of the 5 functions. (I know there is no security in it just yet)

Code:
function branch_menu($did) {

   global $db, $op;

   echo ("<h2>Choose a Branch</h2>");
   
   $branch = $db->sql_query("select * from rm_fsgbranch where did=$did order by branch_name");
      echo ("<table><tr><td>Branch Name</td></tr>");
      while (list($bid, $did, $branch_name) = $db->sql_fetchrow($branch))
      {
         echo ("<tr><td><a href=\"index.php?op=3&amp;bid=$bid\">$branch_name</a></td></tr>");
       }
      echo ("</table>");      
}


If I can't build a clickable link like this:

Code:
echo ("<tr><td><a href=\"index.php?op=3&amp;bid=$bid\">$branch_name</a></td></tr>");



Is there another way to build a clickable link that simply calls a function??

I don't understand the mechanism that passes the argument so I don't know what is wrong. I havent been able to find any examples in any of my books or online either.

Thanks for any thing that points me in the right direction. Even the proper terminology will help with online searches.

Darrell
 
montego







PostPosted: Sat Feb 10, 2007 8:44 am Reply with quote

I am guessing that you are also not getting the $did valued either. The code that you PM'd me looks just fine to me. I have a feeling that register_globals is turned off. I see that this is a standalone script. If this was PHP-Nuke, it would have taken care of that.

I would not turn register_globals on as it adds to your security risk. Since these are coming in off a link, you could use the following instead of the variables that you have:

$_GET['op']
$_GET['did']

etc...

What I do is do something like this:

if (isset($_GET['op']) {
$op = intval($_GET['op']);
} else {
$op = 1;
}

By the way, I added the intval() function around your 'op' as a little extra sanitization of this seemingly integer valued variable.
 
Darrell3831







PostPosted: Sat Feb 10, 2007 11:02 am Reply with quote

Thank you!!

Using this:
Code:
if (isset($_GET['op'])) { 

$op = intval($_GET['op']);
} else {
$op = 1;
}

if (isset($_GET['did'])) {
$did = intval($_GET['did']);
}

if (isset($_GET['bid'])) {
$bid = intval($_GET['bid']);
}

if (isset($_GET['sid'])) {
$sid = intval($_GET['sid']);
}

if (isset($_GET['cid'])) {
$cid = intval($_GET['cid']);
}


Cleared up all my troubles.

What does phpNuke do that dosent make you have to do this in a nuke module??
 
montego







PostPosted: Sun Feb 11, 2007 11:23 am Reply with quote

Awesome!

Nuke uses the following to "import" the globals:

if (!ini_get('register_globals')) {
@import_request_variables('GPC', '');
}

But, I do not recommend it. It is more proper and more secure to access the PHP superglobals $_GET and $_POST (and there are a few others).
 
Darrell3831







PostPosted: Sun Feb 11, 2007 1:25 pm Reply with quote

thanks!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©