Jump to content

[SOLVED] Passing a variable through a function?


N1CK3RS0N

Recommended Posts

Hello,

 

I was wondering if its possible to pass a variable through a function?

 

Something like this:

 

<?php

function cows($noise) {
if ($noise == moo) {
	$say = "Hi Mr. Cow";
} else {
	$say = "Your no Cow fool!";
}
}

cows('moo');

echo $say;

?>

 

The 'Echo $say;' does nothing.

Link to comment
Share on other sites

or declare a global variable. what are you trying to do?

 

I have a number of things going to be using a function. Its checking file permissions. If every file permission meets requirements then the submit button on the form works, otherwise it is disabled.

 

<?php

$pass = "true";

function check_perms($file, $perm) {
if (substr(decoct(fileperms("$file")),2) == $perm) {
	return "<div class=\"container\" style=\"color: #008000; font-weight:bold;\">Pass</div>";
} else {
	$pass = "false";
	return "<div class=\"container\" style=\"color: #D00000; font-weight:bold;\">Fail</div>";
}
}

$backups = check_perms('../backups/', '777');
$downloads_uploads = check_perms('../downloads/uploads/', '777');
$images_uploads = check_perms('../images/uploads/', '777');
$images_banners = check_perms('../images/banners/', '777');
$include_config = check_perms('../includes/config.php', '666');
$languages = check_perms('../languages/', '777');
$modules = check_perms('../modules/', '777');
$templates = check_perms('../templates/', '777');

if ($pass == 'true') {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}"\ name=\"submit\" />";
} else {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}"\ name=\"submit\" disabled=\"disabled\" />";
}

?>

Link to comment
Share on other sites

 <?php

$pass = "true";

function check_perms($file, $perm,&$pass) {
if (substr(decoct(fileperms("$file")),2) == $perm) {
	return "<div class=\"container\" style=\"color: #008000; font-weight:bold;\">Pass</div>";
} else {
	$pass = "false";
	return "<div class=\"container\" style=\"color: #D00000; font-weight:bold;\">Fail</div>";
}
}

$backups = check_perms('../backups/', '777',$pass);
$downloads_uploads = check_perms('../downloads/uploads/', '777'$pass);
$images_uploads = check_perms('../images/uploads/', '777',$pass);
$images_banners = check_perms('../images/banners/', '777',$pass);
$include_config = check_perms('../includes/config.php', '666',$pass);
$languages = check_perms('../languages/', '777',$pass);
$modules = check_perms('../modules/', '777',$pass);
$templates = check_perms('../templates/', '777',$pass);

if ($pass == 'true') {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}" name="submit\" />";
} else {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}" name="submit\" disabled=\"disabled\" />";
}

?>

 

try that

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.