Web Page showing different results on pc and android

I made a web page on PHP.

It is showing me different results in pc and in android browsers .

In android browser it is showing exactly what I want , but in pc it is showing blank page ( end point is same ).

Index.php

<?php

include_once "classes/Database.php";
$db = new Database();

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="Description" content="Enter your description here"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<title>Frontend Challenges</title>
</head>
<body>
    <nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light mb-3">
        <a class="navbar-brand" href="#">
            <img src="<?php echo $db->mySource ; ?>" height = "40" class="d-inline-block align-top" alt="">
          </a>    
      
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav mr-auto">
                        
          </ul>
          <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit"><i class = "fa fa-search"></i></button>
          </form>
      
        </div>
      </nav>
    <div class="container">
        
        <div class="row text-center">
            <h3 class = "w-100 text-center mb-5">Frontend Challenges</h3></br>
            <!-- <h4>Here are some of our challenges</h4> -->
            <div class = "col-md-12">
                <div class="card-deck">

              <?php
                $select_query = "SELECT * FROM challenges";
                $result = $db->select($select_query);
                if($result){
                    while($row = $result->fetch_assoc()){
              ?>
                <div class="card mb-3" style = "text-align: center;">
                  <a class = "img_ref" href = ""><img src="uploads/<?php echo $row['image']; ?>" class="card-img-top" alt="..."></a>
                  <div class="card-body d-flex flex-column justify-content-between align-items-start">
                    <div class="card_title_tech text-left">
                        <a href=""><h4 class="card-title"><?php echo $row['title']; ?></h4></a>
                        <p class = "tech_used w-100">
                          <?php
                        $techs = explode(",",$row['tech']);
                        foreach($techs as $tech){
                          if($tech == "html"){
                            echo "<span class = 'tech_usage tech_html'>HTML</span>";
                          }else if($tech == "css"){
                            echo "<span class = 'tech_usage tech_css'>CSS</span>";
                          }else{
                            echo "<span class = 'tech_usage tech_js'>JS</span>";
                          }
                        }
                        ?>
                        </p>
                    </div>
                    <p class="card-text text-left mb-4"><?php echo $row['descrip']; ?></p>
                    <a href="challenge.php?id=<?php echo $row['challenge_num']; ?>"><button class = "btn take_challenge_btn">Take this challenge</button></a>
                  </div>
                </div>
                <?php
                    }
                  }else{
                    echo "<h1 >No Challenges Found</h1>";
                  }
                ?>
              </div>
            
            </div>
            
        </div>
    </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
</body>
</html>

Style.css

@import url('https://fonts.googleapis.com/css2?family=Fira+Code&family=Lato&family=Nunito&family=Roboto&display=swap');

h3{
    font-family: 'Nunito',sans-serif;
    font-size: 30px;
    font-weight: 500;
}
h4{
    font-size: 25px;
    font-weight: 500;
}
a{
    text-decoration: none;
}
.take_challenge_btn{
    background-color: #00ae4d;
    color:white;
    transition: all 0.5s;
}
.take_challenge_btn:hover{
    color:white;
    background-color:#006a30;
    transition: all 0.5s;
    
}
.card-title{
    font-family: 'Lato';
    font-weight: 500;
    margin-bottom:15px;
}
.card-title:hover{
    color:#00ae4d;
    transition: all 0.2s;
}
.card{
    box-sizing: border-box;
    overflow: hidden;
}
.card-img-top{
    transition: transform 0.5s;
}
.card-img-top:hover{
    transform: scale(1.1);
    transition: all 0.5s;
}
.card_title_tech a{
    text-decoration: none;
    color:#000;
}
.card_title_tech a:hover{
    text-decoration: underline;
    text-decoration-color: #00ae4d;
}



.tech_usage {
    font-family: 'Roboto',sans-serif;
    font-size: 18px;
    font-weight: 700;
    /* padding: 0px 10px; */
    margin-right: 10px;
}
.tech_html{
    color: rgb(106, 190, 205);
}
.tech_css{
    color: rgb(62, 84, 163);
}
.tech_js{
    color:rgb(207, 99, 144);
}

