PHP - Proper Way Of Using Or With Two If Commands
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? Similar TutorialsThis 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? 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']; } 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] 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? 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 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? 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 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 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! 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 Always 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); ?> 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! 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 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=345200.0 This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=333614.0 Hi, I'm modifying the following PHP code from a Wordpress plugin: /* Byline. */ if ( $instance['byline'] ) echo do_shortcode( "<p class='byline'>{$instance['byline']}</p>" ); /* Entry title. */ if ( 'widget' !== $instance['entry_container'] && $instance['entry_title'] && $show_entry_title ) { the_title( "<{$instance['entry_title']} class='entry-title'><a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a></{$instance['entry_title']}>" ); } elseif ( 'widget' !== $instance['entry_container'] && $show_entry_title ) { the_title( "<a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a>" ); } The output currently is: Code: [Select] [ December 13, 2010 ] Post Title I'm trying to combine the two so that the output appears on one line. What is the operator to execute multiple command in one statement? Thanks. Hey guys I usually code in C and I started looking into PHP which I think is pretty good. I'm wondering if there's a function that can be used to execute a command from a remote server on my local machine??? As example if I'd like to have a PHP page/script running on my server which when logged onto would display me a page with buttons like "PING, NETSTAT, IPCONFIG, TRACERT" and when clicked on it would exec those commands but not on the server but from my machine??? So that I would get the PING from my local machine to google.com instead of from the server to google.com ??? making any sense ??? thanks Should this be the proper way of adding the getUsername() text in the query below: Code: [Select] mysql_query("UPDATE posts SET content = '$content', lastedit = ". getUsername() .":NOW() WHERE id = '$pid'") or die(mysql_error()); |