Jump to content

have 1 php script as a variable


MadnessRed

Recommended Posts

I am sure this is possible.

 

anyway my first script

 

<?php
$ip=$_SERVER['REMOTE_ADDR'];
$victor=xxx.xxx.x.x
$bella=xxx.xxx.x.x
$matt=xxx.xxx.x.x
$anthony=xxx.xxx.x.x

if ($ip=$anthony)
echo "Anthony"; 
elseif ($ip=$victory)
echo "Victor"; 
elseif ($ip=$bella)
echo "Bella";
elseif ($ip=$matt)
echo "Matt";
else
echo $ip;
?>

 

<?php
$myFile = $_GET["account"] . ".txt";
$fh = fopen($myFile, 'w') or die("Sorry, I messed up somewhere");
$stringData = "**~**";
fwrite($fh, $stringData);
fclose($fh);
?>

 

where it says **~** I want to add the first scripts output? How would I do that. Also is this script error free. Also I am sure that this is very open for hackers but as you can probably tell its just a simple script for a few friends where no-one will see it apart from us.

 

Thanks

 

Anthony

Link to comment
https://forums.phpfreaks.com/topic/104275-have-1-php-script-as-a-variable/
Share on other sites

<?php
$ip=$_SERVER['REMOTE_ADDR'];
$victor=xxx.xxx.x.x
$bella=xxx.xxx.x.x
$matt=xxx.xxx.x.x
$anthony=xxx.xxx.x.x

if ($ip=$anthony)
echo "Anthony"; 
elseif ($ip=$victory)
echo "Victor"; 
elseif ($ip=$bella)
echo "Bella";
elseif ($ip=$matt)
echo "Matt";
else
echo $ip;
?>

To

<?php
$ip=$_SERVER['REMOTE_ADDR'];
$victor=xxx.xxx.x.x;
$bella=xxx.xxx.x.x;
$matt=xxx.xxx.x.x;
$anthony=xxx.xxx.x.x;

if ($ip=$anthony) {
echo "Anthony"; }
elseif ($ip=$victory) {
echo "Victor"; }
elseif ($ip=$bella) {
echo "Bella"; }
elseif ($ip=$matt) {
echo "Matt";}
else {
echo $ip;}
?>

Ha beat anyone else to it :)

<?php
$ip=$_SERVER['REMOTE_ADDR'];
$victor=192.168.1.1;
$bella=192.168.1.2;
$matt=192.168.1.3;
$anthony=192.168.1.4;

if ($ip==$anthony) {
	$ipName = "Anthony"; 
} elseif ($ip == $victory) {
	$ipName = echo "Victor"; 
} elseif ($ip == $bella) {
	$ipName = "Bella";
} elseif ($ip == $matt) {
	$ipName = "Matt";
} else {
	$ipName = $ip;
}

$myFile = $_GET["account"] . ".txt";
$fh = fopen($myFile, 'w') or die("Sorry, I messed up somewhere");
$stringData = "$ipName";
fwrite($fh, $stringData);
fclose($fh);
?>

A simpler solution.

 

<?php

$users = array(
  '192.168.1.1' => 'victor',
  '192.168.1.2' => 'bella',
  '192.168.1.3' => 'matt',
  '192.168.1.4' => 'anthony'
);

if (array_key_exists($_SERVER['REMOTE_ADDR'],$users)) {
  $myFile = $_GET["account"] . ".txt";
  $fh = fopen($myFile, 'w') or die("Sorry, I messed up somewhere");
  fwrite($fh, $users[$_SERVER['REMOTE_ADDR']]);
  fclose($fh);
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.