@media (min-width: 576px){
    .card{
        flex :none !important ;
        width: 360px !important;
        height: 527px !important;
    }
}



Screenshot – pc view

PC view of web page

Screenshot – android view

Android view of web page

How resource intensive is it to do an AJAX from submission using the oninput event on a range slider input field?

I have the following range slider:

<input type="range" min="0" max="511" value="208" step="0.01" oninput="slider_move();perform_calculation()">

The slider_move() function only updates the value shown in an associated input-number field. What I am concerned about is the perform_calculation() function which looks like this (shortened version):

function perform_calculation() {
var isValid = $('#formname').valid();
var value1 = _("value1").value;
var value2 = _("value2").value;
...

if(isValid){
  var formdata = new FormData();
  formdata.append("value1", value1);
  formdata.append("value2", value2);
  ...
  var ajax = new XMLHttpRequest();  
  ajax.addEventListener("load", completeHandler, false);
  ajax.addEventListener("error", errorHandler, false);
  ajax.open("POST", "/calculator.php");   
  ajax.send(formdata);      
 }
}

With event handlers:

function completeHandler(event) {
  _("result").innerHTML = event.target.responseText;
}

function errorHandler(event) {
  _("result").style.color = "red";
  _("result").innerHTML = "Some error msg.";
}

(Note that I have this shorthand function in the page header:

function _(el) {
 return document.getElementById(el);
}

)

So basically, as a user moves the slider, I assume that the AJAX call is executed dozens of times per second (not exactly sure how often an “input” event occurs as the slider is moved). Of course the nice thing about doing it this way is that the user sees the page updated with the calculation results as the slider gets moved (and the input value changed), but I am worried that this is too resource intensive and may cause the server to slow down if there are many users on the page. Should I be worried and if so, is there a better way to do this while maintaining the same functionality?

Why isnt my login page working? It only allows for one input inside the database at one time

I’m working on a login page for a PHP database (xaamp) and this code is for the sign-up part. This code is meant to check if the database has an existing username. When there are no inputs in the database, the sign-up page works but once a submission is made no more can be made after that. I’m not too sure how to fix that. This is HTML, javascript and PHP.

 if (uidExists($conn, $username) !== false) {
    header("location: ../homepage.php?error=usernametaken");
    exit();
}

  function uidExists($conn, $username) {
    $sql = "SELECT * FROM user_information WHERE UserUid = ?;";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        header("location: ../homepage.php?error=stmtfailed");
    exit();
    }

    mysqli_stmt_bind_param($stmt, "s", $username);
    mysqli_stmt_execute($stmt);
    

    $resultData = mysqli_stmt_get_result($stmt);

    if ($row = mysqli_fetch_assoc($resultData)) {
        return $row;
    }
    else {
        $result = false;
        return $result;
    }

    mysqli_stmt_close($stmt);

}

Laravel: a given number of models (download codes) in a single controller method

I am building a feature which generates a given number of download codes and popupates the DB table with them. So with this link downloadcodes/generate/10?type=1 I want to create 10 entries in my table.

The controller method looks like this:

    public function generate($quantity)
    {


        $codetype = Input::get('type');

        
        XXXX{    // ITERRATING LOOP from 1 to 10 

            $object = new DownloadCode;

            $object->type = $codetype; 
            $object->code = [string-of random-6-digits];
            $object->save(); 

        }

        return $quantity. " codes generated". $codetype;

    }

Thank you.

How to remove the ‘?’ in the URL with router and php MVC

I try to remove this character (?) from my URI (example: www.mywebsite.com/?home to www.mywebsite.com/home) but this is working in localhost and not in production ( i got a 404 error ) what I’m doing wrong?

I’m working on PHP and MVC. This is my router with my modifications.

<?php

ob_start();
session_start();

$theGet = explode('/',$_SERVER['REQUEST_URI']);


if ( strpos($theGet[2],'&&')  ){
    $section = explode('&&',$theGet[2]);
    $giveToGet = explode('=',$section[1]);
    $_GET[$giveToGet[0]] = $giveToGet[1];
    $theGet[2] = $section[0];
}

