Jump to content

jurass1c

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Posts posted by jurass1c

  1. Thanks man, i am still having a little trouble.  I did use this same method but what it does is echo all my results with an "..." after the substr even if the characters are under 7. so for example:

     

    Say i have a 3 names in my database (Orange, Apple, Strawberry) under the field "Fruit", say  i want to limit the characters to "5" i use substr like above:

     

    ". substr($row['fruit'], 0, 5).'...' ."

     

    It will work perfect for both "Orange and Strawberry" but when it comes to "Apple" (which is 5 characters) it will echo the "..." after it when it does not need to. Any idea's ?

     

    Thanks.

     

  2. I was wondering how to get "..." after the text i have cut using Substr. Here in an example of what i mean:

     

    Say i wanted cut down something like a Movie name.

     

    "Pulp Fiction" i use Substr to cut down the characters to only 7 so it would echo only "Pulp Fic" how would i go about adding "..." (3 dots) after Substr cuts off the name ?

     

    so it would look like this "Pulp Fic..." - (notice the 3 dots after the name)

     

    Its prob simple but i am yet to find a solution. any ideas ?

  3. My method is straight forward and if i was to go ahead and code it up the complications i would have is the whole page refreshing when "REPORT" is hit because the hyperlink will direct it to "report.php" i want to know the method of being able to do this live with a simple "alert" and "confirm" either with ajax or Js.

     

    Next complication i would have is the process of inserting the dead links values into the database. I can display the values of a video using ($_GET['id']) BUT inserting those values into a separate table ? how would i go about that ?

     

  4. Heja

     

    i was wondering if their is any example of a report link script. My situation is this,  I have a database of hyperlinked videos. Lets say one of the video links goes down (dead or removed) i want the user to be able to report the dead video, and the reported video displayed in my admin area.

     

    i was thinking this could be done by ofcourse getting the ID of the dead video link (<a href='report.php?id=" .$row['id']. "' >REPORT</a>) notice it will be directed to "report.php. In report.php get the values of the video by using something like this ?:

     

    if($_GET['id'] != ""){
    
    $report = $_GET['id'];
    
    }

    from this somehow get the values of the video (name, provider, length etc) and INSERT those values into a database table. From here in the admin section which i can only access i could use mysql SELECT to show the recent reported link.

     

    So i am presuming that is 1 method of doing it, i was hoping someone could lead me in the right direction or provide me with some sample code of how to exactly do this. I mean grabbing the video's values by using if($_GET['id'] != "") and then inserting them, can it be done with a simple javascript alert popup ? saving the whole page having to refresh using my presumed method, is their a easier alternative ?

     

    thanks.

  5. Hey.

     

    Thanks for helping me on this one. My rapidshare link checker works fine and i also managed to get it working with hotfile but recently went to use it, it failed to work. any help would be greatly appreciated.

     

    here's my script:

     

     
    <?
    
    $result = mysql_query("SELECT * FROM database WHERE provider='HotFile.com'") or die('cant select');
    
    $cnt = 1;
    while($row = mysql_fetch_array($result))  {
    
    $url = $row['link'];
    
    $rsurls = @file_get_contents($url);
    if (preg_match("/REGULAR DOWNLOAD/", $rsurls)){
    
    echo '<a href="'.$url.'"><font color="green">'.$url.'</font></a> - Valid<br />';
    
    }else{
    
    echo '<a href="'.$url.'"><font color="red">'.$url.'</font></a> - Dead - <a href="delete.php?id=' .$row['id']. '">Delete</a><br />';
    }//end preg match
    
    ++$cnt;
    
    }//end while loop
    
    echo "<br /><font size='2'>{$cnt} Links Checked</font>";
    
    ?>
    

  6. No luck there here is what i use in the usr_email variable

     

    {
    $user_email = mysql_real_escape_string($_POST['usr_email']);
    $md5pass = md5(mysql_real_escape_string($_POST['pwd']));
    
    
    if (strpos($user_email,'@') === false) {
        $user_cond = "user_name='$user_email'";
    } else {
          $user_cond = "user_email='$user_email'";
        
    }

     

    so the user can either log in by email or username. This is the session code

     

         // this sets session and logs user in  
       session_start(); 
       
       // this sets variables in the session 
    	$_SESSION['user_id']= $id;  
    	$_SESSION['user_name']= $_POST['user_name'];
    
    
    
    	//set a cookie witout expiry until 60 days
       if(isset($_POST['remember'])){
    			  setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
    			  setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
    			   }
    
    
    	header("Location: account.php");
    	}
    	else
    	{
    	$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
    	header("Location:login.php?msg=$msg");
    	}

     

    I use this code to protect pages and start sessions.

     

    ******************** PAGE PROTECT CODE  ***************/
    
    function page_protect() {
    session_start();
    
    //check for cookies
    
    if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_name'])){
          $_SESSION['user_id'] = $_COOKIE['user_id'];
          $_SESSION['user_name'] = $_COOKIE['user_name'];
       }
    
    if (!isset($_SESSION['user_id']))
    {
    header("Location: login.php");
    }
    
    /******************************************************/
    
    }

     

    So i use this variable $_SESSION[user_name] in the file that insert's content and i want to capture and post the username  in this below file

     

    <?php
    include 'db.php';
    page_protect();
    
    
    $user_ip = $_SERVER['REMOTE_ADDR'];
    
    $sql="INSERT INTO example (cover, album, artist, date, users_ip, user_name,  album_year)
    
    VALUES
    ('$_POST[cover]','$_POST[album]','$_POST[artist]', now(), '$user_ip',  '$_SESSION[user_name]',  '$_POST[album_year]')";
    
    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
      
    header("Location: share.php");  
      exit();
    
    ?> 

     

    where am i going wrong ?

  7. sorry guys lol.

     

     <fieldset id="signin_menu">
        <form method="post" id="signin" action="indxlog.php" name="login">
          <label for="username">Username or email</label>
          <input name="usr_email" id="name" class="required"  value="" title="username" tabindex="4" type="text">
          </p>
          <p>
            <label for="password">Password</label>
            <input id="password "name="pwd" class="required password" value="" title="password" tabindex="5" type="password">
          </p>
          <p class="remember">
            <input id="signin_submit" value="Sign in" tabindex="6" type="submit">
            <input id="remember" name="remember" value="1" tabindex="7" type="checkbox">
            <label for="remember">Remember me</label>
          </p>
          <p class="forgot"> <a href="#" id="resend_password_link">Forgot your password</a> </p>
          <p class="forgot-username"> <A id=forgot_username_link 
    title="Activation code will be required" 
    href="#">Activate Account</A> </p>
        </form>
      </fieldset>

  8.       <form name="form" id="form" class="form" action="insert.php" method="post">

            <tr>

              <td width="89" height="27" align="left" valign="middle"> Album Cover: </td>

              <td width="308" align="left" valign="middle">

                <input name="cover" type="text" size="40" />

                *</td>

              <td width="253" rowspan="9" align="center" valign="middle"> </td>

                </tr>

            <tr>

              <td height="28" align="left" valign="middle"> Album:</td>

              <td align="left" valign="middle"><input name="album" type="text" size="40" />

                *</td>

                </tr>

            <tr>

              <td height="29" align="left" valign="middle"> Artist: </td>

              <td align="left" valign="middle"><input name="artist" type="text"  size="40" />

                *</td>

                </tr>

            <tr>

              <td height="29" align="left" valign="middle"> Album Year: </td>

              <td align="left" valign="middle"><select name="album_year">

                <option value="">Unkown</option>

                <option value="2010">2010</option> 

                <option value="2009">2009</option> 

                <option value="2008">2008</option> 

                <option value="2007">2007</option> 

                <option value="2006">2006</option> 

                <option value="2005">2005</option> 

                <option value="2004">2004</option> 

                <option value="2003">2003</option> 

                <option value="2002">2002</option> 

                <option value="2001">2001</option> 

                <option value="2000">2000</option> 

                <option value="1999">1999</option> 

                <option value="1998">1998</option> 

                <option value="1997">1997</option> 

                <option value="1996">1996</option> 

                <option value="1995">1995</option> 

                <option value="1994">1994</option> 

                <option value="1993">1993</option> 

                <option value="1992">1992</option> 

                <option value="1991">1991</option> 

                <option value="1990">1990</option> 

          </select> *</td>

                </tr>

            <tr>

              <div align="right"><input type="submit" class="btn" value="Share" /></div>

                <br />

                <br />

                <br /></td>

                </tr>

          </form>

  9. here is the login script, the included file and the insert script where i want to capture the the user name of the user and i still cannot see why it's not working.

     

    The forms action is set to method post and the action submits to check.php.

     

    this is check.php.

     

    <?php 
    /*************** START *********************/
    
    include 'db.php';
    
    $user_email = mysql_real_escape_string($_POST['usr_email']);
    $md5pass = md5(mysql_real_escape_string($_POST['pwd']));
    
    
    if (strpos($user_email,'@') === false) {
        $user_cond = "user_name='$user_email'";
    } else {
          $user_cond = "user_email='$user_email'";
        
    }
    
    
    $sql = "SELECT `id`,`user_name`,`approved` FROM users WHERE 
               $user_cond
    		AND `pwd` = '$md5pass' AND `banned` = '0'
    		"; 
    
    
    $result = mysql_query($sql) or die (mysql_error()); 
    $num = mysql_num_rows($result);
    
    // Match row found with more than 1 results  - the user is authenticated. 
    
        if ( $num > 0 ) { 
    
    list($id,$approved) = mysql_fetch_row($result);
    
    if(!$approved) {
    $msg = "Account not activated. Please check your email for activation code";
    header("Location:login.php?msg=$msg");
     exit();
     }
    
         // this sets session and logs user in  
       session_start(); 
       
       // this sets variables in the session 
    	$_SESSION['user_id']= $id;  
    	$_SESSION['user_name']= $_POST['user_name'];
    
    
    	//set a cookie witout expiry until 60 days
       if(isset($_POST['remember'])){
    			  setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
    			  setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
    			   }
    
    
    	header("Location: account.php");
    	}
    	else
    	{
    	$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
    	header("Location:login.php?msg=$msg");
    	}
    
    
    ?>

     

    this is the included file:

     

    <?php
    /******************** MAIN SETTINGS **********************/
    
    $dbname = 'one';
    $link = mysql_connect("localhost","two","three") or die("Couldn't make connection.");
    $db = mysql_select_db($dbname, $link) or die("Couldn't select database");
    
    /******************** ADMIN *****************************/
    
    $admin_user = 'exampleadmin';
    $admin_pass = 'examplepassword;
    
    /******************** PAGE PROTECT CODE  ***************/
    
    function page_protect() {
    session_start();
    
    //check for cookies
    
    if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_name'])){
          $_SESSION['user_id'] = $_COOKIE['user_id'];
          $_SESSION['user_name'] = $_COOKIE['user_name'];
       }
    
    
    if (!isset($_SESSION['user_id']))
    {
    header("Location: login.php");
    }
    
    /******************************************************/
    
    }
    
    function filter($data) {
    $data = trim(htmlentities(strip_tags($data)));
    
    if (get_magic_quotes_gpc())
    	$data = stripslashes($data);
    
    $data = mysql_real_escape_string($data);
    
    return $data;
    }
    
    function EncodeURL($url)
    {
    $new = strtolower(ereg_replace(' ','_',$url));
    return($new);
    }
    
    function DecodeURL($url)
    {
    $new = ucwords(ereg_replace('_',' ',$url));
    return($new);
    }
    
    function ChopStr($str, $len) 
    {
        if (strlen($str) < $len)
            return $str;
    
        $str = substr($str,0,$len);
        if ($spc_pos = strrpos($str," "))
                $str = substr($str,0,$spc_pos);
    
        return $str . "...";
    }	
    
    function isEmail($email){
      return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE;
    }
    
    function isUserID($username)
    {
    if (preg_match('/^[a-z\d_]{5,20}$/i', $username)) {
    	return true;
    } else {
    	return false;
    }
    }	
    
    function isURL($url) 
    {
    if (preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)) {
    	return true;
    } else {
    	return false;
    }
    } 
    
    function checkPwd($x,$y) 
    {
    if(empty($x) || empty($y) ) { return false; }
    if (strlen($x) < 4 || strlen($y) < 4) { return false; }
    
    if (strcmp($x,$y) != 0) {
    return false;
    } 
    return true;
    }
    
    ?>
    

     

    those 2 files log my user in. Now here is where i want to capture the username.

     

    <?php
    include 'db.php';
    page_protect();
    
    
    $user_ip = $_SERVER['REMOTE_ADDR'];
    
    $sql="INSERT INTO example (cover, album, artist, date, users_ip, user_name,  album_year)
    
    VALUES
    ('$_POST[cover]','$_POST[album]','$_POST[artist]', now(), '$user_ip',  '$_SESSION[user_name]',  '$_POST[album_year]')";
    
    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
      
    header("Location: share.php");  
      exit();
    
    ?> 
    

     

    i just cannot capture the user_name in the database.

  10. i tried that variable and nothing. The only code relation to $username is:

     

    function isUserID($username)
    {
    if (preg_match('/^[a-z\d_]{5,20}$/i', $username)) {
    	return true;
    } else {
    	return false;
    }
    }	
    

     

    The above code is just a function. In my database in the "users" table the column is named "user_name" and in my other table "content" it has the same name, could this be the reason ?.... where do we go from here ?

  11. this is the process etc in full detail.

     

    1a. Login - This is the current session variable i am using to log a user in.

     

    
    // this sets session and logs user in  
       session_start(); 
       
       // this sets variables in the session 
    	$_SESSION['user_id']= $id;  
    	$_SESSION['user_name'] = $_POST['user_name'];
    
    	//set a cookie (expiry 60 days) if user selectecs remember me
    
       if(isset($_POST['remember'])){
    			  setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
    			  setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
    			   }
    
    
    	header("Location: account.php");
    	}
    

     

    1b. Included in this file is my database connect. In my database connect i use the following code to protect pages and also to start the session:

     

    function page_protect() {
    session_start();
    
    //check for cookies
    
    if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_name'])){
          $_SESSION['user_id'] = $_COOKIE['user_id'];
          $_SESSION['user_name'] = $_COOKIE['user_name'];
       }
    
    
    if (!isset($_SESSION['user_id']))
    {
    header("Location: index.php");
    }
    

     

    2a. Once the user is logged in they can post content. I use this code to post the content and insert the data into my database, this code is is my form action (insert.php):

     

    <?php
    
    include 'dbc.php';
    page_protect();
    
    mysql_select_db("whit_albums", $con);
    
    $user_ip = $_SERVER['REMOTE_ADDR'];
    
    $sql="INSERT INTO albums (cover, album, artist, provider, link, file_type, file_size, date, users_ip, user_name)
    VALUES
    ('$_POST[cover]','$_POST[album]','$_POST[artist]','$_POST[provider]','$_POST[link]','$_POST[file_type]','$_POST[file_size]', now(),'$user_ip', '$_SESSION[user_name]' )";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
      
    header("Location: thankyou.php");  
      exit();
    
    mysql_close($con)
    ?> 
    

     

    2b. This is where i am having my issue, as i mentioned in my first post i cannot capture the users name making the post and insert it into the database.  As you can see in 1a I tried $_SESSION['user_name'] = $_POST['user_name']; and then i used(2a) $_SESSION[user_name] to capture and it failed. Any idea's ?

  12. ok this is what i did. When user logs in successfully:

     

    session_start(); 
    
    	$_SESSION['user_id']= $id;  
    	$_SESSION['user_name'] = $user_name;

     

    But still i cannot capture the members user_name. Is it possible because i am trying to capture and insert into another table within the database ? i just cant seem to work this one out.

  13. Ok, i sort of understand what u are saying. by storing the session variable u mean simple:

     

    $username = $_SESSION['user_name'];

     

    then in my sql INSERT use '$username'  ? Could you maybe explain this a little better, im still not fluent, could i maybe get possible example.

×
×
  • 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.