UNSET Session And Destrpy Session Question

Hiya,

Is this:

function unset_sessions()
{
    //All Sessions on the script ....
    UNSET($_SESSION['registration_form_display']);
    UNSET($_SESSION['registration_form_button_clicked']);
    UNSET($_SESSION['domain']); //Form Input
    UNSET($_SESSION['domain_email_account']); //Form Input
    UNSET($_SESSION['domain_email']); //Form Input
    UNSET($_SESSION['password']); //Form Input
    UNSET($_SESSION['errors']); Displays errors underneath the form.
    echo __LINE__; echo '<br>';//DELETE
}

unset_sessions();

the exact same as this:

session_destroy();

I ask, because sometimes the 1st one fails to unset or NULL the values of some sessions such as this:

$_SESSION['registration_form_display

And I have to destroy session. Shall I opt to destroy the sessions instead to wipe-out displaying on form previous form inputs ?

Why I created sessions for user inputs.
Let's say user filled-in 2 form fields correctly and missed 1 or input is wrong on one. When they hit the SUBMIT button, script displays errors and indicates what the error is on which particular field. But only after page reloads on submit button click.
So, if form not filled properly and submit button is clicked then form is reloaded on screen for user to correctly fill-in form before trying to submit again.
As for those fields filled correctly, clicking the submit button would delete the inputs and so I dump the inputs to the sessions and then on page load (after clicking submit button) I repopulate the input fields with their previously correct inputs.
That's why I use sessions on forms.
And yes, I do not dump passwords onto sessions or cookies.

Can You Rank These Valid Mysqli Executions ?

Hiya,

Which of these IF CONDITION codes are valid ?
And can you rank the valid ones according to your choice by giving reasons to your choices ?

Thanks!

$conn = mysqli_connect("localhost","root","","buzz");

$sql = "INSERT into users (username,email) VALUES (?,?)";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"ss",$_POST[username'],$_POST['email']);

    if(!mysqli_stmt_execute($stmt)) //FIRST CHOICE

        if(mysqli_stmt_execute($stmt)==FALSE) //IS THIS VALID ? RECKON VALID. SECOND CHOICE
    if(mysqli_stmt_execute($stmt)===FALSE) //IS THIS VALID ? RECKON VALID. BUT POINTLESS.

        if(mysqli_stmt_execute($stmt)!=TRUE) //IS THIS VALID ? 5TH CHOICE
        if(!mysqli_stmt_execute($stmt)!==TRUE) //IS THIS VALID ? RECKON VALID. BUT POINTLESS.

        if(mysqli_stmt_execute($stmt)==NULL) //IS THIS VALID ?
    if(!mysqli_stmt_execute($stmt)===NULL) //IS THIS VALID ?

        if(mysqli_stmt_execute($stmt)==0) //IS THIS VALID ? RECKON INVALID.
    if(!mysqli_stmt_execute($stmt)===0) //IS THIS VALID ? RECKON INVALID.

        if(mysqli_stmt_execute($stmt)<1) //IS THIS VALID ?

    if(mysqli_stmt_execute($stmt)!=1) //IS THIS VALID ?
        if(mysqli_stmt_execute($stmt)!==1) //IS THIS VALID ?

        {
        echo 'Something went wrong! Please notify webmaster following error!';
                die('Error 2!');
    }
    else
    {
        die('Thank you for your submission!)';
    }
}
else
{
    echo 'Something went wrong! Please notify webmaster following error!';
        die('Error 1!');
}

Q1: Which of my choices are incorrect and why ?
Q2. Out of the valid IF CONDITIONS, can you rank them according to most valid on top and least valid on bottom ? This should teach me best practice.

How To Confirm Row Insertion Is Success in Mysql Using Prepared Statement ?

Howdy once more,
Just got another question on Sql and Php Prepared Statement.
How would you confirm a successful row insertion to a mysql table ?
Which one of the following lines would you add the IF condition to in order to check insertion successful or not ?

1).

mysqli_stmt_execute()

2).

mysqli_stmt_affected_rows()

Which of the following examples A-D are a good way of coding and why and which are a bad way of coding and why based on php's proper way of coding (best practice) ?
Looking below, is there any that is actually unnecessarily going through the IF condition ? (Is pointless). If so, then why ?

A).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.