if ( isset($theGet[2]) ){
    if ($theGet[2] === '') {
        include_once "./views/home.view.php";

    }else {
        if (isset($_GET['token'])) {
            $_SESSION['tokenRecup'] = $_GET['token'];
        }
        if (file_exists("./views/$theGet[2].view.php")) {
            include_once "./views/$theGet[2].view.php";
        } else {
            include_once "./views/404.view.php";
        }
    }

    $render = ob_get_clean();
    include_once "./templates/base_template.php";
}else{
    header('Location: ./home');
}

lavaral: problems with rendering sections (->renderSections) and content section

it seems quite simple. i have a controller, a class/object and a view for it (show/edit). and i want to render this view in an overview/listing.therefore i have to extract the the ‘content’ section.

demo.blade.php

@extends('mainlayout.main')

@section('content')
Content of the object
@endsection 

so i use in the overview template (overview.blade.php) the following code

$sections = View::make('demo')->renderSections();
echo($sections['content']);

what happens? the content here overwrites everything in the section (content) of the overview.blade.php

i also tried to take another name for the section like ‘contentnew’ and than ! it works.

so my questions?

  • should it work with section ‘content’? or do i understand something wrong with the template engine?
  • why is ‘content’ handled different than contentnew. simple because it is not parse?

thanks for any help.

t00cg

Invalid character DOMPDF using html5

Hello I’m facing an error when trying to generate a pdf from HTML using dompdf with laravel,
and is give me an error on this path:

…vendordompdfdompdflibhtml5libTreeBuilder.php3203

more specificaly on insertElement function:

>     private function insertElement($token, $append = true) {
        $el = $this->dom->createElementNS(self::NS_HTML, $token['name']);

        if (!empty($token['attr'])) {
            foreach ($token['attr'] as $attr) {
                if (!$el->hasAttribute($attr['name']) && preg_match("/^[a-zA-Z_:]/", $attr['name'])) {
                    $el->setAttribute($attr['name'], $attr['value']);
                }
            }
        }
        if ($append) {
            $this->appendToRealParent($el);
            $this->stack[] = $el;
        }

        return $el;
    }

and I have on DB styles to display on HTML attribute like:

<ul style='box-sizing: border-box; margin-top: 0px; margin-bottom: 8.5px; color: rgb(112, 109, 109); font-family: "Noto Sans", sans-serif, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;'><li style="box-sizing: border-box;">Analyse du besoin en tenant compte des exigences internes et r&eacute;glementaires</li><li style="box-sizing: border-box;">Mise en oeuvre du cahier des charges</li><li style="box-sizing: border-box;">Proposition des solutions techniques pour les applications r&eacute;pondant au cahier des charges</li><li style="box-sizing: border-box;">Respect de la planification du projet de d&eacute;veloppement et participation aux r&eacute;union projets d&#39;&eacute;tat d&rsquo;avancement</li><li style="box-sizing: border-box;">Conception du prototype,programmation,R&eacute;alisation des interfaces et cr&eacute;ation des bases de donn&eacute;es</li><li style="box-sizing: border-box;">&Eacute;laboration des protocoles d&#39;essais et r&eacute;alisation des tests</li><li style="box-sizing: border-box;">R&eacute;alisation des notices techniques et des guides d&#39;installation et d&#39;utilisation</li><li style="box-sizing: border-box;">Traitement des anomalies de fonctionnement et r&eacute;solutions des probl&egrave;mes</li><li style="box-sizing: border-box;">Maintenance des applications dont suivi des modifications ou &eacute;volutions.</li></ul>

I’am using:

“php”: “>=7.0.0”,
“barryvdh/laravel-dompdf”: “^0.8.2”,

if someone have an idea please you can contribute here and thanks
Best regard

Remove unsupported characters in mysqli with php

I’m developing something simple but it brings me upside down the unsupported characters within a text field in mysqli.

This is the string I’m trying to upload

Gloria Grahame, Lawrence Tierney, Henry Wilcoxon, Edmond O'Brien

I try to remove the character that gives me problems right now which is ‘

$resumen=str_replace("'",'',$_POST[resumen]);

