Josh Connerty 20 Unverified User

Thanks for the reply.
I'm not actually looking to build gutenberg blocks. I'm trying to understand how from a React perspective how it actually functions.
Sorry for the confusion.
Josh

Josh Connerty 20 Unverified User

Hello All,

I have a question regarding Gutenberg React. I'm familiar with React which is what leads me to not understanding how the process works.

React can only render JSX but Gutenberg seems to render HTML (presumably by setting inner html dangerously), however it also adds event listeners to the newly rendered "block". How does it do this?

Many Thanks,
Josh

Josh Connerty 20 Unverified User

Glad to hear it :)

Josh Connerty 20 Unverified User

Form:

<form id="myform" method="post" action="">
<input type="checkbox" class="ids" name="ids[]" value="1">
<input type="checkbox" class="ids" name="ids[]" value="2">
<input type="checkbox" class="ids" name="ids[]" value="3">
<input type="checkbox" class="ids" name="ids[]" value="4">
</form>

<div id="response"></div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script>
 $(document).ready(function() {
     $('.ids').click(function() {
        var state = ($(this).is(':checked')) ? '1' : '0';
        var myobj = {}
        console.log($(this).serialize())
        $.ajax({
            url: "test.php",
            type: "post",
            data: $(this).serialize() + "&state=" + state
        }).done(function(data) {
            $('#response').html(data);
        });
    });
 });
</script>

Endpoint:

<?php

    if (isset($_POST['ids'])) {
        $id_value = $_POST['ids'];
        $state = (int)$_POST['state'];
        $sql_check = "UPDATE toggle SET status= '$state' WHERE id = '$state' ";
        $result_check = mysqli_query($conn,$sql_check);

        if($result_check){
            echo "sucess";
        } else{
            echo "failure";
        }
    }

?>
Josh Connerty 20 Unverified User

I tested this while in a meeting so fingers crossed it works for you:

<?php

$ip_ranges = "63.119.179.0/24, 23.119.180.0/24,154.119.181.0/24,193.119.182.0/24,133.119.183.0/24";
    function multiCidrToRange($cidrs)
    {
        $return_array = array();
        $cidrs = explode(",",str_replace(" ","",$cidrs));
        foreach($cidrs as $cidr)
        {
            $begin_end = explode("/",$cidr);
            $ip_exp = explode(".",$begin_end[0]);
            $range[0] = long2ip((ip2long($begin_end[0])) & ((-1 << (32 - (int)$begin_end[1]))));
            $range[1] = long2ip((ip2long($range[0])) + pow(2, (32 - (int)$begin_end[1])) - 1);
            unset($ip_exp[3]);
            $ip_prefix = implode(".",$ip_exp);
            $count = str_replace($ip_prefix . ".","",$range[0]);
            $ncount = 0;
            while( $count <= (str_replace($ip_prefix,"",$range[0]) + str_replace($ip_prefix . ".","",$range[1])) )
            {
                $return_array[] = $ip_prefix . "." . $count;
                $count++;
                $ncount++;
            }
            $begin_end = false;
            $ip_exp = false;
            $range = false;
            $ip_prefix = false;
            $count = false;
        }
        return $return_array;
    }

    var_dump(multiCidrToRange($ip_ranges));

?>
matei_ commented: Thank you very much! You saved me. It works in the way I want it to. +0
Josh Connerty 20 Unverified User

Got meetings for the next couple of hours. I'll post something as soon as I get chance

Josh Connerty 20 Unverified User

OH I see. That won't work then. Let me look up the calculations for the range

matei_ commented: Any updates? Can't we work something from cidrToRange function? +0
Josh Connerty 20 Unverified User

You could create a custom plugin for this. Would need to know more about where the files are hosted and where you retrieve the student number from.

Josh Connerty 20 Unverified User

So if you var_dump the text field and it's an empty array it implies it has nothing in the textfield. I need to see more of how it's implemented

matei_ commented: I solved the error, but the problem is now that I get only the IPs only to .24 and I should get until .255 +0
Josh Connerty 20 Unverified User

