Jump to content

WesleyA

Members
  • Posts

    172
  • Joined

  • Last visited

Posts posted by WesleyA

  1. trimming the input first works fine. Thanks for the suggestion

     

    Now, I want to use get_headers to test if a website exists. But testing only at status code 200 seems not enough. Sometimes an URL gives code 301 or 302 or so.

     

    So how exactly is get_headers used? What is recommended I mean. Is it possible to check all status codes and how is that done?

  2. ok this is the output of an URL giving an error message:

     

     

     

     

    string ' http://www.facebook.com' (length=24)

    ( ! ) Warning: get_headers(): This function may only be used against URLs in ......\WebSiteValid\test-get-headers.php on line 30 Call Stack # Time Memory Function Location 1 0.0401 245968 {main}( ) ..\test-get-headers.php:0 2 0.0420 246104 get_headers ( ) ..\test-get-headers.php:30 boolean false


    Checks with curl get info Array ( => http://www.facebook.com/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => Array ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 )
  3. 
        <html><center><br><br><br>checks with get headers
    
        <form action="#" method="post">
        <input type="text" name="webadres" value=" " required>
        <br>
        <input type="submit" value="Send" ><br><br><br>
        </form>
         <?php
         if ($_SERVER['REQUEST_METHOD'] == 'POST'){
           
             $sites= $_POST['webadres'];
    		 var_dump($sites);
    		 
    		if (isset($sites)) {
    
    
    	var_dump(get_headers($sites));
         }
    
         ?>
    
         <br><br>Checks with curl get info
    
         <?php
    
         $url = curl_init($sites);
         curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
         $result = curl_exec($url);
         $info = curl_getinfo($url);
         print_r($info);
         curl_close($url);
    
         } ?>
    
         </html>
    

    I made above script to test whether a webadress exists or not.

     

    I'm very surprised that a lot of inputs dont give any result, they actually give a php error message.

     

    using sites like http://www.facebook.com does not work, for it twitter it runs. pinterest does only run http and not https. I also found sites like http://www.bbc.co.uk or http://www.cnn.com and more giving no result.

     

    Can someone explain why this happens and how to securily check the existance of a website.

     

     

     

  4. OkI think the last option provides me of the output I need but I have a range of names and drinks.

     

    What way can it be inserted?

     

    Is this correct?

    $data = array( array( 'name' => '$names','drink' => '$drinks'))
    

    or maybe $data[]?

     

    ..................

     

    This does not work for instance:

    <?php
    		$naam = array('Mark', 'Lauren', 'Baasgozer');
    		$drinks = array('cocktail', 'champaign', 'Wodka');
    	$data = array( array( 'name2' => $naam ,'drink2' => $drinks));
    			       
    
    
    foreach($data as $row) {
    	
    	
      echo $row['name2'] . ' ' . $row['drink2'];
      echo '<br>';
    }
    	?>
    
  5. My goal is to loop with foreach through two variables.

     

    So I found this script;

    <?php
        $abc = array('Mark','Laura');
        $add = array('cocktails','champagne');
        $array = array($abc,$add);
    
        foreach ($array as list($arr1, $arr2)) {
    		// echo '<br>';
    	
    		echo '<br>';
             echo $arr1;
    		 echo '<br>';
             echo $arr2;
        }
    

    But the output is not wat is desired. It says:

     

     

     

    Mark
    Laura
    cocktails
    champagne

     

    And I would rather have:

     

     

    Mark cocktails

    Laura Champagne

     

    Is there any function / command in the php array reference to do this or should other code be used?

  6. Hi there

     

    I'm looking for a way to strip multiple backslashes. I'm able to strip up to 7 backslashes.

     

    This is my code:

    $url = stripslashes($url);
    $url = stripslashes($url);
    $url = stripslashes($url);
    

    You read it well, I used it 3 times. I know the backslash is a delimiter so it is necessary to use it 3 times to strip one slash. But my goal is (like with other characters) to strip all.

     

    How is PHP handling this?

  7. @ justsomeguy

     

    What I want is different.

     

    I noticed an important difference between MYSQL punctuation and PHP. Am I right that MYSQL in this way differs from PHP?

     

    Why is this? And how should I write the code above in the former posting; in PHP?

  8. I use for instance this in the sql console

         CREATE TABLE temp SELECT DISTINCT col1, col2, col3, col4, col5 FROM my_table GROUPED BY col1;
    

    After that I drop my_table

          DROP TABLE my_table; 

    then I use ALTER TABLE and RENAME like this

         ALTER TABLE temp RENAME TO my_table
    

    But I need to make a php script of it.

     

    so my_table is in my case $var

     

    How should the query look like then?

  9. I found different techniques online.

     

    One is with SELECT DISTINCT. The result is an output of all unique fields from a specified column . The technique makes you create a new table with only these unique column fields.

     

    I would like to use these commands but then without having to make a new table. Maybe I decide to do make it with a new table and then change the new name into the old name.

     

    But if there is an easier way I would like to do that.

     

    @dsonesuk : I realize now it is not a duplicate record but a duplicate field. I explained that wrong: :facepalm:

     

    It's not I want to create a phonebook with only appearing single occurences of 1 family name :lol:

  10. I should have posted my own code making it clearer.

    <form action="#" ><SELECT name="rubsel" class="btn"><?php$tmp=0;while($row = $result->fetch_assoc() ) {$reeks = implode(" " , $row); ?>        <optgroup ="btn" label = "<?php echo $reeks; ?>" ><?php     echo $reeks ;$tmp ; ?><option class="btn" name="rub_sub1" value="<?php echo $reeks; ?>">1 t/m 10        </option><option class="btn" name="rub_sub2" value="<?php echo $reeks; ?>">11 t/m 20       </option><option class="btn" name="rub_sub3" value="<?php echo $reeks; ?>">21 t/m 30       </option><option class="btn" name="rub_sub4" value="<?php echo $reeks; ?>">31 t/m 40       </option></optgroup><?php $tmp++;}?></SELECT><br><br><input type="submit" class ="btn" name ="tab_wrd" value="Kies Rubriek" /> <br><br></form>

    name "rub_sub1" is not read and cant be output.

  11. This is an example working with optgroup.

    
    
    <form action="#" ><SELECT name="rubsel" class="btn"><?php$tmp=0;while($row = $result->fetch_assoc() ) {$reeks = implode(" " , $row); ?>        <optgroup ="btn" label = "<?php echo $reeks; ?>" ><?php     echo $reeks ;$tmp ; ?><option class="btn" name="rub_sub1" value="<?php echo $reeks; ?>">1 t/m 10        </option><option class="btn" name="rub_sub2" value="<?php echo $reeks; ?>">11 t/m 20       </option><option class="btn" name="rub_sub3" value="<?php echo $reeks; ?>">21 t/m 30       </option><option class="btn" name="rub_sub4" value="<?php echo $reeks; ?>">31 t/m 40       </option></optgroup><?php $tmp++;}?></SELECT><br><br><input type="submit" class ="btn" name ="tab_wrd" value="Kies Rubriek" /> <br><br></form>

    What i would like to know is how the input is being processed when using php.

     

    Especially how to find exactly the value of <option>

     

    The Select name input is found and echoed but what if I put a name attribute in the option element? I cant get an output of that.

     

    Or is there another way to get the option value with other attributes for instance?

  12. I dropped a column (linknum) in a table (wine) with mysql in the console

     

    After that I wanted to make it again

         ALTER TABLE wine ADD linknum INT DEFAULT '1' NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

    but now I recieve an error message like this:

    ERROR 1067 (42000): Invalid default value for 'linknum'

    How can I solve it, and create a column called linknum again, starting with 1 and incrementing 1 ?

  13. Is it possible to use an array, so a range of numbers to delete records from a table?

     

    This is the normal query

         $sql = "DELETE FROM MyGuests WHERE id=3";

    But this only deletes one record.

     

    I have several numbers and I would like to use an array but I'm not sure whether it is possible or not. Can you just use something like

          $sql = "DELETE FROM MyGuests WHERE $_GET['id']";

    so var_dump($_GET['id']); would be something like: 5, 8, 14, 88 and all these records would be deleted.

     

    Like this:

     

    array (size=5)0 => string '7' (length=1)1 => string '11' (length=2)2 => string '15' (length=2)3 => string '17' (length=2)4 => string '21' (length=2)

  14. This is my situation

     

    If variable $conn has all variables (with a value)

         $conn = new mysqli($servername, $username, $password, $dbname);

    and then you use

         var_dump($conn);

    and the output would be null of all the values of $conn.

     

    What would it mean?

     

    Am I right the connection then needs to be re-established?

     

    I'm doing 2 queries on a database. First query is SHOW TABLES then make the user choose a table value. From this value a new query is done.

     

    So first connection is done.

     

    But can I use this connection or should I make a new one?

  15. There is an issue I have with creating a filter for the correct domain and toplevel domain. For example google.com is correct and all the other not.

     

    my code:

         function my_funct($data2) {        $data2 = preg_replace('#(http://www.|http:|https:|ftp://www.|https://www./|//|www.|htp:|htt:|htp:/|htt:/|)#  ' , '', $data2);         return $data2;         }

    but directories wil not be blocked

     

    like www.google.com/directory/page/page2

     

    is there a way to use preg_replace and put only domain and toplevel domain in it?

     

    maybe it is possible to negate it, but he entire validation of pre_replace would be changed I assume.

  16. I have a question about security and MYSQL. I installed MYSQL and PHPMYADMIN.

     

    I changed the root password.

     

    But when in PHPMYADMIN I see a list of users and priviliges.

     

     

    Usernames sound like: All, root or pma. I understand I need pma or root, but what is the use of All ?

         User name 	Host 	     Password 	Global privileges 	User group 	Grant 	Action     Any 	% 	         -- 	USAGE     Any 	localhost 	No 	USAGE 		     pma 	localhost 	Yes 	USAGE 		     root 	127.0.0.1 	Yes 	ALL PRIVILEGES 		     root 	::1 	        Yes 	ALL PRIVILEGES 		     root 	localhost 	Yes 	ALL PRIVILEGES 		

    Furthermore which priviliges and global rights should a user have when developing localhost?

  17. You can't allow for every combination, you can filter out attempts to inject code, invalid characters etc but you have to allow proper users to use common sense to check details and fill out a form correctly, and the use of confirmation page and confirm email page, can help to weed out undesirables, but that won't catch all because there are sites where you can create a 10min email (google).

     

    Yes I think it is not possible to secure something a 100%. But why not try to get as close as possible. But security is now not yet the issue for me as validating is more then just having crappy code in your database. An empty record is also useless even if it is done by accident.

     

    I found some code I changed:

        <?php    $string = "namename";    $newstring = str_replace("name", "Foo", $string, $count);       print "$count changes were made.n";     if ($count>1)    {    echo "<br> ". $newstring;}    ?>

    But the problem is that if you make a string like this;

        <?php    $string = "Hey name you can type your name in this field. Bye name";    $newstring = str_replace("name", "", $string, $count);       print "$count changes were made.n";     if ($count>1)    {    echo "<br> ". $newstring;}    ?>

    This causes the wrong output and I want to have the correct one, is there a solution?

×
×
  • Create New...