But it doesn’t work, how can I fix? I would like to find a way that removes from the string all the characters not supported by the database

Package development: “Failed to open stream: No such file or directory” when trying to load routes

I’m developping a package, I created all my classes and routes, but when it comes to access my routes, I keep getting the same message :

require(packages/uhgroup/UHTickets-laravel/src/routes/web.php): Failed
to open stream: No such file or directory

I don’t know what I did wrong…

I tried to use the command composer dumpautoload but I get the same error.
In addittion, I get a “Class UHGroupUhTicketsAppLivewireCreateTicket located in C:/Users/lilia/Documents/GitHub/UH-Tickets/vendor/uhgroup/uhtickets-laravel/srcappLivewireCreateTicket.php does not comply with psr-4 autoloading standard. Skipping.” message for every single class I made…
What’s wrong with my namespaces ?
Error message

Here are the structure of my files/folders in my project:

enter image description here

and my package’s AppServiceProvider:

<?php

namespace AppProviders;

use IlluminateSupportServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadMigrationsFrom("packages/uhgroup/UHTickets-laravel/src/database/migrations");
        $this->loadRoutesFrom("packages/uhgroup/UHTickets-laravel/src/routes");
    }
}

I’m not going to lie, I’m not really sure of the namespace to write when developping a new class in a package.
For instance this is the namespace I put for my models : namespace UHGroupUhTicketsAppModels;

Stop converting string to integer on post request php

I am having trouble getting data in post request php.

In the frontend i am sending a post request value as 080
but when i save the data or show the data in backend it only shows 80.

I tried using following methods but it all returns same:

$value = (string)$_POST["value"];

$value = strval($_POST["value"]);

$value = "{$_POST["value"]}";

$value = $_POST["value"] . "";

But when i tried adding some value in the string following way it works

$value = "Hello: {$_POST["value"]}" <– in this scenario it works perfectly fine.
Returning as Hello: 081

When i use var_dump($_POST["value"]) it returns as: string(3) "080"

How can i solve this issue?

how can run websockets:serve on hosting laravel

Work on a laravel site with real-time notifications using the laravel-websocket library from:

https://beyondco.de/docs/laravel-websockets/getting-started/introduction

On the local server I have to run the following command for it to work:

php artisan websockets:serve

Starting the WebSocket server on port 6001...

Now I have uploaded the website to cloudways hosting

How can I implement the command to always run the server?

php artisan websockets:serve

jQuery post to the same PHP page

I am creating a jQuery search bar, that will asynchronously send the inputted value from a form from the client side to the same page on the server side (in PHP). Then I can search my database with the value. Unfortunately when I send this value, using $.ajax, and attempt to echo out the value, I don’t get the value at all. How can I receive my value? I’ve tried print_r, var_dump, echo but to no avail.

Here is my form:


<form method = 'POST'>
  <input id="myInput" type ="text"  name ="value" 
  placeholder="press enter when finished" > 
</form> 

And here is my script to make the call. I get the value in my console when I press enter (key===13), but it seems to be the furthest my variable (value) seems to go.



$(document).ready(function(){
    $('#myInput').bind('keypress', function(e){ 
        if(e.keyCode ===13){
        let value = $(this).val().toLowerCase();
        console.log(value);
            
        e.preventDefault();  //stops the damn page refreshing
            
         $.ajax({
            type: "POST",
            data: value
            
        
        });

        };
    });
});

I haven’t put the URL in the AJAX call for a reason: I’m sending to the same page.

Here is the code (further up the page) that I’m using to echo out the posted value, on the same page.

if(isset($_POST['value'])) { echo $_POST['value']; exit;  }

No matter what I seem to do, my value isn’t sent to the page! I’ve tried to add in the URL, I’ve added “success” to the call…. nothing seems to work.

How can I successfully send my data?

JQuery get siblings value / text in dynamically created element

I want to get the .text() of the sibling customerID from the class”db_record_left” when class=”db_record_left” gets clicked.
The whole class=”db_record” is dynamical generated. But the console.log(CustID); still prints it for every class=”db_record” and not only for the clicked one.