$sql = "INSERT into users (username,email) VALUES (?,?)";

$stmt = mysqli_prepare($conn,$sql);
mysqli_stmt_bind_param($stmt,"ss",$input_1,$input_2);
mysqli_stmt_execute($stmt);
echo 'INSERTED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);

mysqli_stmt_close($stmt);
mysqli_close($conn);

B).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.

$sql = "INSERT into users (username,email) VALUES (?,?)";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"ss",$input_1,$input_2);
    mysqli_stmt_execute($stmt);
    echo 'INSERTED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);
}
else
{
    echo 'Mysqli Error: ' .mysqli_error();
    echo '<br>';
    echo 'Mysqli Error No: ' .mysqli_errno();
}

mysqli_stmt_close($stmt);
mysqli_close($conn);

C).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.

$sql = "INSERT into users (username,email) VALUES (?,?)";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"ss",$input_1,$input_2);

    if(mysqli_stmt_execute($stmt))
    {
        echo 'INSERTED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);
    }
    else
    {
        echo 'Mysqli Error: ' .mysqli_error();
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_errno();
        echo '<br>';
        die('Failed to INSERT!');
    }
}
else
{
    echo 'Mysqli Error: ' .mysqli_error();
    echo '<br>';
    echo 'Mysqli Error No: ' .mysqli_errno();
}

mysqli_stmt_close($stmt);
mysqli_close($conn);

D).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.

$sql = "INSERT into users (username,email) VALUES (?,?)";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"ss",$input_1,$input_2);
    mysqli_stmt_execute($stmt);

    if(mysqli_stmt_affected_rows($stmt))
    {
        echo 'INSERTED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);
    }
    else
    {
        echo 'Mysqli Error: ' .mysqli_error();
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_errno();
        echo '<br>';
        die('Failed to INSERT!');
    }
}
else
{
    echo 'Mysqli Error: ' .mysqli_error();
    echo '<br>';
    echo 'Mysqli Error No: ' .mysqli_errno();
}

mysqli_stmt_close($stmt);
mysqli_close($conn);

I experimented with all my example codes and they all work so far.

Cheers!

How To Confirm Sql Row Update Using Prepared Statements?

Hello,

Got questions on Sql and Php Prepared Statements.
How would you check whether the SQL managed to update a row or not ? Which one of the following lines would you add the IF condition to ?

1).

mysqli_stmt_execute()

2).

mysqli_stmt_affected_rows()

Which of the following examples A-D are a good way of coding and why ?
And, which are a bad way of coding and why ?

Here are my notes.
A).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.
$input_3 = '0'; //id.

$sql = "UPDATE users SET username=?,email=? WHERE id=?";

$stmt = mysqli_prepare($conn,$sql);
mysqli_stmt_bind_param($stmt,"sss",$input_1,$input_2,$input_3);
mysqli_stmt_execute($stmt);
echo 'UPDATED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);

mysqli_stmt_close($stmt);
mysqli_close($conn);

B).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.
$input_3 = '0'; //id.

$sql = "UPDATE users SET username=?,email=? WHERE id=?";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"sss",$input_1,$input_2,$input_3);
    mysqli_stmt_execute($stmt);
    echo 'UPDATED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);
}
else
{
    echo 'Mysqli Error: ' .mysqli_error();
    echo '<br>';
    echo 'Mysqli Error No: ' .mysqli_errno();
}

mysqli_stmt_close($stmt);
mysqli_close($conn);

C).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.
$input_3 = '0'; //id.

$sql = "UPDATE users SET username=?,email=? WHERE id=?";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"sss",$input_1,$input_2,$input_3);

    if(mysqli_stmt_execute($stmt))
    {
        echo 'UPDATED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);
    }
    else
    {
        echo 'Mysqli Error: ' .mysqli_error();
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_errno();
        echo '<br>';
        die('Failed to INSERT!');
    }
}
else
{
    echo 'Mysqli Error: ' .mysqli_error();
    echo '<br>';
    echo 'Mysqli Error No: ' .mysqli_errno();
}

mysqli_stmt_close($stmt);
mysqli_close($conn);

D).

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'magi'; //username.
$input_2 = 'admin@magi.com'; //email.
$input_3 = '0'; //id.

$sql = "UPDATE users SET username=?,email=? WHERE id=?";

