PHP - Help With Referring System
I have 2 referring url.
USERNAME
http://testsite.com/...gister&ref=test
USER ID
http://testsite.com/...gister&ref_id=1
1. Code to remember ref and ref_id
2. Code to allow user to insert own referrer if no ref link detected?
3. Store ref and ref_id into same column Like db referrer = username/user_id or referrer = username / referrer_id = user_id ?
PHP
$ref_id = isset($_GET['ref_id']) ? filter_input(INPUT_GET, 'ref_id', FILTER_SANITIZE_STRING) : ''); $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : '');FORM if(!empty($_GET['ref_id'])){ print ' <tr> <td style="font-weight:bold">Referred by user id #</td> <td><input type="text" name="ref_id" maxlength="255" style="width:200px" value="'.cleanOutput($ref_id).'"></td> </tr>'; }else{ print ' <tr> <td style="font-weight:bold">Referred by</td> <td><input type="text" name="ref" maxlength="255" style="width:200px" value="'.cleanOutput($ref).'"></td> </tr>'; }2. $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : (isset($_POST['ref']) ? filter_input(INPUT_POST, 'ref', FILTER_SANITIZE_STRING) : ''); Similar TutorialsHello everyone, I'm having real trouble with something I'm sure most of you would find easy.... ...here we go..... ...I want a redirect script based on referring URL. More specifically, a small part of the referring URL. example.... ad is placed on Bing, if someone clicks on the ad they get directed to a URL starting "0.r.msn.com/?Id=54r645f3345e" which redirects to my site. I want the referrer checker to looks specifically for the ".r.msn.com/?Id=" and if it's present let the visitor through to the site. The reason I only want it to check for that small part of the URL is because the bits before and after are variables and that is the only "static" part. However, if someone arrives at my site by not clicking on an ad, I want them to go somewhere completely different, let just say for arguments sake, google.com. This is what I have so far... <?php $_GET = $_SERVER['HTTP_REFERER']; if ($_GET == '.r.msn.com') { header('Location: http://www.mysite.com'); } else { header('Location: http://www.google.com'); } ?> I must be missing something, please help. Thanks Hello People, I've been racking my brains, searching google and trawling through the many pages here to see if someone else has already asked the same question but I cant find it. I'm trying to build a simple redirect script based on the referring URL. I want to direct the user to "page a" if any of the arrays are found and "page b" if not. This is what I have so far Code: [Select] <?php $main_string="@$HTTP_REFERER"; $arr = array('aaaa','bbbb','cccc'); foreach($arr as $key => $search_needle) { if(stristr($main_string, $search_needle) != FALSE) { echo "<meta http-equiv=Refresh content=0;url=http://www.google.com/PAGEA.html>"; } } ?> I thought that it might be a case of adding the "else" command but doing that will always redirect to "page b" if all of the arrays aren't true and only 1 needs to be. Anyone got any ideas? Thanks Hey! I am having issues with my site not going to the correct page after submitting a form to login or register or anything in that regards. The script that referrers the user is poster below: Code: [Select] <? /** * Process.php * * The Process class is meant to simplify the task of processing * user submitted forms, redirecting the user to the correct * pages if errors are found, or if form is successful, either * way. Also handles the logout procedure. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 19, 2004 */ include("session.php"); class Process { /* Class constructor */ function Process(){ global $session; /* User submitted login form */ if(isset($_POST['sublogin'])){ $this->procLogin(); } /* User submitted registration form */ else if(isset($_POST['subjoin'])){ $this->procRegister(); } /* User submitted forgot password form */ else if(isset($_POST['subforgot'])){ $this->procForgotPass(); } /* User submitted edit account form */ else if(isset($_POST['subedit'])){ $this->procEditAccount(); } /** * The only other reason user should be directed here * is if he wants to logout, which means user is * logged in currently. */ else if($session->logged_in){ $this->procLogout(); } /** * Should not get here, which means user is viewing this page * by mistake and therefore is redirected. */ else{ header("Location: index.php"); } } /** * procLogin - Processes the user submitted login form, if errors * are found, the user is redirected to correct the information, * if not, the user is effectively logged in to the system. */ function procLogin(){ global $session, $form; /* Login attempt */ $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember'])); /* Login successful */ if($retval){ header("Location: ".$session->referrer); } /* Login failed */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } /** * procLogout - Simply attempts to log the user out of the system * given that there is no logout form to process. */ function procLogout(){ global $session; $retval = $session->logout(); header("Location: logout.php"); } /** * procRegister - Processes the user submitted registration form, * if errors are found, the user is redirected to correct the * information, if not, the user is effectively registered with * the system and an email is (optionally) sent to the newly * created user. */ function procRegister(){ global $session, $form; /* Convert username to all lowercase (by option) */ if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } /* Registration attempt */ $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email']); /* Registration Successful */ if($retval == 0){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } /* Registration attempt failed */ else if($retval == 2){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = false; header("Location: ".$session->referrer); } } /** * procForgotPass - Validates the given username then if * everything is fine, a new password is generated and * emailed to the address the user gave on sign up. */ function procForgotPass(){ global $database, $session, $mailer, $form; /* Username error checking */ $subuser = $_POST['user']; $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered<br>"); } else{ /* Make sure username is in database */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5 || strlen($subuser) > 30 || !eregi("^([0-9a-z])+$", $subuser) || (!$database->usernameTaken($subuser))){ $form->setError($field, "* Username does not exist<br>"); } } /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); } /* Generate new password and email it to user */ else{ /* Generate new password */ $newpass = $session->generateRandStr(8); /* Get email of user */ $usrinf = $database->getUserInfo($subuser); $email = $usrinf['email']; /* Attempt to send the email with new password */ if($mailer->sendNewPass($subuser,$email,$newpass)){ /* Email sent, update database */ $database->updateUserField($subuser, "password", md5($newpass)); $_SESSION['forgotpass'] = true; } /* Email failure, do not change password */ else{ $_SESSION['forgotpass'] = false; } } header("Location: ".$session->referrer); } /** * procEditAccount - Attempts to edit the user's account * information, including the password, which must be verified * before a change is made. */ function procEditAccount(){ global $session, $form; /* Account edit attempt */ $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']); /* Account edit successful */ if($retval){ $_SESSION['useredit'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } }; /* Initialize process */ $process = new Process; ?> All it does is bring you to a unknown page. Thanks! $_SERVER['HTTP_REFERER']; <-- this returns the full path. Can I return the referring page name only? ie) somepage.php Cheers Hello, When I use this function, the time always refers to January 1st 1970 ?! How come? I get the output '4 decades 1 year 11 months' regardless of which date I enter into the function.. ? Code: [Select] function timeAgo($tm,$rcs = 2) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]); if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs); return $x; } When I call for the function I use this: Code: [Select] timeAgo($row['dateposted']) The format in the database for 'dateposted' is: Code: [Select] 2006-08-14 23:29:23 Any ideas what I am doing wrong? Thanks a million hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 Hi Folks, This is my first post here and I was wondering if anyone could help me out at all please. I would basically like to change the logo on the home page based on whether a query string from a referring URL has a specific value. It's an affiliate URL for an online store, so essentially I need to get the referrer, check if the query string adnetwork = as and then replace the logo if it does, if not leave it as it is. Does that make sense? Any help would very much appreciated. I was thinking along the lines of: <?php if ($_GET('adnetwork') == 'as') { changeLogo(); } else { leaveLogo(); } ?> Am I along the right lines folks? Hi all I have been looking though loads of tutorials regarding log in method for websites (not APIs), and cant help find that they are outdated. So I am asking what is the correct way to create a log in system using php? Modern websites use JavaScript for asynchronous web requests so this requirement should also be catered for. APIs and mobile apps use access tokens which is very secure if implemented correctly. Can we use the token principle for websites? As the way I see it that most php log in systems use php sessions and they create a session and save some data in this session when the user successfully authenticates, however the session id is held in a cookie so if the cookie is stolen then they have access to your account. API access tokens are expired and refreshed periodically so is there such a implementation method for web sites too?
Hi this is my login script i do have the html if you need to see it please ask & i was wondering if anyone would be kind enough to tell me how i can get my ban system to work Thanks
<?php require 'connect.php'; if(isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['password']; //Prevent hackers from using SQL Injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); $user_level = $_GET['user_level']; $_SESSION['user_level'] = $user_level; if($count == 1) { $_SESSION['username']; $_SESSION['password']; header("Location: index.php"); } else { echo "Please check the username and password you entered is correct."; } if($_SESSION['user_level'] == 0) { $_SESSION['username']; $_SESSION['password']; header("Location: index.php"); } else if($_SESSION['user_level'] == -1) { die(); header("Location: banned.php"); } else if($_SESSION['user_level'] < -1) { die(); echo "An error has occurred please contact your administrator."; } else if($_SESSION['user_level'] == 1) { $_SESSION['username']; $_SESSION['password']; header("Location: admin.php"); } } ?> Edited by Tom8001, 23 November 2014 - 12:18 PM. i am trying to add a like system to my forum similar to facebook where it shows how many people like a post. this is my code so far: $like_list = ""; $likes = explode("|", $post_info['post_likes']); $amount_likes = count($likes); $ac_likes = ($amount_likes / 2); $slice = array_slice($likes, 0, 4, true); $remain = array_slice($likes, 4, $ac_likes, true); $remain_num = count($remain); if ($ac_likes >= 4) { for($i=0; $i<$ac_likes; $i+=2) { $like_list .= $likes[$i].", "; } $like_list .= " and $remain_num others like this"; } elseif ($amount_likes == 1 ) { $like_list .= "0 people like this"; } elseif ($ac_likes == 1) { $like_list = implode(", ", $likes); $like_list .= " likes this"; } else { $like_list = implode(", ", $likes); $like_list .= " like this"; } $post_info['post_likes'] contains data like: Code: [Select] user1|123456789|user2|123456789 where the number is the timestamp. unfortunatly $like_list prints the username and the timestamp when i would like it to only display the username. This means printing every 2nd element in the array starting from 0. I have seen this done with for loops but i am not using one therefore i am stuck. Any ideas? and is this the best database setup for likes? the post_likes column is added on to the end of the post table. Hi, i have been thinking on ways to make an ordering system for my web site. The code bellow shows how i populate the page. i desplay the pizza's from the data base. i want at the end of each line a box thati allows the user to pick howmany pizzas they want. from they when they click order i want it to send all the information of what they want so they can double check it and when they click the final order button it will send to a diffrent order table. Code: [Select] <? session_start(); if ($_SESSION['userName']) {} else { header('location:../index.php'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Deliver-Pizza Topping</title> <link href="css/pizza-topping.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="header"> <img src="images/logo.jpg" alt="logo" /> <a href="log-off.php" id="logg-off" >log off</a> <ul id="nav"> <li><a href="home.php" target="_self">Home</a></li> <span> | </span> <li><a href="Pizza-Topping.php" target="_self">Pizza Topping</a></li> <span> | </span> <li><a href="order.php" target="_self">Order</a></li> <span> | </span> <li><a href="Account.php" target="_self">Account Details</a></li> <span> | </span> </ul> </div> <div id="Featured"> <img src="images/banner1.jpg" alt="banner" name="banner"" ID="banner"></div><!--end Featured--> <div class="featuredimage" id="main"> <div id="content" class="tiles"> <h1>Pizza-Topping</h1><hr /> <p>Please select the pizza you would like bellow</p> <div id ="staff"><div style="width:970px; height:300px; overflow:auto" <left> <table> <tr> <th>Type</th> <th>Size</th> <th>Topping</th> <th>Cost</th> <th>Information</th> <th>Order</th> </tr> <tr> <form name="input" action="order.php" method="post"> <?php mysql_connect("localhost", "root", "")or die("cannot connect"); mysql_select_db("deliverpizza")or die("cannot select DB"); $sql="SELECT * FROM `pizzatopping` "; $result= mysql_query($sql); while($row =mysql_fetch_assoc($result)) { ?> <td><?php echo $row['type'] ?></td> <td><?php echo $row['size'] ?></td> <td><?php echo $row['topping'] ?></td> <td><?php echo $row['cost'] ?></td> <td><?php echo $row['info'] ?></td> <td> <input type:"text" name:"pizza<?php echo $row['id'] ?>" /></td> </tr></left> <?php } ?> <input type="submit" value="Order" /> </table> </div> </div> </div> </div> <!--end content--> <div id="footer"><span><p>Created By Ryan Williams</p></span></div><!--end footer--> </div><!--end container--> </body> </html> Help please I'm busy with a small storage system for my site, but i encounter some problems with it. I have successfully managed to get all products from the order, and traced on what spots those product are in the warehouse. It looks like this atm http://img37.imageshack.us/img37/7302/tableordereng.jpg this is the code i have atm (sorry i program in dutch, i hope its abit understandable) Code: [Select] <?php $query = "select * from `orderregel` WHERE `ordernr`='".$ordernr."'"; $row = mysql_fetch_array( $query ); echo "<table border=1 width=680 bgcolor=#FFFFFF> <tr> <th width= 100>artikelnummer</th> <th width= 100>productnaam</th> <th width= 40>Plaats</th> <th width= 40>aantal in magazijn</th> <th width= 40>aantal nodig</th> </tr> </table>"; foreach ( self::find_by_sql($query) as $user) { $query2 = "select * from magazijn WHERE artikelnr = ".$user->artikelnr.""; $row = mysql_fetch_array( $query ); foreach ( self::find_by_sql($query2) as $magazijn) { echo "<table class= order_overzicht border= 0 width= 680>"; echo "<tr> <td width= 100>".$magazijn->artikelnr."</td> <td width= 100>".$magazijn->productnaam."</td> <td width= 40>".$magazijn->magazijn_plaats."</td> <td width= 40>".$magazijn->aantal."</td> <td width= 40>".$user->aantal."</td> </tr> </table>"; } } ?> The problem i have now is, that i want it to do the following. for example someone orders 430 packages of Haribo Kers Cola (see imageshack upload). I first want it to empty spot 16 in the wherehouse. Only when spot 16 is empty, i want it to go to the next spot (19) wich contains the same product. the end result would be something like this: http://img690.imageshack.us/img690/6246/tableorderneweng.jpg i hope you guys can help me out on this one, becouse i have no clue how i can resolve this problem thanks in advance (Sorry btw for my bad english ) Good Afternoon everyone. I am having some problems in getting a script I found on a forum to work, I have tried contacting the original author but with no joy. Basically its a php/ajax comment system, however I am getting these errors Code: [Select] Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 93 Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 105 Here is the portion of code that I am working on, I don't understand what $_post['type'] is meant to come from? I guess its basically if the form has been submitted, but if I change the values tp 'submit' I still get the same result, just with the message submit is undefined instead! <?php $date=date("Y-m-d"); $username = $_SESSION['username']; if($_POST['type'] == "addcomment") { $username = mysql_real_escape_string($_POST['username']); $comment = mysql_real_escape_string($_POST['comment']); if($username == "" || $comment == "") { die("<p><font color='red'>Error: Please include a message.</font></p>"); } $q1 = mysql_query("INSERT INTO 'comments' ('c_id', 'm_id', 'username', 'date', 'comment') VALUES ('', '$m_id', '$username', '$date', '$comment')") or die("<p>Mysql Error: <b>".mysql_error()."</b></p>"); echo "<p><font color='green'>Comment added successfully.</font></p>"; } elseif($_POST['type'] == "getcomments") { $q1 = mysql_query("SELECT * FROM 'comments'"); $n1 = mysql_num_rows($q1); if($n1 == 0) { die("<p><font color='red'>No comments were found.</font></p>"); } echo "<table border=1>"; echo "<tr><td><b>User</b></td><td><b>Comment</b></td></tr>"; while($r1 = mysql_fetch_assoc($q1)) { $a = $r1['username']; $m = $r1['comment']; echo "<tr><td>$a</td><td>$m</td></tr>"; } echo "</table>"; } else {?> <div style="font-size: 18px;"> <p>Current Comments: </p> <div id="comments"></div> <hr /> <p>Add a comment:</p> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> <p>Username: <input type="text" name="username" id="username" /></p> <p>Comment: <textarea name="message" cols="50" rows="10" id="message"></textarea></p> <p><input type="submit" name="submit" value="Add Comment" id="submit" /></p> </form> <div id="return"></div> </div> <?php } ?> Many Thanks for any help i am making a private messaging system like hotmails where the message list appears on the left. Then when you click on one of them the box on the right loads the email. The problem is i dont really know how to go about it. Anyone have any pointers? Hello, I have the following code Code: [Select] class Uploads extends Controller { public function __construct() { parent::__construct(); if (empty($_FILES)) { log_message('error', 'Uploads - files empty'); exit('No files uploaded'); } ini_set('memory_limit', '128M'); $this->load->helper('file'); $this->load->helper('helpers'); $this->load->model('uploads_model'); } public function font_handler() { $this->uploads_model->font_handler(); } } class Uploads_model extends Model { public function font_handler() { $config = array( 'max_size' => '8388', 'allowed_types' => 'ttf', 'upload_path' => 'assets/fonts/' ); $this->load->library('upload', $config); if ($this->upload->do_upload('Filedata')) { $file = $this->upload->data(); $jsFile = $file['raw_name'].'.js'; $query = $this->db->where('location', 'menuFont')->get('fonts')->row(); if ($query->customFile != '' && file_exists('assets/fonts/'.$query->customFile)) { unlink('assets/fonts/'.$query->customFile); } $path = getcwd() . '/assets/fonts/cufon/convert.php'; $command = 'php ' . $path . ' -u "U+??" ' . $file['full_path'] . ' 1> ' . getcwd() . '/assets/fonts/' . $jsFile; system($command); } } } Ok so, the ttf file is uploaded correctly and I can run $command from the command promt in putty and it works perfect, but when I try to run the same command from system() the js file just contains (from the controller) "No files uploaded" I have no idea why this is happening? Anyone have any ideas? Also one thing i'm not sure about is if it should be 1> or > when creating the js file?!? Thanks guys! Hey guys, I'm starting to build a website and I was wondering wether I should use a library template engine such as smarty, or use pure php, such as this tutorial - http://www.massassi.com/php/articles/template_engines/ Basically the website will not expose any of the users/designers to the designer portion of the website. I am scratching my head wether I should use smarty or pure php, even Facebook uses smarty, from what I have heard. I need some answers. Thank you all! ok i need directing to a tutorial, an easyish one that can help me do a secure login and registration system. Something that uses sessions and mysql. something with sql injection and other security. i need it very secure. hope you can help. is there any available for me to enhanced on /etc? How would I go about starting 1 i want 1 with 32 numbers and i need to have to run a query every 1hour how would i go about this? Hello, Basically i am following this tutorial -: http://tutorialzine.com/2010/06/simple-ajax-commenting-system/ for a website I am creating. But in that tutorial when you write a comment you add a name, I was wondering is it possible instead for my website to use the users username as I have a login system that I created from folowing a tutorial on the same site. I am new to PHP and web creation so please keep the comments simple. |