Jump to content

Mad programmer

Members
  • Posts

    26
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Mad programmer

  1. For the loop I'd recommend to use a nested foreach.(on the array you've used in your print_r) The first foreach kan be used like: Foreach($array as $key => $value) { ... } Where $key is example.com and value are its children. So then do another foreach inside this one with the $value as an array. That should work!
  2. You may wish to add a print_r($myArray) between the html pre tags. <pre> </pre>. That will give the desired result!
  3. Well I do use symfony's components, I am looking into the full stack framework but currently I am not using it for a project or anything. Maybe you can write a service that does the job? It may be a little more work right now but It will safe time if you need this particular function more then once in your application.
  4. True, But how about getting the form validators output first? And retrieve the values only and store those along with the request parameters in the session? That way you don't have to run the validators again, and you have the data
  5. Why not just write the form values from the request object to the session? And in your view you bind those values to the form again? I cannot think of any way why that should not work Then you don't have write the complete form object into a session.
  6. Hi Jessica, I am not familiar with behat, but maybe it uses output buffering internally? So I'd try to catch the output buffer and end it, after that you echo your content and then reenable the output buffer with that content?
  7. Hello, If you include the script from another script you can set a variable like: $allowSend = true; And then simply check if that variable is not null and is true, else exit. If it is a standalone script you may use sessions for this.
  8. Hello, Why not just append to the string? $string .= '.html';?
  9. Woa woa hold there you DO know how to use a variable in a string right? Take my modified example from above and BEFORE that do this; $id = $_SESSION['userid']; bindParam is not working with query but only with prepared statements.. the fetch function is only taking pdo arguments such as PDO::FETCH_ASSOC. My modified example is all you need, you're combining prepared pdo wirh normal query statements and that wont work.
  10. That is correct, however PDO does not always require that much lines of code. The prepare functions are for safety purposes. It would be good practice to put these to use. But in your case you typecast to an int by using intval which may also be passed directly to a sql query. You can do this with PDO like so: (Example taken from php.net/pdo and modified a bit) <?PHP $users = $pdo->query("SELECT * FROM users WHERE id = {$id}")->fetch(); ?> Sorry for not using codetags but I am on my cell phone right now.
  11. If you by different syntax mean the way of constructing a query in PDO then no. Except for binding the parameters. This is because pdo sends the query to the mysql server and afterwards your binded parameters. As of php 5.5 the mysql_* functions will be removed(I think) and you will need to use pdo or the mysqli functions for your scripts. MySQL itself cannot be shutdown since it is just a database software package, the interfaces for php are a different story
  12. Well MySQL is the language for the database itself while PDO is an abstraction layer for the database. You can still use variables in a string like you did right there, however the bindParam also makes sure your data is safe and it protects against sql injections.
  13. Have you tried to run my supplied code example? You will see that $user is an array. The array contains your database columns so you echo them like this: echo $user['username'];
  14. True, but I was talking about execute and not exec This is what the docs say: You do NOT want the affected rows but you want to retrieve the rows themself which is done like this: <?php $id = 441; $query = $db->prepare('SELECT * FROM users WHERE id = :id'); // You first PREPARE the query $query->bindParam(':id', $id); // You bind the required parameters for your query $query->execute(); // This sends the query to the SQL server $user = $query->fetch(PDO::FETCH_ASSOC); // Specify the PDO::FETCH_ASSOC to fetch the data as an associative array (not required) echo '<pre>'; // I always PRE before I print an array which makes it more readable in the browser print_r($user); // This contains your fetched row from the sql server ?> Please compare the above piece of code to what you have written and note the differences.
  15. You forgot to call $query-execute(); which executes the prepared statement. After that you may retrieve the data so: $query->fetch(); which returns the data as an array;
  16. You can use variables That is where the prepare function is for. Like so: $query = $db->prepare('SELECT *FROM pages WHERE offline = :offline'); $query->bindParam(':offline', $offlineVariable); Prepare does as the name is called, it prepares the data for the sql server. Such as escaping the data etc.
  17. Hello, I'd like to suggest that you look into pdo's prepare function. First you build up your query with pdo prepare and then execute it. After that you may return the data in this way: $pdo->fetchAll(PDO::FETCH_ASSOC); Which returns all data as an associative array. You might find this link usefull http://php.net/pdo
  18. Hello, As an framework I'd like to suggest symfony2, due to its modern standard and great possibilities. It features a build in authentication system. As for the pagination there are modules for that which can easily be installed in your application. I thought the name was KnpPaginatorBundle. As for the database symfony2 comes with doctrine 2 with is an powerful orm/dbal. You can abstract your database work into php classes wich is rather nice. The documentation can get you started on the framework, it is not complete. But it does explain things pretty well (in my opinion)
  19. Hmm a while ago I wrote a furl like system for my proprietary forum software. It created the urls like this: http://forum.dev/category/forum/(id here)/topic-title-goes-here With this furl it is possible to have duplicate titles since you match the url on the id.
  20. Hello again! I have tested your code on my local server and I got several errors, with these errors the problem was quite easy to find. If you take a look at the code you seem to have made a little mistake ;P $page = (!isset($_GET['page'])) ? 'intro' : $_GET['page']; if (!in_array($page, $files)){ require_once('pages/' . $_GET['page'] . ".php"); } The problem is on the 3rd line above, on the first line you set the variable $page to intro if $_GET['page'] is not set else you just use the $_GET variable. However on the 3rd line you are using the $_GET variable instead of the $page variable. This should work for you: $page = (!isset($_GET['page'])) ? 'intro' : $_GET['page']; if (!in_array($page, $files)){ require_once('pages/' . [color=#ff0000]$page[/color] . ".php"); }
  21. Hello, I looked quickly over your code, but I do not have the possibillity to test it out right now. After your if statement you could add an else and include the 404 page from there. That should work for you.
  22. @Freid001: Good! I'm glad that I could be of any help
  23. @Freid001: Here is an adjusted version of my demo code, this one contains the timestamp as I've suggested. If the session has been set 30 seconds ago the script destroys the session and allowing the user on the page again. (Right after that the timeout is set to 30 again); <?php session_start(); // This is the timeout that the session needs to be checked against (seconds) $timeout = 30; // Allows us to manually unset the session to test our code if (isset($_GET['delete'])) { unset($_SESSION['check']); exit(); } // If our session is not set then create it with its values to false if (!isset($_SESSION['check'])) { $_SESSION['check'] = array( 'set' => false, 'time' => time() ); } if ($_SESSION['check']['set'] == true) { // Check our current time against our timeout if (time() <= $_SESSION['check']['time'] + $timeout ) { echo 'You should not be here!<br /><br>Timespan: '; echo time() - $_SESSION['check']['time']; exit(); } else { // Session is older than 30 seconds, you might unset it.. unset($_SESSION['check']); } } // The user may view the page but we set our session for control purposes! $_SESSION['check'] = array( 'set' => true, 'time' => time() ); echo 'welcome!'; Let me know if it works for you @xyph: I did not mean to say that if its possible to see where the request came from, Take a look at my newly posted code that's how I've meant it all along.
  24. @xyph: I know it affects the current tab as well if you refresh it (Should've mentioned that), this can be fixed by adding some sort of flood control. If you set the session you can add in a current timestamp, and in the session check you can check against the session and the timestamp. If the timestamp is 30 seconds old then unset the session, with this solution you can prevent spamming a little. @Freid001: Where you unsetting the session when you output an error to the viewer? However my method can be used however it also has its disadvantages like Xyph said. You can try adding in a time based mechanism like I said, It doesn't matter how many tabs someone has open the code will always be checked against the session. The real problem is when someone reloads the page, then they have to wait
  25. @xyph: I know they persist, however if you use my approach and open the page in a new tab the session is set. Thus further code execution can be prevent, there is indeed no way to tell if it is a new tab. If you try my script you can see what I mean
×
×
  • 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.