if($stmt = mysqli_prepare($conn,$sql))
{
    mysqli_stmt_bind_param($stmt,"sss",$input_1,$input_2,$input_3);
    mysqli_stmt_execute($stmt);

    if(mysqli_stmt_affected_rows($stmt))
    {
        echo 'UPDATED SUCESSFULLY: ' .mysqli_stmt_affected_rows($stmt);
    }
    else
    {
        echo 'Mysqli Error: ' .mysqli_error();
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_errno();
        echo '<br>';
        die('Failed to INSERT!');
    }
}
else
{
    echo 'Mysqli Error: ' .mysqli_error();
    echo '<br>';
    echo 'Mysqli Error No: ' .mysqli_errno();
}

mysqli_stmt_close($stmt);
mysqli_close($conn);

Looking above, is there any that is unnecessarily going through the IF condition ? (Is pointless). If so, then why ?

Thank you for your helps!

How Can I Hookup My Mobile Phones To My PC Monitor ?

Hiya,

I program on PC laptop mostly throughout the year.
And in winter, program on my mobile phone. Nokia 2 (old timer).
I got now Samsungs which are better. So thinking of programming on them too, just for fun (so to speak).
I am curious to see my Samsungs Desktops on my PCs monitor.
Meaning, I want to hookup my Samsung Mobile Phones to my PC monitor so I do not have to use the mobile's little screens but use the PC monitor's big screen instead.
now, my mobiles use usb charger. That means, they only got usb ports.
So, which type of cable or connector I should buy to hookup the Samsung Phones to my PC monitor ?
I guess I will need some kind of adapter. So, which one ? Care to advise ? better, care to provide a link to any store selling those particular adapters ?

MONITOR DETAILS:

MONITOR: DELL E1916HV DISPLAY 18.5"
S/N: #AA2319310519
https://www.startech.com.bd/dell-e1916hv-18-5-inch--led-monitor

MOBILE DETAILS:
SAMSUNG GALAXY A9.

Help Me Choose Right PC Power Supply

Hello People,

I am not much oif a techie guy.
I got fed-up of using laptops for about a dacade now and so reverted back to pc.
PCs in Europe last 5 years with no hardware issues but here in Asia you are lucky if a part does not fail after 12 months. So bought this pc (as parts and got the shop to assemble it) and after 1 yr the power supply died. So went to another shop and had it replaced. Bad thing is, the new part died about the 3mnths later. Got fedup of the pc and now started using the old 2015 laptop for about 6mnths now. Got to get the pc working again as this laptop is 2 yrs out of date now and might die on me anytime.
If this laptop was bought here in Asia I know it wowuld have long died on me before the 5yrs was over. Chinese goods, hey!
Anyway, this is my Asian pc spec. I need your advice which power supply to buy (spec) so it lasts atleast 12months and nbot a lousy 3 month or even 1 month!

PROCESSOR: INTEL CORE 13 3RD GEN
S/N: #1635

MOTHERBOARD: GIGABYTE INTEL CHIPSET H61M-DS2
S/N: #184540016033

RAM: ATA DDR3-4GB
S/N: #213900264632

STORAGE: TEAM 120GB SSD SATA
S/N: #AA2319310519
WARRANTY 1 YEAR

MONITOR: DELL E1916HV DISPLAY 18.5"
S/N: #AA2319310519
WARRANTY 3 YEAR

MOUSE: LOGITECH B-100

KEYBOARD: LOGITECH K120

CASING & PSU: SPACE D-096

HARD DISK WESTERN DIGITAL (WD)
WARRANTY 1 YEAR
S/N: #WXDIAA0M2326

UPS: SANTAK R60
S/N: #190408-87430065

