Jump to content


  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

TrueMember's Achievements


Member (2/5)



  1. Yes, you can see the proof in the first post. I don't understand why. To try i added the code to controller and it happens again.. $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $response = curl_exec($ch); $dom = HtmlDomParser::str_get_html($response); echo '<pre>'; print_r($dom->find(".title")); echo '</pre>'; $dom->clear(); unset($dom); die();
  2. Hi again, I did a simple request and i get right response from curl_exec($ch); but when i call the static method str_get_html my result is always the same. I tried increase the memory memory_limit=2048M but the result is the same. Proof of memory limit: Memory Limit I also tried ->clear(); unset(); but doesn't work. I'm using the following library: kub-at/php-simple-html-dom-parser My code: $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $this->callback = HtmlDomParser::str_get_html(curl_exec($ch)); .... Any tips? I can use regular expression, but will be my last choice. Thank you!
  3. Thank you all. Problem solved adding this content to composer: "classmap": ["app/libraries", "app/controllers", "app/models"] For future troubles about this, i leave here a good tutorial about a simple MVC. (1/5 videos)
  4. This is what i do in bootstrap.php but only for content inside libraries folder. I should do the same for controllers? Do you have any example?
  5. I know that, but my ideia is change to work with version with error. But i don't have any ideia to do it.
  6. I'm using this struture to run my application, everything works fine, but i don't like how the controllers are called. If i load the model in construct it will work great again, but i think that is unnecessary. You can see two pieces of code about controller "Post.php", the last one, works great. If i try this: (Posts.php) namespace app\controllers; use app\libraries\Controller; use app\models\User; class Posts extends Controller { public function index():void { //Get posts $user = new User(); $posts = $user->posts(); $data = [ 'posts' => $posts ]; $this->view('posts/index', $data); } } I will get an error: Structure: bootstrap.php //include all files from libraries require_once __DIR__ . "/../vendor/autoload.php"; index.php use app\libraries\Core; require_once '../app/bootstrap.php'; //Init Core Library $init = new Core(); core.php public function __construct(){ $url = $this->getUrl(); //Look in controllers for first value if(file_exists(dirname(__FILE__, 2) . '/controllers/' . ucwords($url[0]) . '.php')){ //if exists, set as controller $this->currentController = ucwords($url[0]); //Unset 0 index unset($url[0]); } //Require the controller require_once dirname(__FILE__, 2) . '/controllers/' . $this->currentController . '.php'; //instantiate controller class $class = 'app\\controllers\\' . $this->currentController; $this->currentController = new $class; //check for second part of url if(isset($url[1])){ //Check to see if method exists in controller if(method_exists($this->currentController, $url[1])){ $this->currentMethod = $url[1]; //Unset 1 index unset($url[1]); } } //Get params $this->params = $url ? array_values($url) : []; //Call a callback with array of params call_user_func_array([$this->currentController, $this->currentMethod], $this->params); } Posts.php class Posts extends Controller { public function __construct() { $this->userModel = $this->model('User'); $this->postModel = $this->model('Post'); } public function index():void { //Get posts $posts = $this->userModel->posts(); $data = [ 'posts' => $posts ]; $this->view('posts/index', $data); } } Controller.php abstract class Controller { /** * Load model * @param $model * @return mixed */ public function model($model) { //Require model file require_once '../app/models/' . $model . ".php"; //instantiate model $class = 'app\models\\' . $model; return new $class(); }
  7. ::1 is the IP address of the client. Maybe what you want is: $_SERVER['SERVER_ADDR']
  8. I don't know what you want to do, you need be more specific. Nobody will work to you, if you want to learn, try by yourself and ask your doubts.
  9. Enable errors and check what's wrong. Print the query and execute directly on database. <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $Title = $_POST['title']; $Price = $_POST['price']; $Author = $_POST['author']; $con = mysqli_connect('localhost', 'root') or die("not connected"); mysqli_select_db($con, 'BRM_DB'); if (!$con) { echo "ERROR: " . mysqli_connect_errno() . PHP_EOL; echo "ERROR: " . mysqli_connect_error() . PHP_EOL; die; } $query = "INSERT INTO book(title,Price,Author)values('$Title',$Price,'$Author')"; $result = mysqli_query($con, $query); mysqli_close($con); ?> <!DOCTYPE html> <html> <head> <title>Insertion</title> </head> <body> <h1>Book Record Management</h1> <p> <?php if ($result == 1) { echo ("Record inserted"); } else { echo ("insertion failed"); } ?> </p> <a href="insertform.php">click here</a> </body> </html>
  10. U should use $_POST, try the below code: $var_username = $_POST['username']; $message = '<p>Hello</p>' . $var_username . '<p>Please click the following link to activate your account : <a href="' . $var_username . $activate_link . '">' . $activate_link . '</a></p>';
  11. I think this is the result intended. HTML: <label for="firstname"> <i class="fas fa-user"></i> </label> <input type="text" name="firstname" placeholder="Firstname" id="firstname" required > <input type="text" name="surname" placeholder="Surname" id="surname" required > <br> <label id="result"></label> JQUERY: $(document).ready( function() { $("#firstname, #surname").keyup( function() { var firstname = $("#firstname").val($("#firstname").val().toUpperCase()); var surname = $("#surname").val($("#surname").val().toUpperCase()); $("#result").html(firstname.val() + " " + surname.val()); }); });
  12. Try this: $fields = array( 'username' => urlencode('xxx'), 'password' => urlencode('xxx'), 'B1' => 'Submit' );
  • 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.