Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-26-2007, 02:26 PM VariableFile Editor
Novice Talker

Posts: 13
Name: hach22
Trades: 0
VariableFile Editor V0.1
PHP Code:
<?php
/**
 * @Author H22CREATIONS
 * @Copyright 2007
 */
/***************************
* VariableFile Editor 0.1
* Released under the Beerware licence :P
* Dicussion in http://www.webmaster-talk.com/php-forum/114008-variablefile-editor.html
****************************/

/***************************
* Config
****************************/
$var_file='variables.php';
$backup_file='variables.bak.php';//FALSE to disable
/***************************
* htmlentities($var_file)
****************************/
$var_file_hehtmlentities($var_file);
/***************************
* Header of the page
****************************/
echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>'
;
/***************************
* Recieving Variables
****************************/
if (!empty($_POST)){
    
var_dump($_POST);
    if (!
is_writable($var_file)){
        die(
htmlentities($var_file).' is not writable');
    }
    
//if get_magic_quotes_gpc {stripslashes} thanks webmaster[ at ]kevinjb.com
    
if (get_magic_quotes_gpc()) {
        function 
stripslashes_array($array) {
            return 
is_array($array) ? array_map('stripslashes_array'$array) : stripslashes($array);
        }
    
        
$_COOKIE stripslashes_array($_COOKIE);
        
$_FILES stripslashes_array($_FILES);
        
$_GET stripslashes_array($_GET);
        
$_POST stripslashes_array($_POST);
        
$_REQUEST stripslashes_array($_REQUEST);
    }
    
$statue= ($backup_file!==FALSE) ? copy($var_file,$backup_file) : TRUE;
    if (!
$statue) die('<div>Cannot backup (CHMOD this folder to 777)</div>');
    
$handle fopen($var_file,'w');
        
fwrite($handle,"<?php\n");
        foreach (
$_POST as $n=>$v){
            
$v=html_entity_decode($v);
            
fwrite($handle,"\t$n = $v;\n");
        }
    
fclose($handle);
}
/***************************
* Get the file
****************************/
$variables=file_get_contents($var_file);
/***************************
* Get the variables
****************************/
//REGEX (\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\]\[]*)[ \r\n]*=[ \r\n]*('.*;.*'|".*;.*"|.*?);
$pattern='/(\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\]\\[]*)[ \\r\\n]*=[ \\r\\n]*(\'.*;.*\'|".*;.*"|.*?);/';
preg_match_all($pattern$variables,$variables_a);
(
count($variables_a[1])===count($variables_a[2])) || DIE('ERROR');

/***************************
* Get the HTML Form
****************************/
$count=count($variables_a[1]);
echo 
'<h3><div style="text-align:center">';
switch (
$count){
    case 
0:
        
$msg'No Variable Found in '.$var_file_he;
        die;
    case 
1:
        
$msg'One Variable Found in '.$var_file_he;
    break;
    default:
        
$msg$count.' Variables Found in '.$var_file_he;
    break;

echo 
'<script language="JavaScript">
document.title = "'
.$msg.'";
</script>'
;
echo 
$msg.'</div></h3>';
echo 
'<form method=post action="editor.php">';
echo 
'<table border="1" align="center">';
$count=count($variables_a[1]);
for(
$i=0;$i<$count;$i++){
    
$name=htmlentities($variables_a[1][$i]);
    
$value=htmlentities($variables_a[2][$i]);
    echo 
'<tr><td><u>'.$name.'</u> = <td>'.'<input type=text name='.$name.' value="'.trim($value).'"><br>';
}
echo
'<tr><td colspan=2 align=center><input type=submit value=Change></table>
</form>
</body></html>'
;
Latest Version http://www.webmaster-talk.com/php-fo...tml#post517325

Last edited by hach22; 12-27-2007 at 03:20 PM.. Reason: Added * Dicussion in http://w...... ;Added "last version...";Changed Email Address
hach22 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-26-2007, 02:42 PM Re: VariableFile Editor
Novice Talker

Posts: 13
Name: hach22
Trades: 0
The script is written to edit variable-only files with no much complications in its syntax.
(sorry I have a bad English)
hach22 is offline
Reply With Quote
View Public Profile
 
Old 12-26-2007, 10:53 PM Re: VariableFile Editor
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Um, your script raises some questions:

1) stripslashes_array is not a PHP function.
2) Content Relevant URLs by vBSEO 3.0.0 &copy;2007, Crawlability, Inc. and yet you're copyrighting it?
3) Why set the title using javascript? You're outputting the whole page.
4) You've included some dude's email address which is likely to increase his spam - will he appreciate that?
5) Exactly why did you include this?
Quote:
<script type="text/javascript">
_uacct = "UA-139461-1";
urchinTracker();
</script>
...

The list of questions could go on, but I just don't get what it is you're trying to accomplish here.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE

Last edited by JeremyMiller; 12-26-2007 at 10:55 PM..
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-27-2007, 03:01 PM Re: VariableFile Editor
Novice Talker

Posts: 13
Name: hach22
Trades: 0
Quote:
1) stripslashes_array is not a PHP function.
PHP Code:
function stripslashes_array($array) {
            return 
is_array($array) ? array_map('stripslashes_array'$array) : stripslashes($array);
        } 