Can someone tell me if the parts specs are good or bad or ok ?
I bought all these back in Christmas 2020. Was the spec good for that year ?
For some reason the parts, especially the monitor feels like light-weight and toyish. You know how chiinese goods feel. Cheap and light weight. Toyish feeling which do not last long, unlike 80's Japanese hardwares and parts (electronics) which were heavy and good quality, lasting over 5 years. In Europe hardwares and parts (electronics) feel heavy and good quality lasting atleast 5 yrs. Hence I had no problems with my PCs and laptops, ever throughout the 5 yrs guarantees. No parts ever need replacing. And the PCs/laptops last well over 5 yrs too!
Nevertheless, they are not that much high tech quality as the Japanase electronics hardwares & parts as USA been suppliying the European markets since the 90's (ever since Japan started losing the global market as the dominator) and USA hardwares (electronics) are not that solid (good quality) as Japanese were.
But these Chinese light weight stuffs, which flood the Asian markets are a real light weight, crap quality and a total disgrace. Parts come with only 1 year warranty and most die within or fater 3 months and need fixing or replacing!
Very different from the PCs I bought in EU. hardwares there feel like real stuffs. Not toys.
This crap of a pc I bought here (yes in Asian Market) for the first time in 2020 as starting to be a headache. Hance, asking you all these questions on my spec. The shop said it was not Chinese parts as they are bad quality and last very low time. I can't remember if he said the parts were from Taiwan or what. I think he said Taiwan or maybe he said Korea. Cannot remember fully.

Which Tablet Is Suitable For Php & Python Programming ?

Good Evening Folks,

I got some basic questions on Tablets.

Which Tablet do you recommend I buy to use for php programming ?
I never bought a Tablet before. Now taken an interrst to buy one but need to buy one suitable for programming. I Always program using pc or mobile phone. Now let us change this.

What bare min spec I should get ?
Ram ?
HDD ?

To hookup an external keyboard & mouse, which ports must the Tablet have ?
USB ?

To hookup an external monitor (like to my desktop pc monitor), which ports must the Tablet have ?
HDMI ?

To hookup an external monitor (like a 22 inches internet tv), which ports must the Tablet have ?
HDMI ?

Are there any Adapters I can use to hookup the Tablet to external hardwares like monitors and TVs ? What are these adapters called and which you recommend ?

Which IDEs you recommend for my Tablet to program in php ?

I been reading reviews and some people say it is ok to prigram in a Tablet while others don;t recommend it saying the onscreen keyboard would take-up most of the screen.
If I hookup the Tablet to an external keyboard then would not the Tablet detect the external keyboard and auto hide the onscreen one or I have to manually hide it ?

Which Tablet you recommend for Android OS to program with a suitable php IDE ?

Anything else I should know ?

My budget is 200 British Sterling. That's $300USD.
Planning on learning Python and building websites aswell as desktop softwares for PCs, Tablets and Mobile Phones.
And ofcourse, need to install wamp/xampp as localhost.
So bare this in mind when responding as the hardware got to be good enough to deal with all this.

Thanks!

Why Password Hash Changes Each Time ?

Hi,

Seem to be having problem with the password_hash() as it keeps changing the hash value of the same password. Why ?
When each time I refresh the page, the $password_hashed value changes! Why ? The $password is still the same who's value is: '123'.
And password_verify($password,$db_password) always echoes '1' (TRUE). How so, since the $hashed_password value changes each time ? Odd!

Try this code in your browser and see for yourself.
Refresh the page on each occassion and see what you get echoed!

echo 'password: ' .$password = '123'; echo '<br>';
echo 'password hashed: ' .$password_hashed = password_hash($password,PASSWORD_DEFAULT); echo '<br>';
//$db_password or database password is now the hash: $2y$10$cie0yEEiLdJkK3IDj8ABXO/vTMvR3F3twO2SVY1VC6D3zP1Fp/xPW

echo 'db password: ' .$db_password = '$2y$10$cie0yEEiLdJkK3IDj8ABXO/vTMvR3F3twO2SVY1VC6D3zP1Fp/xPW'; echo '<br>';
echo password_verify($password,$db_password); //echoes '1' (true).

I understand that the hash value changes each time due to the SALT changing each time on page refresh but how will the password_verify() know which SALT to use on each occassion to decrypt the hash ?

Why MySql Fails To Delete Table Columns ?

Good Evening People,

No matter what I do in mysql, why I get this following error where the rows do not get deleted ?
**Error
SQL query: Copy Edit Edit

DELETE FROM phpmyadmin.pma__column_info WHERE db_name = 'buzz' AND table_name = 'submitted_links_index2' AND column_name = 'title'
MySQL said: Documentation

#1142 - DELETE command denied to user 'pma'@'localhost' for table 'pma__column_info'**

I am trying to delete two cols in my mysql tbl:

