Jump to content

papaface

Members
  • Posts

    1,437
  • Joined

  • Last visited

    Never

Posts posted by papaface

  1. Hello,

    I am trying to work with the API for my website.

    Basically I need to load a specific url to instigate a series of functions. The API will call back my script later automatically.

     

    I am trying to find a reliable way of invoking a given URL so that it starts processing the API file BUT I don't want php to sit and wait until the API has finished doing its stuff.

     

    I want to update a field in my database when the API is run.

     

    I have tried if (get_headers($url)), but this takes to long.

    I have tried if (curl_exec($ch)) with timeout, but this is unreliable as it seems to start counting the moment curl is exec'd rather than the time from when the url is successfully loaded.

    I have tried file_get_contents($url), but like curl this is unreliable.

     

    Does anyone have any other ideas as to how I could do this?

     

    Any help would be appreciated!

  2. Wow, I come back and see a massive wall of text lmao

    I am using MadTechie's code as it seems to work pretty well for what I require. So thank you :)

    This is not related to regex however I wonder if someone could help me.

     

    As part of getting these urls (some are tinyurls) I am needing to find out what they actually link to i.e I need the link tinyurl redirects the user to

    Does anyone know of a way to do this?

  3. Hello,

     

    I am trying to extract a text link from a given string however I am finding it rather difficult and I am getting no matches for some reason.

     

    My code is:

    <?php
      $string = "some random text http://tinyurl.com/dmugyw";
    function do_reg($text, $regex)
    {
    preg_match_all($regex, $text, $result, PREG_PATTERN_ORDER);
    return $result = $result[0];
    }
    }
    
    do_reg($string, '\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]');
    ?>

     

    Can anyone explain why I am not getting a match?

     

    Any help would be appreciated :)

  4. How is that stored in the database?

    As "donater,vip"?

    If so you could try:

    <?php
       session_start();
       require_once('config.php');
       
       $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
       if(!$link) {
          die('Failed to connect to server: ' . mysql_error());
       }
       
       $db = mysql_select_db(DB_DATABASE);
       if(!$db) {
          die("Unable to select database");
       }
       
       $qry="SELECT * FROM `members` WHERE `username`='".$_SESSION['user']."'";
       $result=mysql_query($qry);
       
       $getbadge = mysql_query($qry) or die(mysql_error());
       
       if($result) {
          while ($row = mysql_fetch_array($getbadge)) {
    	  $imgs = explode(",",$row['badges']);
    	  foreach ($imgs as $v)
    	  	{
    	  	echo "<img src='badges/".$v.".gif' alt='".$v."'>";	
    	  	}
    } 
    }else {
                      echo "<p>".$error."</p><br>";
                      }
                      ?>
    

     

  5. Try:

    <?php
       session_start();
       require_once('config.php');
       
       $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
       if(!$link) {
          die('Failed to connect to server: ' . mysql_error());
       }
       
       $db = mysql_select_db(DB_DATABASE);
       if(!$db) {
          die("Unable to select database");
       }
       
       $qry="SELECT * FROM `members` WHERE `username`='".$_SESSION['user']."'";
       $result=mysql_query($qry);
       
       $getbadge = mysql_query($qry) or die(mysql_error());
       
       if($result) {
          while ($row = mysql_fetch_array($getbadge)) {
                            $img = $row['badges'];
                            
        echo "<img src='badges/".$img.".gif' alt='".$img."'>";
    } 
    }else {
                      echo "<p>".$error."</p><br>";
                      }
                      ?>
    

    You were calling $Query instead of $qry. Try the above code.

  6. Should be:

    <?php
       session_start();
       require_once('config.php');
       
       $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
       if(!$link) {
          die('Failed to connect to server: ' . mysql_error());
       }
       
       $db = mysql_select_db(DB_DATABASE);
       if(!$db) {
          die("Unable to select database");
       }
       
       $qry="SELECT * FROM members WHERE username='$_SESSION[user];'";
       $result=mysql_query($qry);
       
       $getbadge = mysql_query($query) or die(mysql_error());
       
       if($result) {
          while ($row = mysql_fetch_array($getbadge)) {
                            $img = $row['badges'];
                            
        echo "<img src='badges/".$img.".gif' alt='".$img."'>";
    } 
    }else {
                      echo "<p>".$error."</p><br>";
                      }
                      ?>
    

    I think.

  7. You have an extra } at the bottom.

     

    Should be:

    <?php
       session_start();
       require_once('config.php');
       
       $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
       if(!$link) {
          die('Failed to connect to server: ' . mysql_error());
       }
       
       $db = mysql_select_db(DB_DATABASE);
       if(!$db) {
          die("Unable to select database");
       }
       
       $qry="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
       $result=mysql_query($qry);
       
       $getbadge = mysql_query($query) or die(mysql_error());
       
       if($result) {
          while ($row = mysql_fetch_array($getbadge)) {
                            $img = $row['badges'];
                            
        echo "<img src='badges/".$img.".gif' alt='".$img."'>";
    
    } else {
                      echo "<p>".$error."</p><br>";
                      }
                      ?>

  8. Hello,

     

    I am trying to find a way of improving the user experience for my website. The site is heavily reliant on AJAX and PHP.

    The problem we've encountered is when we change the javascript on the site it causes problems as people are using the old cached files.

    I want to make a small script that will force the browser to reload each page the user visits, however I don't want this to happen every time the user visits. This is where PHP comes in. I'm thinking of creating a cookie that the script will look for and only include these headers if the user either does not have the cookie, or the cookie was set BEFORE the date the update was pushed to the site.

     

    Any help would be appreciated, as this situation is very confusing for me :( lol

     

    HTML headers:

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Pragma-directive" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Directive" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">

  9. Hello,

     

    Hope you can help me guys.

     

    I am wanting to delete duplicate entries in my database.

     

    At the moment I have something like this:

     

    username | password | email address | status

    test1 | password1 | email@somedomain.com | 0

    test1 | password1 | email@somedomain.com | 0

    test1 | password1 | email@somedomain.com | 1

     

    How can I remove the ones with the duplicate usernames but keep the one that has a status of "1"?

     

    Any help would be appreciated!

     

    Thanks

  10. I don't really see the point in using regex to get rid of specific characters unless there is a reason you need to do so other than protecting against SQL injections. I'd stick with simply adding slashes tbh, doing both can't hurt though.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.