Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. That is the same as what trq linked to. For what you are wanitng to do you are going to need to setup virtualhosts for each project/site. This is only way you can host multiple sites from one server instance Setting up virtual hosts looks complicated at first, but in actual fact it is rather simple For each <virtualhost></virtualhost> directive you need to define a ServerName this is the domain name for the site (eg site1.localhost, site2.localhost). The other important directive each virtualhost needs is a DocumentRoot . This defines where the sites files are located for the site. Your very basic virtualhost config would be some like <VirtualHost *:80> ServerName site1.localhost # domain for site1 DocumentRoot "D:/site1" # document root for site1 <Directory "D:/site1"> # the directory config options Options Indexes FollowSymLinks AllowOverride All Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName site2.localhost # domain for site2 DocumentRoot "D:/site2" # document root for site2 <Directory "D:/site2"> # the directory config options AllowOverride All Allow from all </Directory> </VirtualHost> Now add the following to your Windows hosts file (located in C:\Windows\System32\drivers\etc\). 127.0.0.1 site1.localhost 127.0.0.1 site2.localhost Restart Apache you should now be able to access http://site1.localhost and http://site2.localhost which should serve the sites located in D:/site1 and D:/site2 respectively. You can add as many virtualhosts as you like.
  2. Try RewriteEngine On RewriteCond %{REQUST_FILENAME} !-d RewriteCond %{REQUST_FILENAME} !-f RewriteRule ^main/([^/]+)/([^/]+)/([^/]+)/ get.php?var1=$1&var2=$2&var3=$3 [NC,L]
  3. PHP cant target elements in browser so using header will never work. Your only hope is to use javascript to target the parent window and change its location, something like <script> parent.window.location = 'target-page.php' </script> But using iframes is so old school. The more modern method is to use ajax to accomplish this. Whereby when the user clicks the login/submit button you'd submit the forms contents via ajax. Your PHP script will only serve a success response if the users credentials where valid. In your JavaScript you'd then listen out for this response and decide what to do when the user logins successfully, such as redirect the page using javascript or dynamically load in the restricted elements into the page without having the page reload (like when you click the edit button on your post). There are javascript frameworks out there which helps to aid in this process. JQuery is more common (there are others) or an alternative would be something AngularJS for creating single page applications.
  4. If the query failed you could use PDO ErroCode to retrieve the error code, if it matches 42S02 (MySQLs error code for table does not exist) then you can output the appropriate error message to the user. if(!$result) { if($dbh->errorCode == '42S02') { // handle table does not exist error echo 'Sorry invalid survey id: ' . $survey_id; } else { // some other error, handle this differently } } else { // output results } You should also be very careful when using variables in queries as part of column/table names, as this can lead to SQL Injection, regardless of fact you are using prepared statements. I agree with fastcol you should first get an array of acceptable table names. Then compare $survey_id to see if its acceptable to use.
  5. Splitting your code into two query is inefficient. Your original code you posted is fine, all you needed to do is implement the while loop provided by mac_gver. I will you step through the 6 (simple) changes you need to make to be able to implement it into your code 1. The first line to change is while(...){ Here you need to replace the ... with your mysql_fetch_*() function. Like so while($row = mysql_fetch_assoc($result)){ 2. The second change is this line $new_heading = $row['some_column_that_you_want_to_do_something_only_once_when_it_changes']; Replace some_column_that_you_want_to_do_something_only_once_when_it_changes with the field you don't want to be repeated. In your case you don't want the phones model to be repeated so we'll use the model field here. $new_heading = $row['model']; This variable is used to output a new table for listing the new phones information and its repairs table when the phones model changes 3 & 6. Where you see this if statement if($last_heading != null){ // there is a previous data section, close it here... } You replace the comment ( // there is a previous data section, close it here... ) with the HTML for closing the phone repairs and phone information sections. Example echo ' </table> <!-- closes the repairs table --> </tr> </table> <!-- closes the phone information table -->'; This code is only executed when the model of the phone changes! 4. Replace // there is a previous data section, close it here... With the HTML for listing the phones information (icon, model, model_no, year, capacity). You will also open a table for listing the repairs for that model. Example echo ' <table> <tr> ... list the phones information ... </tr> <tr> <table> <tr> ... create icon, fault, description and cost headings ONLY ... </tr> <!-- open the table but DO NOT CLOSE IT --> '; This code is only executed when the phone model has changed. We create a new table for listing the phones information and opening a new table for listing the repairs. 5. Replace // output the data under each heading here... Here you will create a new table row outputting these fields: icon, fault, description and cost from the database echo ' <tr> ... output row for repair information (icon, fault, description, cost) </tr>'; This code is used for listing the repairs for the current model Those are only changes you need to make. I have explained what changes are required with examples. You should now be able to replace your while loop with mac_gver's. The next challenge for you is to replace mysql_* functions with either PDO or MySQLi. The mysql_* functions are deprecated which means they are no longer supported and could be removed from future versions of PHP.
  6. No, any changes made to any superglobals variables (except $_SESSION) in your code will not be remembered. PHP handles the $_SESSION superglobal differently, whereby at the end of script execution it will write the data stored in that array to a file on the server. On the next page PHP will read the contents of that file and populate the contents of the $_SESSION superglobal. The only way to persist data form page to page is either query string parameters in the url, a from (using hidden input fields) or using sessions/cookies. You could define formtype as a hidden input field and give the value of house_insurance_form Example: <form method="post" action="..."> ... <input type="hidden" name="formtype" value="house_insurance_form" /> </form>
  7. No, sha256 returns a hash that is 64 character string. All you needed to do was increase the character limit of your password field to 64 characters You need to be concatenating $salt and $password together (a period between the two variables not a comma) when you pass them to the hash function. $hash = hash('sha256', $salt.$password);
  8. Remove the quotes around the code highlighted in red <td colspan="7" class="hideme"> '. (get_post_meta($post->ID,"_as_pros",true)!="" ? '(get_post_meta($post->ID,"_as_pros")' : '') .' </td> Code within in single quotes, will not be parsed it will be treated as text.
  9. Remove line 14 e.preventDefault(); // Not needed, just for demonstration This is preventing the form from submitting.
  10. It would be helpful if you posted any error messages you are getting in full here along with the relevant code.
  11. Barands solution is correct, I think you have missunderstod how to implement it into your code. Example usage: $miles = $_GET['miles']; // get the miles // $miles is used as the array key for the $values array. $result = $values[ $miles ][2]; // returns the third item corresponding to the $miles key. Example if $miles is 25, then $result will be 'hot'
  12. Not sure what you are asking, but you can install PHP and MySQL locally on your PC so you can test your PHP scripts locally without having to upload your files to a webhost. To do so you can install them manually yourself or you can install an all in one packages such as WAMP (for windows only), XAMPP (for windows, *nix & Mac) or MAMP (for Mac only) on your PC to get your development environment setup locally.
  13. So you only want to apply it to numbers with more than 10 digits, if it is more replace 44 at the beginning of the number with a zero Simple substr replacement should do the trick. $num = '441234567890'; // number greater than 10 digits and beings with 44 if(strlen($num) > 10 && substr($num, 0, 2) == 44) { $num = '0' . substr($num, 2); // ignore the first two digits and prepend the number with a zero } echo $num;
  14. That has nothing to do with PHP. You'd use CSS to stylize elements on the the page. Example: http://jsfiddle.net/DgPVR/
  15. Remove the closing </tr> tag directly after the foreach loop, this is probably what is causing it. If all you are doing is dumping the data in $row into <td> tags, then you can write while loop as. while($row = mysql_fetch_row($result) { echo ' <tr> <td>' . implode('</td><td>', $row) . '</td> <td><a href="edit.php?contact_id='.$row['contact_id'].'">Edit</a></td> <td><a href="delete.php?contact_id='.$row['contact_id'].'">Delete</a></td> </tr>'; }
  16. Either add an empty option before the first option or change the onchange event to an onblur event.
  17. You need to answer mac_gyver question here, as you replies make no sense.
  18. @ajoo you get that error message because you have not change your if statement to the one I have posted! This is because there is an error in your code. I have highlighted what is wrong below if(isset($_POST(['myselect']))) echo " I am selected".$_POST['myselect']; // ^ ^ // | | // remove two braces, these are causing the error
  19. So you want to output a separate link for each color in your array? <?php $colors = array('blue','green','white'); foreach($colors as $color) { echo '<a href="page.php?color='. $color. '">' . $color. '</a><br />'; } ?>
  20. Yes, you need to wrap echo "$val"; in curly braces <?php $test = array('blue','green','white'); foreach($test as $val) { echo "$val"; } ?> If you are to go in and out of PHP mode then you should format your code like <?php $test = array('blue','green','white'); ?> <ul> <?php foreach($test as $val): /* opens foreach block */ ?> <li><?php echo "$val"; ?></li> <?php endforeach; /* closes foreach block */ ?> </ul>
  21. The session id is a unique id which is used to identify the user that belongs to the session. When you call session_start(); PHP will first check to make sure if a current session is active, by first looking to see if a PHPSESSID cookie is set (other places could be a PHPSESSID url query string parameter or form field named as such). If it cannot find the PHPSESSID. It will generate a new session, and create a new PHPSESSID cookie. What can happen with sessions is something called session hijacking, where by a malicious user manages to steal your PHPSESSID. All the malicious user would need to do is to create a PHPSESSID cookie, or define it as query string parameter/form field and the server will think it is you. Have a read of this chris shiflett article to understand it more and how to protect yourself. Miss read your code originally. application/x-www-form-urlencoded is the default enctype handled by the web browser. The only time you need to define the encytype as multipart/form-data is when you are going to be uploading files. So if you are not uploading files there is no added benefit for defining the enctype. .. and that will lead to Cross Site Scripting attacks . This does not apply to GET but all request inputs (such as POST and COOKIE etc..). No data retrieved from the user should ever be trusted.
  22. Why? There is no need to do that. This is why you have session_id() function for. The only time you need to get the session id is if you're doing something specific with it, such as writing your own session handler. For what? Yes, after calling header() make sure you also terminate script execution directly after. I hope there is more logic for processing the users login than what you currently show. The following will cause a undefined index notice if $_SESSION['logged'] is not defined if (!$_SESSION['logged'] == true){ You should check it exists first before checking its value if (isset($_SESSION['logged']) && $_SESSION['logged'] !== true){ The enctype="application/x-www-form-urlencoded" form attribute is only required if you are allowing file uploads when the form is submitted. I dont see you needing this for logging in/out users? I wouldn't pass messages over the url. If you are needing to do so then look into setting up flash messages (see here for an example)
  23. What? I do not understand your post. Can you explain what it is you're trying to do?
  24. Your if statement should be if(isset($_POST['myselect'])) echo " I am selected".$_POST['myselect']; Also always enclose HTML attribute values in quotes too <form method="post" action="dropdownaction.php"> ...
  25. phpMyAdmin does not need to be fully configured in order to use it. The parts highlighted with warnings can be ignored, these settings are for controlling what features certain users from different user groups can access. You'd only set this up if your development server is accessed by multiple users. If you are the only user then it is pointless setting this up.
×
×
  • 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.