title
header

Mysql page url:
http://localhost/phpmyadmin/

How To Write EMBEDDING Code For Particular Section In Your Page ?

Hello Programmers,

We use the fragment in urls for the browser to hone in on a particular secion on our page.
http://www.yoursite.com/#heading_number~1
http://www.yoursite.com/#heading_number~2

And so on.
Now, we can easily open those particular sections in iFrames of your's or third party site's) that does not have a fragment {#) in the url.
And, let's say you want to open in an iFrame that particular section (on some page of your's or on third party site's) then how would you code the iFrame to be able to show the page honed-in on your desired section ? You cannot do it with iFrames in this case. Now can you ? So, let's try embedding here. That's why I ask, how to write the embedding code here ?

iFrame Security Questions

Hello Php Programmers,

I want to open iframes, more than one, to some of my webpages from other webpages.
What do I need to be careful off so no crook injects anything malicious on my site or on my visitors' clientsides ?

Q1.
Which of these attributes, mentioned in the tutorial, do I need to add or ignore on my iFrames for the sake of preserving security so no holes popup ?

allow
allowfullscreen
height
loading
name
referrerpolicy
sandbox
src
srcdoc
width

https://www.w3schools.com/tags/tag_iframe.ASP

Bear in mind, I won't be using Javascript on my website or iFrame pages.
Only html, php and maybe css.

I know this is lame for security purpose:

<iframe src="https://www.w3schools.com" title="W3Schools Free Online Web Tutorials">
</iframe>

Same question goes for if I want to open iFrames to third party sites and I do not want to jeopordise security on my end, visitor's end or the site's end to where I open the iFrames to. I must have security intact. Do not want other sites getting harmed or my website visitors getting harmed by internet malicious crooks due to my insecured iFrame codes and find myself getting sued left & right.
How would you code the iFrames on both cases.

Why password_verify() function Not Working ?

Php Programmers,

Getting to build a login page using the php's passwordverify() function.
Issue is, no matter if I give correct password or incorrect, I always get message 'Incorrect user Credentials'.
Why is that ?
The details on Mysql Looks like this:

id | domain | password
0 | gmail.com | 373b29d2837e83b9ca5cec712a5985843df271cc

Obviously, password is hashed using sha_256.

ini_set("display_errors",1);
ini_set("display_startup_errors",1);
error_reporting(E_ALL);

echo login_form();

if($_SERVER['REQUEST_METHOD'] === 'POST')
{
    echo __LINE__; echo '<br>';//DELETE

    check_user_input();

    echo __LINE__; echo '<br>';//DELETE

    process_login_form();

    echo __LINE__; echo '<br>';//DELETE
}

function login_form()
{
    echo $login_form = 
    '
    <div name="center pane" id="center pane" align="center" size="50px" width="33%">
    <form method="POST" action="" name="login_form" id="login_form" width="50%">
    <fieldset>
    <label for="domain">Domain</label>
    <input type="text" name="domain" id="domain" size="50" minlength="5" maxlength="253" title="Input your Domain" placeholder="yourdomain.tld">
    <br>
    <label for="password">Password</label>
    <input type="text" name="password" id="password" size="50" minlength="8" maxlength="25" title="Input your Password" placeholder="alpha-numerical-chars">
    <br>
    </fieldset>
    <fieldset>
    <button type="submit" name="login" id="login" title="Submit Form">Login!</button>
    </fieldset>
    </form>
    </div>
    ';
}

function check_user_input()
{
    if(!EMPTY($_POST['domain']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $domain = trim($_POST['domain']);
    }
    elseif(!EMPTY($_POST['domain_email']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $domain_email = trim($_POST['domain_email']);
    }
    else
    {
        die('Input your Domain');
    }

    if(!EMPTY($_POST['password']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $hashed_password = hash('sha256',$_POST['password']); 
    }
    else
    {
        die('Input your Password');
    }
}

function process_login_form()
{
    echo __LINE__; echo '<br>';//DELETE

    Global $domain;
    Global $password; //DELETE
    Global $hashed_password;

    //Query DB.
    //Check if User already registered or not.
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");
    $stmt = mysqli_stmt_init($conn);
    $sql_count = "SELECT password FROM domains WHERE domain = ? OR domain_email = ?";

    if(!mysqli_stmt_prepare($stmt,$sql_count))
    {
        echo __LINE__; echo '<br>';//DELETE

        echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
        echo '<br>';
        die('Registration a Failure!');
    }
    else
    {
        echo __LINE__; echo '<br>';//DELETE
        echo $domain = $_POST['domain'];  echo '<br>';//DELETE
        echo $password = $_POST['password']; echo '<br>';//DELETE

        mysqli_stmt_bind_param($stmt,"sss",$domain,$domain_email,$password);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt,$db_password);
        mysqli_stmt_fetch($stmt);

        if(!password_verify($password,$db_password)) //FINISH THIS LINE.
        {
            echo __LINE__; echo '<br>';//DELETE
            echo 'password: ' .$password; echo '<br>';
            echo 'hashed password: ' .$hashed_password; echo '<br>';
            echo 'db_password: ' .$db_password; echo '<br>';

            die('Incorrect User Credentials!');
        }
        echo __LINE__; echo '<br>';//DELETE

        mysqli_stmt_close($stmt);
        mysqli_close($conn);

        echo __LINE__; echo '<br>';//DELETE
        echo 'password: ' .$password; echo '<br>';
        echo 'hashed password: ' .$hashed_password; echo '<br>';
        echo 'db_password: ' .$db_password; echo '<br>';
        unset_sessions();
        echo __LINE__; echo '<br>';//DELETE
        echo 'password: ' .$password; echo '<br>';
        echo 'hashed password: ' .$hashed_password; echo '<br>';
        echo 'db_password: ' .$db_password; echo '<br>';
        header('location: home.php');
        exit;
    }
}

Logging In With Sql’s COUNT Function

Helle Fellow Programmers!

Unlike last time where I was checking for matching rows count using mysqli_stmt_rows_count():

https://www.daniweb.com/programming/web-development/threads/539306/login-with-prepared-statements-mysqli-stmt-num-rows-function

On this thread, I am checking for matching rows count using Sql's COUNT function.

This means, both threads are not same so mods do not close them.

Issue is, on both threads, no matter if I give correct password or incorrect, I always get message 'Incorrect user Credentials'.
Why is that ?
The details on Mysql Looks like this:

id | domain | password
0 | gmail.com | 373b29d2837e83b9ca5cec712a5985843df271cc

Obviously, password is hashed using sha_256.

Here is the php code:

ini_set("display_errors",1);
ini_set("display_startup_errors",1);
error_reporting(E_ALL);

echo login_form();

if($_SERVER['REQUEST_METHOD'] === 'POST')
{
    echo __LINE__; echo '<br>';//DELETE

    check_user_input();

    echo __LINE__; echo '<br>';//DELETE

    process_login_form();

    echo __LINE__; echo '<br>';//DELETE
}


function login_form()
{
    echo 
    '
    <div name="center pane" id="center pane" align="center" size="50px" width="33%">
    <form method="POST" action="" name="login_form" id="login_form" width="50%">
    <fieldset>
    <label for="domain">Domain</label>
    <input type="text" name="domain" id="domain" size="50" minlength="5" maxlength="253" title="Input your Domain" placeholder="yourdomain.tld">
    <br>
    <label for="password">Password</label>
    <input type="text" name="password" id="password" size="50" minlength="8" maxlength="25" title="Input your Password" placeholder="alpha-numerical-chars">
    <br>
    </fieldset>
    <fieldset>
    <button type="submit" name="login" id="login" title="Submit Form">Login!</button>
    </fieldset>
    </form>
    </div>
    ';
}


function check_user_input()
{
    if(!EMPTY($_POST['domain']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $domain = trim($_POST['domain']);
    }
    elseif(!EMPTY($_POST['domain_email']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $domain_email = trim($_POST['domain_email']);
    }
    else
    {
        die('Input your Domain');
    }

    if(!EMPTY($_POST['password']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $hashed_password = hash('sha256',$_POST['password']); 
    }
}


function process_login_form()
{
    echo __LINE__; echo '<br>';//DELETE

    Global $domain;
    Global $password; //DELETE
    Global $hashed_password;

    //Query DB.
    //Check if User already registered or not.
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");
    $stmt = mysqli_stmt_init($conn);
    $sql_count = "SELECT COUNT('id') FROM domains WHERE domain = ? AND password = ?";

    if(!mysqli_stmt_prepare($stmt,$sql_count))
    {
        echo __LINE__; echo '<br>';//DELETE

        echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
        echo '<br>';
        die('Registration a Failure!');
    }
    else
    {
        echo __LINE__; echo '<br>';//DELETE

        mysqli_stmt_bind_param($stmt,"ss",$domain,$hashed_password);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt,$rows_count);
        mysqli_stmt_fetch($stmt);

        if($rows_count<1) //User not registered.
        {
            echo __LINE__; echo '<br>';//DELETE
            echo 'password: '.$password; echo '<br>';
            echo 'hashed password: '.$hashed_password; echo '<br>';

            mysqli_stmt_close($stmt);
            mysqli_close($conn);
            die('Incorrect User Credentials!');
        }
        mysqli_stmt_close($stmt);
        mysqli_close($conn);

        echo __LINE__; echo '<br>';//DELETE
        echo 'password: ' .$password; echo '<br>';
        echo 'hashed password: ' .$hashed_password; echo '<br>';

        header('location: home.php');
        exit;
    }
}

Login With Prepared Statements Mysqli_Stmt_Num_rows() Function

Hi,

I am trying to create a login page using the sql's mysqli_stmt_num_rows() function.
Issue is, no matter if I give correct password or incorrect, I always get message 'Incorrect user Credentials'.
Why is that ?
The details on Mysql Looks like this:

id|domain|password

0|gmail.com|373b29d2837e83b9ca5cec712a5985843df271cc

Obviously, password is hashed using sha_256.

Here is the php code:

<?php
ini_set("display_errors",1);
ini_set("display_startup_errors",1);
error_reporting(E_ALL);

echo login_form();

if($_SERVER['REQUEST_METHOD'] === 'POST')
{
    echo __LINE__; echo '<br>';//DELETE

    check_user_input();

    echo __LINE__; echo '<br>';//DELETE

    process_login_form();

    echo __LINE__; echo '<br>';//DELETE
}


function login_form()
{
    echo 
    '
    <div name="center pane" id="center pane" align="center" size="50px" width="33%">
    <form method="POST" action="" name="login_form" id="login_form" width="50%">
    <fieldset>
    <label for="domain">Domain</label>
    <input type="text" name="domain" id="domain" size="50" minlength="5" maxlength="253" title="Input your Domain" placeholder="yourdomain.tld">
    <br>
    <label for="password">Password</label>
    <input type="text" name="password" id="password" size="50" minlength="8" maxlength="25" title="Input your Password" placeholder="alpha-numerical-chars">
    <br>
    </fieldset>
    <fieldset>
    <button type="submit" name="login" id="login" title="Submit Form">Login!</button>
    </fieldset>
    </form>
    </div>
    ';
}


function check_user_input()
{
    if(!EMPTY($_POST['domain']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $domain = trim($_POST['domain']);
    }
    elseif(!EMPTY($_POST['domain_email']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $domain_email = trim($_POST['domain_email']);
    }
    elseif(!EMPTY($_POST['password']))
    {
        echo __LINE__; echo '<br>';//DELETE

        $password = trim($_POST['password']);
    }
}


function process_login_form()
{
    echo __LINE__; echo '<br>';//DELETE

    Global $domain;
    Global $password; //DELETE
    Global $hashed_password;

    //Query DB.
    //Check if User already registered or not.
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");
    $stmt = mysqli_stmt_init($conn);
    $sql = "SELECT id FROM domains WHERE domain = ? AND password = ?";

    if(!mysqli_stmt_prepare($stmt,$sql))
    {
        echo __LINE__; echo '<br>';//DELETE

        echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
        echo '<br>';
        die('Registration a Failure!');
    }
    else
    {
        echo __LINE__; echo '<br>';//DELETE

        mysqli_stmt_bind_param($stmt,"ss",$domain,$hashed_password);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt,$id);
        mysqli_stmt_fetch($stmt);

        if($num_rows = mysqli_stmt_num_rows($stmt)<1) //User not registered.
        {
            echo __LINE__; echo '<br>';//DELETE
            echo 'password: '.$password; echo '<br>';
            echo 'hashed password: '.$hashed_password; echo '<br>';

            mysqli_stmt_close($stmt);
            mysqli_close($conn);
            die('Incorrect User Credentials!');
        }
        mysqli_stmt_close($stmt);
        mysqli_close($conn);

        echo __LINE__; echo '<br>';//DELETE
        echo 'password: ' .$password; echo '<br>';
        echo 'hashed password: ' .$hashed_password; echo '<br>';

        echo 'You are logged in!';
        exit;
    }
}

Experimenting With simplehtmldom

Hi,

I get the feeling from this forum that simplehtmldom is old stuff.
Nevertheless, experimenting with it since a simple tutorial code depends on it.

Check this Xml SItemap Link Extractor

include_once('simplehtmldom_1_9_1/simple_html_dom.php');

//Works.
//$sitemap = 'https://www.rocktherankings.com/post-sitemap.xml';
//$sitemap = "https://www.rocktherankings.com/sitemap_index.xml"; //Has more xml files.

//Does not work. Shows blank page.
$sitemap = "https://bytenota.com/sitemap.xml";


$html = new simple_html_dom();
$html->load_file($sitemap);

foreach($html->find("loc") as $link)
{
    echo $link->innertext."<br>";
}

It manages to extract links of html files aswell as xml files from these 2 xml sitemaps:
$sitemap = 'https://www.rocktherankings.com/post-sitemap.xml'; Has no further Xml Sitemaps listed.
$sitemap = "https://www.rocktherankings.com/sitemap_index.xml"; //Lists more xml files.

So far, so good.
But why it fails to extract further xml sitemap links from this following particular xml sitemap ? That is the big issue!
https://bytenota.com/sitemap.xml

How Many Levels Deep Do Xml SItemaps Go ?

Hiya,

I need to know something.
First I thought Sitemap Xml files will list all .html and .hml and .shtm and .shtml files. All pages of the website.
But now I see, Sitemap xml files also list other xml files. Check this one out for what I mean:
https://www.rocktherankings.com/sitemap_index.xml

So that means, I got to program my web crawler to go one level deep to find the site links (html files).
Question is: Does this happen more than one level deep ?
I mean does it do this ....
I go to a Sitemap xml file.
I see further xml files. I clickover to an xml file. Thus go one level deep.
I see more xml files listed. I clickover to an xml file. Thus go two level deep.

How many levels deep can a site go like this to list their html files ?
I need to know this to program my crawler how many levels it should check before giving up. Do not want to be going in an endless loop and get my crawler get into a trap.

How To Parse File Type Or File Extension Of A Given Url ?

Hi,

I used to know how to do this but forgotten.
How can I check the extension of a url ?
You see, sometimes sitemap xml files do not list site urls (.html) for my crawler to extract all the urls.
Instead, they list further xml files and so my crawler has to go one level deep to extract all the site urls (.html).
And so, I now need to teach the crawler to detect the file type once it extracts urls from a page.

Let's say, my crawler extracted this url/link on a page:
https://www.rocktherankings.com/sitemap_index.xml

Now, how to detect the file type or file extension of that url ?
Which php function to use ? I see parse_url() won't do the job.
I really do not want to be using explode() function here and doing things the long way. I remember php has a specific file type function to do things the shorter way to detect the file type.

Can This OOP Be Convert To Procedural Style ?

I am still at procedural style programming. And so, oop code samples confuse me.
I found this oop style. Any chance you can show me how to convert this to procedural style ?
Test the code. It woks fine!
https://bytenota.com/parsing-an-xml-sitemap-in-php/

// sitemap url or sitemap file
$sitemap = 'https://bytenota.com/sitemap.xml';

// get sitemap content
$content = file_get_contents($sitemap);

// parse the sitemap content to object
$xml = simplexml_load_string($content);

// retrieve properties from the sitemap object
foreach ($xml->url as $urlElement) {
    // get properties
    $url = $urlElement->loc;
    $lastmod = $urlElement->lastmod;
    $changefreq = $urlElement->changefreq;
    $priority = $urlElement->priority;

    // print out the properties
    echo 'url: '. $url . '<br>';
    echo 'lastmod: '. $lastmod . '<br>';
    echo 'changefreq: '. $changefreq . '<br>';
    echo 'priority: '. $priority . '<br>';

    echo '<br>---<br>';
}