PHP - Php Write To Server Commands And Mod_security
I'm reworking a script to write a file in one directory to write another file in a second directory. This works on my testing machine. My shared host, however, is not taking to some of these
Similar TutorialsAlways humbling to be knocked on your arse by what you think would be so easy... How can I run a std mysql_query command like this from cron? $query_insert_new = mysql_query("INSERT INTO members (ID, name, date)VALUES (NULL,'$new_name',CURDATE())"); It is a long time since I firstt learnt how to access mysql from the command line via pUTTY or cmd... However I never learnt how to write a php script in the same fashion... I have configured cron to run correctly and the script runs. After testing however I was wondering how my database was not getting updated... then i realised I must have to enter the commands as if command line... I tried but don't know where to start. Do I have to connect to the database in the same fashion you do in cli: mysql -u username -p password ? This is my script. The idea is to cycle every 7 days and write over old files. It is very simple, but all i need. The table has 3 fields, ID name date. <?php $db_username = "username"; $db_password = "password"; $db_hostname = 'localhost'; $db_database = 'databasename'; //first log into the database $db_server = mysql_connect($db_hostname, $db_username, $db_password); //selecting databse mysql_select_db($db_database, $db_server); //now get the latest entry in the table 'database_backup_info' $query_latest_entry = mysql_query("SELECT name FROM database_backup_info ORDER BY ID DESC LIMIT 1 "); //if there are results in the table if(mysql_num_rows($query_latest_entry)>0) { //retrieving the info $query_latest_entry_row = mysql_fetch_assoc($query_latest_entry); //now determine the new file number based on the last entry if($query_latest_entry_row['name'] + 1 > 7) { $new_name = $query_latest_entry_row['name'] + 1; } else { $new_name = 1; } //insert the entry into the db $query_insert_new = mysql_query("INSERT INTO members (ID, name, date) VALUES (NULL,'$new_name',CURDATE())"); } //if no results then this will be the first entry else{ $new_name = 1; //insert the entry into the db $query_insert_new = mysql_query("INSERT INTO members (ID, name, date) VALUES (NULL,'$new_name',CURDATE())"); } //creating the file path and name $db_backupFile= dirname(__FILE__).'/sql_files/'.$new_name.'.sql'; //the mysql dump command $command = "mysqldump -u$db_username -p$db_password -h$db_hostname $db_database > $db_backupFile"; //running the mysql_dump command system($command, $result); ?> Hey guys i am writing a code which will get data frm the user and then write a file in my server and well sadly i am really confused with the annoying errors and warnings i am getting please help here is my code <?php //This File Gets the data from the chat setup form and then writes the chat file or edits it //Get Data from the form $cname=$_POST['cname']; $nicklen=$_POST['nicklen']; $msglen=$_POST['msglen']; $pm=$_POST['pm']; $msgh=$_POST['msgh']; $aname=$_POST['aname']; $pass=$_POST['pass']; $cheight=$_POST['cheight']; $cwidth=$_POST['cwidth']; $prcadmin=$_POST['prcadmin']; $cas=$_POST['cas']; $frznick=$_POST['frznick']; $sm=$_POST['sm']; $id=$_COOKIE["id"]; //Check if the cookie id is empty if (!isset($id)) { header( 'Location: www.techbreeze.in/mychat/chat-add.html') ; } //Check if any field is empty and redirect to setup page if empty if ((isset($cname))&&(isset($nicklen))&&(isset($msglen))&&(isset($pm))&&(isset($msgh))&&(isset($aname))&&(isset($pass))&&(isset($cheight))&&(isset($cwidth))) { if ((is_numeric ($nicklen)) && (is_numeric ($msglen))&&(is_numeric($pm))&&(is_numeric($msgh))&&(is_numeric ($cheight))&&(is_numeric ($cwidth))) { //Start writting data into the file $str1=";"; $str2 = ".php"; $str4 = "\n"; $File = $id . $str2; $fh = fopen($File, 'w') or die("can't open file"); $stringData = "<?php\n"; fwrite($fh, $stringData); $strt1= "require_once /mychat/src/phpfreechat.class.php;\n"; $stringData = $strt1; fwrite($fh, $stringData); $strt1='$params["serverid"] ='; $stringData = $strt1 . $id . $str1 . $str4; fwrite($fh, $stringData); fclose($fh); $strt3 = "$params"; $stringData = $strt3; fwrite($fh, $stringData); fclose($fh); } else { echo "Only numeric Inputs allowed for the fields"; echo "<br><br><br>"; echo "Enter the maximum length of nick"; echo "<br>"; echo "Maximum Lenth of message"; echo "<br>"; echo "Max number of Simultaneous PM"; echo "<br>"; echo "No. of msg to be stored in history"; echo "<br>"; echo "Height of the Chat Room"; echo "<br>"; echo "Width of Chat Room"; echo "<br><br><br>"; echo "Please Fill them up Carefully!"; echo "<meta HTTP-EQUIV='REFRESH' content='6; url= http://www.techbreeze.in/chat-setup.html'>"; } } else { echo "You Have one or more incomplete Field"; echo "<br>"; echo "Please Fill them up Carefully!"; echo "<meta HTTP-EQUIV='REFRESH' content='2; url= http://www.techbreeze.in/chat-setup.html'>"; } ?> ok now the error i am getting is Quote Warning: fclose(): 3 is not a valid stream resource in /home/techbr/domains/techbreeze.in/public_html/mychat/chatcreate.php on line 52 Any ideas as to what i should do and why i am getting this error. Im having trouble with this wondering if someone could help me out please if (isset($_POST['escape'])) { || if (isset($_POST['suicide'])) { its giving me a error on the || im writing it so that one or the other has to happend. is this the correct way to use this? Hi, I am trying to create a PHP script ("repair-correct.php") in order to run some CLI commands without using PuTTy - The CLI commands are needed to repair/correct the execution of a web application named Mautic. Shared web host account with PHP 7.0 URL: https://www.myserver.com Mautic directory: https://www.myserver.com/mautic
What I want to do is:
Step1: Change ownership of files and folders To find out which user Apache is running as, I want to execute the following command and take note of the first entry in the line which is returned: ps aux | grep apache2 I want to use this information to find the groups with the following command groups apache_user (where apache_user is the user I identified from the first step above) To reset the ownership of files and folders, I want to use the following command (ensuring that I replace apache_user and apache_group with the values identified in the steps above): sudo chown -R apache_user:apache_group With this command I want to change ownership, using the -R flag which means recursively - including all files/folders within that location.
Step 2: Reset the file and folder permissions
find . -type f -not -perm 644 -exec chmod 644 {} +
Thanks so much for your help in solving this problem!
Best, Tony
How can i switch between the 2 lines below in my function. At the moment the bottom line is ignored: /* Determine if user is logged in */ $this->logged_in = $this->checkLogin(); /* Determine if client is logged in */ $this->logged_in_Client = $this->checkLoginClient(); Code: [Select] function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session /* Determine if user is logged in */ $this->logged_in = $this->checkLogin(); /* Determine if client is logged in */ $this->logged_in_Client = $this->checkLoginClient(); if($this->logged_in){ $database->addActiveUser($this->username, $this->time); } if($this->logged_in_Client){ $database->addActiveClient($this->clientname, $this->time); } /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['REQUEST_URI']; } This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306588.0 When i get onto a new server, i put a php file on it and see what versions of php sqlite and mysql there are. For some reason, when i put it on this server, it does not show anything ... 2 of the lines: Code: [Select] echo sqlite_libversion(); echo phpversion(); Other php commands work and i am able to call simple methods and what not. But for some reason those commands and a sqlite query is not working . Any ideas? I have 3 variables that im still cleaning up but they produce results at least. I have spent a couple days searching how to execute (exec or shell_exec) them in order. The best iv found, this is done like Code: [Select] $statementa = 'cd test"' then do this"' exec=($statementa) but what i am doing is a bit more complicated Code: [Select] $tempFolder = 'C:\\xampp\\htdocs\\remote\\'; $filename7Z = 'C:\\xampp\\7-zip\\7z.exe'; $sessionKey = '12345' $commandtest1= 'C:\\xampp\\7-zip\\7z.exe a ' .$tempFolder. 'c' .$sessionKey. '.7z C:\\xampp\\htdocs\\remote\\client\\ helpdesk.txt icon1.ico icon2.ico icon3.ico winvnc.exe'; //semi working, copies entire dir $commandtest2 = 'copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+'.$tempFolder.'c'.$sessionKey.'.7z c'.$sessionKey.'.exe'; //create executable in build directory \\\\not working\\\\\\ $commandtest3 = 'del /F /Q '.$tempFolder.'\\c'.$sessionKey.'.7z'; //remove *.7z from %tmp% directory \\\\\\\\\working\\\\\\\ //session_write_close(); exec($commandtest1); Where i cant seem to find any guidance is, if i wrap these in " then is looks fine in dreamweaver but produces nothing. I think it may be the variables but i cant be sure. I tried todo $exec($commandtest1 & $commandtest2) but that didn't help any then i tired ($commandtest1 | $commandtest2) still noting. It seems i can just have three exec so i have to comine into one however i have several breaks where it need todo the first then sencond then third. Please someone point me in the correct direction. I must have read http://php.net/manual/en/function.exec.php at least 6 times and either miss is each time or haven't been able to apply it to my code correctly Commands out of sync; you can't run this command now Query: DELETE FROM case_ref WHERE user_id='3';DELETE FROM updates WHERE user_id='3' php]<?php // Check if the form has been submitted: if (isset($_POST['delete'])) { if ($_POST['sure'] == 'Yes') { // Delete the record. // Make the query: $query = "DELETE FROM case_ref WHERE user_id='$id';"; $query .= "DELETE FROM updates WHERE user_id='$id'"; $r = mysqli_multi_query ($dbc, $query); if (mysqli_affected_rows($dbc) >= 1) { // If it ran OK. echo '<h3>All cases & updates associated with user have been deleted</h3>'; } // Make the query: $q = "DELETE FROM users WHERE user_id='$id' LIMIT 1"; $r = $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. echo '<h3>User has been deleted</h3>'; } else { // If the query did not run OK. $errors[] = '<p class="error">The user could not be deleted due to a system error.</p>'; // Public message. $errors[] = '<p>' . mysqli_error($dbc) . '<br />Query: ' . $query . '</p>'; // Debugging message. } } else { // No confirmation of deletion. $errors[] = '<p class="error">The user has NOT been deleted.</p>'; } }else{ //show the form echo '<form id="form1" name="form1" method="post" action="delete_user.php?user_id=' . $id . '"> <table width="100%" border="1" cellpadding="5" cellspacing="5"> <tr> <td width="30%">Do you wish to delete this user?</td> <td width="19%"><input type="radio" name="sure" value="Yes" /> Yes </td> <td width="17%"><input type="radio" name="sure" value="No" checked="checked" /> No</td> <td width="34%"> <input type="submit" name="button" id="button" value="Submit" /> <input name="delete" type="hidden" id="delete" value="1" /></td> </tr> </table>'; } // Print any error messages, if they exist: if (!empty($errors)) { foreach ($errors as $msg) { echo "$msg\n"; } } mysqli_close($dbc); ?>[/php] Right, Hopefully I can make you understand what I am trying to do. I am currently creating a PHP chat. Where I use php and mysql. Right now I have only have one chat board and everything works, but I want to add a button that will stay on the same page but load another pvp script instad of the one I an currently running and that will load another sub chat board such as game discussion.Like a mini-irc. Now my question is, is there a php way to this or will I have to script it and if there is ways of this out there could you point me in the right direction. Thanks, ScoreKeeper I'm experimenting with the shell_exec function to gain shell capability on a Linux host that doesn't provide it otherwise. I've found that I can see what is in different directories by entering a command line like: Code: [Select] cd ..; ls but if I enter two consecutive command lines: Code: [Select] cd .. ls The cd command has no effect. Apparently shell_exec is using a new shell every time I call it. Is there a way to start a shell in a PHP script and keep it active while I pass it multiple commands, so that this won't happen? I have a hardware device that I can send commands to by typing in a URL in the address bar. One command tells me if the ports are in use: Code: [Select] http://admin:12345678@192.168.1.10/Set.cmd?CMD=GetPower It returns the result: Code: [Select] p61=1,p62=1,p63=1,p64=1 What I want to do is try and grab the result with PHP when the page loads so I can tell people if the port is turned on or off. So "p61=1" means port 1 is turned ON. If "p61=0" was displayed, it means port 1 is turned OFF. I am not sure if it is even possible to grab the information using PHP or not. Any place to start would be great! Thanks! Hello On my current site i have a seperate php file for each product with a WHERE ID=X clause. How do i put the where clause in the URL? (if that is how its done) so that i only need one file Thanks It would be GREAT if someone could provide some specific structural info for this: I have one checkbox each for Moe, Larry, and Curly respectively. I have managed to assemble code that allows for each of their names: $sql="INSERT INTO $table (first_name) VALUES... It works great INDIVIDUALLY. But I want to be able to insert any combination into the $table by checking the respective checkboxes and submitting the form. It seems that initiating more than a single INSERT will not get the job done, and separating the values as variables hasn't worked either. What is required? Can you offer an example? Hi;
I would like to make a php script read the commands in the htaccess file and apply those commands to itself. Here is an example :
htaccess commands :
RewriteEngine On RewriteCond %{QUERY_STRING} badword RewriteRule .* - [F]The meaning : Deny any request in witch the query string contain the word badword The translation into php code : if( strpos($_SERVER['QUERY_STRING'], 'badword') !== false ) { header('HTTP/1.1 500 Internal Server Error'); exit(0); }Now this example is simple, but how to translate more complex htaccess commands with multiple RewriteCond and complex regular expressions into php commands like the one i did ? or better is there any php script that read an entire htaccess file and apply the rule it read on it ? Thank you Hi. I have our company website running on an older Joomla and so running PHP v5.6. We were encountering some issues so I have been rebuilding on latest Joomla version and will run the latest PHP now but I have encountered an issue (and I'm no php expert). We have a brochure page on the site where a user can select one or more brochures from a list, and then have to complete their details in a form and an email is sent to them with the brochures as a pdf attachment. We also receive an email notification with the user details and what brochure was selected so we can follow up on the lead. So I have the html coding for the web page, which links back to a php file with the brochures listed in an array and using phpmailer to send. Would someone be able to assist me by looking at the current files I have and showing me how to update the deprecated php commands - and also to ensure that the fields info is being properly verified etc. Thank you! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=345200.0 I have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? I'm trying to make a simple website where people register to my website. When the user doesn't fill anything inside the boxes they get a message "Please fill all required fields" on the register.php page On my local host require_once works good. It shows up.
But when i upload the files to my sever the require_once does not show up on the register.php It just refreshes and i dont get the message "Please fill all required fields"
This is the code that works in local host but not in a live server <?php require_once 'messages.php'; ?>
Here is my full code
Register page: <html> <?php require_once 'messages.php'; ?> <br><br> <form action="register-clicked.php" method="POST"> Username:<br> <input type="text" name="usernamebox" placeholder="Enter Username Here"> <br><br> Email:<br> <input type="text" name="emailbox" placeholder="Enter email here"> <br><br> Password:<br> <input type="password" name="passwordbox" placeholder="Enter password here"> <br><br> Confirm Password:<br> <input type="password" name="passwordconfirmbox" placeholder="Re-enter password here"> <br><br> <input type="submit" name="submitbox" value="Press to submit"> <br><br> </form> </html>
Register clicked <?php session_start(); $data = $_POST; if( empty($data['usernamebox']) || empty($data['emailbox']) || empty($data['passwordbox']) || empty($data['passwordconfirmbox'])) { $_SESSION['messages'][] = 'Please fill all required fields'; header('Location: register.php'); exit; } if ($data['passwordbox'] !== $data['passwordconfirmbox']) { $_SESSION['messages'][] = 'Passwords do not match'; header('Location: register.php'); exit; } $dsn = 'mysql:dbname=mydatabase;host=localhost'; $dbUser='myuser'; $dbPassword= 'password'; try{ $connection = new PDO($dsn, $dbUser, $dbPassword); } catch (PDOException $exception){ $_SESSION['messages'][] = 'Connection failed: ' . $exception->getMessage(); header('Location: register.php'); exit; }
messages.php <?php session_start(); if (empty($_SESSION['messages'])){ return; } $messages = $_SESSION['messages']; unset($_SESSION['messages']); ?> <ul> <?php foreach ($messages as $message): ?> <li><?php echo $message; ?></li> <?php endforeach; ?> </ul> Edited Wednesday at 12:49 AM by bee65 Hi, I am not a PHP programmer. I took on a new client with a simple PHP site, without any databases. The site is up and running on the web. I would like to get it running on my local machine for further development. I have latest version of WAMP installed, running Apache version 2.2.11 and PHP version 5.3.0 I created a directory in the WAMP "www" project directory and it shows up there like it's supposed to when I browse to "localhost" Problem: The home page of website displays text but no, images, styles, footer, header, nav links, etc. Here is the code for the home page: <? define("NAV","home"); require_once('local/local.php'); ?> <!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> <title>TITLE</title> <meta name="keywords" content=""> <meta name="Description" content=""> <? include("common/dochead.php"); ?> </head> <body onLoad="<? include('common/preloads.php'); ?>"> <!-- ============================ main ============================= --> <div id="main-frame"><div id="main" class="noCollapse"> <? include("common/sign.php"); ?> <div id="right-frame"> <? include("common/navigation.php"); ?> <div id="content-frame"> <div id="content"> <h1>Welcome</h1> <p>This is the content area. This is the content area. This is the content area. </p> </div><!-- end content --> </div><!-- end content-frame --> </div><!-- end right-frame --> <div class="clearFloats"></div> </div><!-- end main --></div><!-- end main-frame --> <? include("common/footer.php"); ?> </body> </html> Any help would be greatly appreciated. I have spent many hours on this. Regards |