What does $pluginData hold? if you pass a list of comma separated range values to the function it will return an array of ip addresses from all of the ranges

matei_ commented: The $pluginData -> ipAddresses is the actual text area that holds all the CIDR ranges. +0
Josh Connerty 20 Unverified User

That's becuase the trigger is bound to the FORM element so when you use $(this) a little later on, you're refering to the form and not the checkbox.

The form only send the ID's of checkboxes that have been checked if this helps? Alternatively you need to bind the trigger on the checkbox and use it's state to update a hidden field that can contain the states and then serialized with the form data

KnowledgeMan commented: Thanks. I kinda understand what you mean. Can you please provide an example or guide on how to do it? +0
Josh Connerty 20 Unverified User

I adapted you ajax method to this and it works:

    $.ajax({
        url: "test.php",
        type: "post",
        data: $(this).serialize() + "&state=" + state
    }).done(function(data) {
        $('#response').html(data);
    });
KnowledgeMan commented: Thank you it is showing success but the database is not getting updated. I think the issue with state: var state = ($(this).is(':checked')) ? '1' : '0 +0
Josh Connerty 20 Unverified User

$state = (int)$_POST['state']; Refers to a post variable that has not been passed

KnowledgeMan commented: So how do I resolve it? Sorry for asking again I am new to programming +0
Josh Connerty 20 Unverified User

Did you put it outside of this logic?