stripslashes_array is not a PHP function but It's declared. It stripslashes of all Global _Arrays(recursive).
Quote:
2) Content Relevant URLs by vBSEO 3.0.0 &copy;2007, Crawlability, Inc. and yet you're copyrighting it?
5) Exactly why did you include this?
Quote:
<script type="text/javascript">
_uacct = "UA-139461-1";
urchinTracker();
</script>
I don't know how the hell that's inserted there.
Quote:
3) Why set the title using javascript? You're outputting the whole page.
Yes you're right...
Quote:
4) You've included some dude's email address which is likely to increase his spam - will he appreciate that?
"likely to increase his spam" Absolutely not true...
Sorry I removed IT

Last edited by hach22; 12-27-2007 at 03:15 PM.. Reason: Added "recursive"
hach22 is offline
Reply With Quote
View Public Profile
 
Old 12-27-2007, 03:09 PM Re: VariableFile Editor
Novice Talker

Posts: 13
Name: hach22
Trades: 0
PHP Code:
<?php
/**
 * @Author H22CREATIONS
 * @Copyright 2007
 */
/***************************
* VariableFile Editor 0.1.1
* Released under the Beerware licence :P
* Dicussion in http://www.webmaster-talk.com/php-forum/114008-variablefile-editor.html
****************************/

/***************************
* Config
****************************/
$var_file='variables.php';
$backup_file='variables.bak.php';//FALSE to disable
/***************************
* htmlentities($var_file)
****************************/
$var_file_hehtmlentities($var_file);
/***************************
* Header of the page
****************************/
echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
'
;
/***************************
* Recieving Variables
****************************/
if (!empty($_POST)){
    
    if (!
is_writable($var_file)){
        die(
htmlentities($var_file).' is not writable');
    }
    
//if get_magic_quotes_gpc {stripslashes} thanks webmaster [ *at* ] kevinjb.com
    
if (get_magic_quotes_gpc()) {
        function 
stripslashes_array($array) {
            return 
is_array($array) ? array_map('stripslashes_array'$array) : stripslashes($array);
        }
    
        
$_COOKIE stripslashes_array($_COOKIE);
        
$_FILES stripslashes_array($_FILES);
        
$_GET stripslashes_array($_GET);
        
$_POST stripslashes_array($_POST);
        
$_REQUEST stripslashes_array($_REQUEST);
    }
    
$statue= ($backup_file!==FALSE) ? copy($var_file,$backup_file) : TRUE;
    if (!
$statue) die('<title>VariableFile Editor - Error</title></head><body><div>Cannot backup (CHMOD this folder to 777)</div></body></html>');
    
$handle fopen($var_file,'w');
        
fwrite($handle,"<?php\n");
        foreach (
$_POST as $n=>$v){
            
$v=html_entity_decode($v);
            
fwrite($handle,"\t$n = $v;\n");
        }
    
fclose($handle);
    echo 
'<title>VariableFile Editor - File successfully edited</title>
    </head>
    <body>'
;
}
/***************************
* Get the file
****************************/
$variables=file_get_contents($var_file);
/***************************
* Get the variables
****************************/
//REGEX (\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\]\[]*)[ \r\n]*=[ \r\n]*('.*;.*'|".*;.*"|.*?);
$pattern='/(\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\]\\[]*)[ \\r\\n]*=[ \\r\\n]*(\'.*;.*\'|".*;.*"|.*?);/';
preg_match_all($pattern$variables,$variables_a);
(
count($variables_a[1])===count($variables_a[2])) || DIE('ERROR');

/***************************
* Get the HTML Form
****************************/
$count=count($variables_a[1]);

switch (
$count){
    case 
0:
        
$msg'No Variable Found in '.$var_file_he;
        die;
    case 
1:
        
$msg'One Variable Found in '.$var_file_he;
    break;
    default:
        
$msg$count.' Variables Found in '.$var_file_he;
    break;
}
echo 
'<title>'.$msg.'</title>
</head>
<body>'
;
echo 
'<h3><div style="text-align:center">'.$msg.'</div></h3>';
echo 
'<form method=post action="editor.php">';
echo 
'<table border="1" align="center">';
$count=count($variables_a[1]);
for(
$i=0;$i<$count;$i++){
    
$name=htmlentities($variables_a[1][$i]);
    
$value=htmlentities($variables_a[2][$i]);
    echo 
'<tr><td><u>'.$name.'</u> = <td><input type=text name='.$name.' value="'.trim($value).'">';
}
echo
'<tr><td colspan=2 align=center><input type=submit value=Change></table>
</form>
</body></html>'
;
Release Note:
* Deleted unnecessary javascript.
* Added some HTML to improve page title.
* Changing The email address to avoid spamming.

Last edited by hach22; 12-27-2007 at 03:13 PM.. Reason: Release Note added
hach22 is offline
Reply With Quote
View Public Profile
 
Old 12-28-2007, 02:37 PM Re: VariableFile Editor
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Content Relevant URLs by vBSEO 3.0.0 &copy;2007, Crawlability, Inc. and yet you're copyrighting it?


<script type="text/javascript">
_uacct = "UA-139461-1";
urchinTracker();
</script>
Somewhere along the way you must have done a copy and paste from the source of a post here at this very forum and maybe edited out some bits.

UA-139461-1 is the GoAn account reference for this very forum, and the copyright line is from the vBSEO mod for vBulletin.

(look at the bottom of the page in source view)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to VariableFile Editor
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.10237 seconds with 12 queries