echo'
                    <div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
                        <div class="db_record_left">
                            <div class="db_record_describer">'.$cus_Fname.' '.$cus_Lname.'</div>
                            <div class="db_record_info_wrapper">
                                <div class="db_record_info_describer">Adresse:</div>
                                <div class="db_record_info">'.$cus_Adress.'</div>
                                <div class="db_record_info">
                                    <span>'.$cus_ZipCode.' </span>
                                    <span>'.$cus_Locality.'</span>
                                </div>
                            </div>
                            <div class="db_record_info_wrapper">
                                <div class="db_record_info_describer">Fahrzeuge:</div>
                                '.matchVehicles($cus_Vehicles).'
                            </div>
                        </div>
                        <div class="db_record_right">
                            <div class="material-icons md-large md-ghost-white-enabeld w-embed">
                                <span class="material-icons-outlined">navigate_next</span>
                            </div>
                        </div>
                    </div>
                    <span class="customerID" style="display: none">'.$cus_ID.'</span>                
                ';

This would be the jQuery-code

function checkCustomerInformation(){
    $(".db_records_wrapper").on('click', 'div.db_record', function (){
        const CustID = $(this).siblings(".customerID").text();
        console.log(CustID);
    });
}

How to make POST (API) request with cookies inside controller | Laravel 9.x

I’m working with Omada Controller (External Portal Server). That is, to register users through the EAP. The device must be allowed to use WiFi.
I use following documentation:

https://www.tp-link.com/ru/support/faq/3231/
I tested the requests through Postman. Everything is working. However, it is necessary to send a cookie in the request to authorize the device after logging in.

I wrote the following code in Laravel. but cookies are not being stored or sent.

public function AuthFree(Request $req)
    {
        $inputs = $req->all();
        //IP Address of Controller
        $endPoint = 'https://CONTROLLER_API:PORT/CONTROLLER_ID/api/v2/hotspot/extPortal/auth';
        $operatorData = self::getCSRFToken();
        $csrfToken = $operatorData->object()->result->token;
        $cookies = $operatorData->cookies()->getCookieByName('TPEAP_SESSIONID')->toArray();//->getValue();
        $deviceBody = [
            'clientMac' => $inputs['clientMac'],
            'apMac' => $inputs['apMac'],
            'ssidName' => $inputs['ssidName'],
            'radioId' => inputs['radioId'],
            'time' => 1859960742,
            'authType' => 4,
        ];

        $authDevice = Http::withCookies($cookies, $endPoint)
        ->timeout(30)->withOptions([
            'verify' => false,
        ])
        ->withHeaders([
                'Content-Type' => 'application/json',
                'Accept' => 'application/json',
                'Csrf-Token' => $csrfToken,
            ])
            ->post($endPoint, $deviceBody);
        dd($authDevice);
    }

//Login operator.
public function getCSRFToken()
    {
        $authOperator = Http::accept('application/json')->timeout(15)->withOptions([
            'verify' => false,
        ])
            ->post('https://IP:PORT/ID/api/v2/hotspot/login', [
                'name' => 'USERNAME',
                'password' => 'PASSWORD',
            ]);
            
        return $authOperator;
    }

Also i wrote as following code:

$ch = curl_init();
        // Set return to a value, not return to page
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // Set up cookies.
        curl_setopt($ch, CURLOPT_COOKIEJAR, request()->cookie('TPEAP_SESSIONID'));
        curl_setopt($ch, CURLOPT_COOKIEFILE, request()->cookie('TPEAP_SESSIONID'));
        // Allow Self Signed Certs
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        // API Call
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($authInfo));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $res = curl_exec($ch);
        $resObj = json_decode($res);
        return $resObj;

But this also returns error.

The operator enters the system and receives a token through the getCSRFToken function mentioned above. A COOKIE is returned along with the token. I need to send TOKEN and COOKIES together to authorize the device.
Meanwhile, the getCSRFToken function is running and returning tokens. But authDevice is returning an error. Because it can’t get Header and Cookies.

My question is: How can I save the cookies and how can I add them to the request and send them?

Is there something wrong with the code I wrote?