var_dump($_POST); // Here
if (isset($_POST['ids'])) {
       $id_value = $_POST['ids'];
       $state = (int)$_POST['state'];

        foreach($id_value as $check) {

          $sql_check = "UPDATE toggle SET status= '$state' WHERE id = '$check' ";
          $result_check = mysqli_query($conn,$sql_check);

         if($result_check){
             echo "sucess";
         }else{
             echo "failure";
         }
        }
KnowledgeMan commented: No sorry my mistake, yeah now it generating array(1) { ["ids"]=> array(1) { [0]=> string(1) "1" } } when I click the first checkbox +0
Josh Connerty 20 Unverified User

Try var dumping the $_POST object

var_dump($_POST);

If this returns nothing then you know there is an issue with the reference back to the data that was sent

KnowledgeMan commented: Yes it does return nothing +0
Josh Connerty 20 Unverified User

Yep so what does the response on the "Network" tab say?

You should be able to click the request and it'll open another panel with headers and you want the one which reads "Preview" or "Response".

This is the data that your endpoint returns

KnowledgeMan commented: Yes so on request I get this value ids[]:[..] 0:"1",1:"2" and for reponse nothing +0
Josh Connerty 20 Unverified User

You can use console.log() within the trigger call

$('#myform').click(function() {
    console.log("Click event triggered");

in order to see if the trigger is ran through the console. If you click the "Network" tab in the "Inspect" you can see if the XHR/AJAX request is being sent.

KnowledgeMan commented: Ok, I am getting the message "Click event triggered", status code "200". So the form is getting submit +0
Josh Connerty 20 Unverified User

Something like that

<?php

    $ip_ranges = "32.89.178.30/24, 63.119.179.0/24, 23.119.180.0/24,154.119.181.0/24,193.119.182.0/24,133.119.183.0/24";
    function multiCidrToRange($cidrs)
    {
        $return_array = array();
        $cidrs = explode(",",str_replace(" ","",$cidrs));
        foreach($cidrs as $cidr)
        {
            $begin_end = explode("/",$cidr);
            $ip_exp = explode(".",$begin_end[0]);
            $range[] = $begin_end[1];
            $range[] = $ip_exp[3];
            unset($ip_exp[3]);
            $ip_prefix = implode(".",$ip_exp);
            $count = $range[1];
            while( $count <= ($range[0] + $range[1]) )
            {
                $return_array[] = $ip_prefix . "." . $count;
                if($count == 255)
                { exit; }
                $count++;
            }
            $begin_end = false;
            $ip_exp = false;
            $range = false;
            $ip_prefix = false;
            $count = false;
        }
        return $return_array;
    }

    var_dump(multiCidrToRange($ip_ranges));

?>
matei_ commented: Using "var_dump($pluginData -> ipAddresses)" it shows me this: "array(0) { }"... +0
Josh Connerty 20 Unverified User

Give me an 20 mins and I'll write something for you. Just got to finish what I'm on and push to live

matei_ commented: Sure, thank you very much! +0
Josh Connerty 20 Unverified User

$cidrs is not defined yet. This would be for instance explode(",",$my_form_field) passing an array of ranges

matei_ commented: I get only the CIDR, e.g.: 88.39.88.0/24, 89.33.88.0/24 etc.. I want to retrieve a list with IPs from all the CIDRs that I have in my textarea. +0
Josh Connerty 20 Unverified User

What results have you had so far?

KnowledgeMan commented: Thanks for the relpy. Well I get no errors on the page and nothing in inspector as well. +0
Josh Connerty 20 Unverified User
function cidrToRange($cidr) {
    $range = array();
    $split = explode('/', $cidr);

    if(!empty($split[0]) && is_scalar($split[1]) && filter_var($split[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
        $rangeStart = ip2long($split[0]) & ((-1 << (32 - (int) $split[1])));
        $rangeStartIP = long2ip($rangeStart);
        $rangeEnd = ip2long($rangeStartIP) + pow(2, (32 - (int) $split[1])) - 1;

        for($i = $rangeStart; $i <= $rangeEnd; $i ++) {
            $range[] = long2ip($i);
        }
        return $range;
    } else {
        return $cidr;
    }
}

$ip_arr = array();

foreach($cidrs as $cidr)
{
    array_merge(cidrToRange($cidr),$ip_arr);
}
echo '<ul>';
foreach($ip_arr as $ip)
{
    echo '<li>'.$ip.'</li>';
}
echo '</ul>';
matei_ commented: "Notice: Undefined variable: cidrs on line 41 && Warning: Invalid argument supplied for" - Line 41" foreach($cidrs as $cidr) +0
Josh Connerty 20 Unverified User

If theres discrepencies with spaces etc. I'd consider

$ips = explode(",",str_replace(" ","",$field)); // Gives IP's
foreach($ips as $key => $ip) {
    $range = explode("/",$ip);
    $ips[$key] = $range;
}

which will strip spaces out and then create an array of ip addresses

[0] => [[0] => 192.168.0.0, [1] => 30]
[1] => [[0] => 192.168.10.0, [1] => 10]
matei_ commented: Your function works as you said, but what I am trying to do is to retrieve a full list with IPs from the CIDR ranges that I have. +0
Josh Connerty 20 Unverified User

Because React does not carry out a page refresh the cookie storage that React has access to is outdated.

The best method for React & PHP authentication is to use token authentication:
Click Here

Josh Connerty 20 Unverified User

What did you change?

Josh Connerty 20 Unverified User

The usual way of achieving this functionality is to store a reference to the current player through a token/cookie and use that to refer to the related row in the database. For example:

  ________players________
  id  |    name    | gold
  25  | "Player 1" |  0

Being the database structure, if I wish to update "Player 1"'s gold count I would take the cookie value $_COOKIE['player_id'] to update the row in the database

<?php

    $player_id = $_COOKIE['player_id'];
    $new_gold = $old_gold + 2;

    $sql = mysqli_connect(HOST,USERNAME,PASSWORD);
    mysqli_select_db(DATABASE,$sql);

    $sql->query("UPDATE `players` SET `gold` = '" . $new_gold . "' WHERE `id` = '" . $player_id . "'");

?>

This poses a number of security concerns but the principle is the same.

I hope this is of some help.

Josh Connerty 20 Unverified User

This is quite an ambiguous question. Can you elaborate on exactly what you're trying to achieve?

Josh Connerty 20 Unverified User

From what I can see, you're short a closing <div> tag.

Josh Connerty 20 Unverified User

I don't have access to my suppliers database however each part will be populated from their website listing of that product, so when I add that product to the database I will do so with the website address of that part on my suppliers website. Periodically a CRONJOB will run to keep the table updated with price fluctuations. I'd prefer to have them stored in my database then have to reference my suppliers website every time a users goes to select a repair. Saves page load time.

The issues I am having is how to structure my tables. I get how I can use the information and what not I'm just strugling to figure out how many tables and their relationships to one another.

Thanks for the swift replies.

Josh Connerty 20 Unverified User

Like @minitauros said, change the header("Location: $file \r\n"); line with something like: echo '<script type="text/javascript">window.open(' . $file . ')</script>';

See if that works.

Josh Connerty 20 Unverified User

I'm a little confused as to why you want so much information to log someone in. Do you mean register?

You say you get 1 extra error? So this doesn't happen for every textfield? This is only happening for one?

My advice would be to change the else statements to echo something more specific to that field ie:

if( isset( $_POST['name'] ) ) {
    $name = $_POST['name'];
} else {
    echo '<div class="alert alert-danger">&quot;Name&quot; has not been completed!</div>';
}

That way you should be able to see which field is causing the problem and from that likely find a "name=" attribute that doesnt match up with a "$_POST['" variable.

Hope this helps and let me know how you get on.

Josh Connerty 20 Unverified User

Hello all,

I'm trying to build a system to provide an easy access but very clever service select (sounds confusing, I will explain).

Essentially I'm trying to create a system then will firstly store devices of different types, these types are:

  • Device type (iPhone, iPod, iPad)
  • Generation (4th Gen, 5th Gen etc.)
  • Model (iPhone 4s, iPod Touch , iPad 2 etc)

In addition to this I also need to give optional parameters for instance "colour" or "memory" and then options "black" or "16GB" etc. and as I said these must be optional, for instance an iPhone 3G or 3GS will need the parameter of "Memory" with options "8GB" or "> 8GB".

This is just the begining. I then need some way ofadding a repair to each item all though the repairs are muchly the same for instance "Front Screen" replacement. That's nice and easy and I could do that BUT what I need the system to do is calculate the cost of that repair by finding the correct parts involved in that repair. Each part is model specific.

I have a pretty advanced knowledge of PHP and MySql it's just the design of the table structure that leaves me a little bit cufuffled!

Any help would be greatly appreciated.

Thanks,
Josh.

Josh Connerty 20 Unverified User

You could always user Apache's .htaccess RewriteEngine

Josh Connerty 20 Unverified User

Because you shouldn't usually save a users password in the raw format, but instead save it as an ecrypted version using something like md5() you can't physically retrieve the users password.

Instead you could send out a reset email...

Josh Connerty 20 Unverified User

What exactly are you asking from us?

Josh Connerty 20 Unverified User

Thanks guys ;)

Josh Connerty 20 Unverified User

Pretty much yeah...

Josh Connerty 20 Unverified User

I took a look at cake but it's too intrusive, I'm looking for a a non-intrusive framework that just gives me a class to communicate with the database instead of controlling my file handling.

Josh Connerty 20 Unverified User

Hello All,

I wonder if someone could help me, I'm about to start work on a pretty heavy system that will be massively database driven. I was wondering if there was a framework out their a bit like jQuery for example that will assist me in all my MySql funcitonality.

Yes I do know how to use MySql, that isn;t the question I'm asking, I'm asking if anyone knows of a write less do more framework a bit like jQuery for JavaScript or Skeleton CSS for design?

Thanks in advance ;)

Josh Connerty 20 Unverified User
if ($channel_name6 = 'post') {
    $channel_name2 = $channel_name2;
} else {
    $channel_name2 =  "<img src='/videobox/data/uploads/images/$channel_name2' height='200px' width='100px'>";
}

Correct me if I'm wrong but are you not trying to see if $channel_name6 is equal to "post" and not set the value of it to "post"? If so then you need a double equals == not a single =.

Josh Connerty 20 Unverified User

And to add to this. Like @jkon said, it will be the ISP's designated IP for that client.

In most cases everytime your router connects to the ISP it will be designated a new IP address and therefore collecting their current IP address is pretty useless as next time they visit the website their IP address may well have changed. This is called a dynamic IP address.

Also the IP in the header of an email I beleive will be the Email Server's IP address (don't quote me). It's easy to test though.

My advice would be to grab the users IP address on filling out the registration form.

Josh Connerty 20 Unverified User

I'm not overly keen with using the "toggle()" function in this way. I'd advise using the "animate()" function. The reason being is that toggle doesn't communicate at which state the object is at present, it only does the oposite. So if it's displayed, it just hides it. If it's hidden it just displays it, it's a very simple function.

I'd be tempted to have the content elsewhere and populate the display area with the content from wherever you have it placed on your page. This way it avoids any unwanted content on your main display area...

Josh Connerty 20 Unverified User

Yes there is, however the most valid point that has been made this far is that the theory behind this is bizare.

All you would have to do is input the data to the database then re-print the page to the document looping through each feild and seeing what was posted last time using the $_POST global variables for instance.

if( strlen( $_POST['name'] ) > 0 ) {
    echo 'Name: <input type="text" name="name" value="' . stripslashes( $_POST['name'] ) . ' />';
} else {
    echo '<span style="color: red">This field is required...</span>';
    echo '<br />';
    echo 'Name: <input type="text" name="name" />';
}

BUT why would you want to input it to the database at all until you have a full data set and verified the data within it?

Josh Connerty 20 Unverified User

You need to use JavaScript and possibly AJAX to make this work. You need to put an "onChange" event on each drop down box so that the page reacts to the drop down box being changed. Do you have any JavaScript knowledge?

Josh Connerty 20 Unverified User

Saving your image as a PNG or GIF file format will keep the transparency from you image editor.

JPG/JPEG does not hold transparency therefore if you save a transparent image as a JPG you image editor will replace add a white background so as to cover the transparency.

Josh Connerty 20 Unverified User

Hey,

Okay my mums laptop is a pile of junk and she has managed to break it even more then it already is.

She is a windows live messenger obsessive so she really can't live without it. After updating Java it has signed in then crashed. I have checked the event viewer and I get the following report:

- System 

  - Provider 

   [ Name]  Application Error 
 
  - EventID 1000 

   [ Qualifiers]  0 
 
   Level 2 
 
   Task 100 
 
   Keywords 0x80000000000000 
 
  - TimeCreated 

   [ SystemTime]  2009-09-06T18:59:12.000Z 
 
   EventRecordID 9482 
 
   Channel Application 
 
   Computer Diane-PC 
 
   Security 
 

- EventData 

   wlcomm.exe 
   14.0.8064.206 
   498cddf7 
   0A09AAD4.x86.dll 
   0.0.0.0 
   4a97f4f7 
   c0000005 
   00005874 
   1d14 
   01ca2f241a61e291

Does this help anyone? She really can't do without it.

Josh Connerty 20 Unverified User

When I run an IP check on a local machine using the remote_addr method I get an internal IP, as this is an intranet I would presume it would do the same.

Josh Connerty 20 Unverified User

Also try defragmenting your hard drive and checking for any hard drive issues. It secondly (if it isn't malware, was also my first assumption) might be caused by a hard drive issue as it seems windows can't access some files or is taking very long to do so.

I believe windows provides software to check the hard drive etc on microsoft download.

kaninelupus commented: Will you STOP pegging yourself to requests for help, adding nothing but vague or useless tidbits! Is getting old. +0
Josh Connerty 20 Unverified User

Have you tried another mouse? It sounds more like the mouse as oppose to the OS.

Josh Connerty 20 Unverified User

The first thing you must figure out is what IP the intranet is going to read, whether it be internal or external IP.

Once you have found this out then it will be easier to use the IP to refer. If it reads internal then it is most likely you need PHP to do a lookup on an IP range.

Although if I understand right there is a security flaw with this method as if someone finds out the address of the employee area then they could just enter that URL into the browser and get there anyhow...

Is it not a better idea to make a login system then transfer them post login to the area they are required to be.