PHP - Php Tracking / Redirect Code Not Working
Hey guys, I am not a coder at all and would love a little bit of help with my code not working.
Basically, I have a redirect script that sends my visitors to a software download. I want to be able to track a snippet from the incoming refer and send it along with the download. I hope I am explaining this correctly. Here is my code: <?php $tid = $_GET["tid"]; header( 'Location: http://www.liutilities.com/affcb/?id=RBgendtd&aff=14231&xat=WU-<?php echo $tid; ?>' ); ?> The page that sends them to this script automatically adds ?tid={keyword here}. What the above script is supposed to do is grab tid and then put it after the &xat=WU- but instead, its only putting the actual code itself (&xat=WU-<?php echo $tid; ?>). Can anyone offer a suggestion? Thanks so much! Similar TutorialsCan you see any problems with the code below? It doesn't work. What I am trying to do is quite straightforward. The links on my site look like this: go.php?id=1&url=usa go.php?id=1&url=uk go.php?id=2&url=usa go.php?id=2&url=uk When a visitor clicks on one of these links, I want to grab the values of the id and url parameters, count the click, and redirect the visitor. Here's the error that I get when I try the code: Quote Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sites\go.php on line 18 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sites\go.php:18) in C:\xampp\htdocs\sites\go.php on line 19 <?php $conn = mysql_connect('localhost','username', 'password') or trigger_error("SQL", E_USER_ERROR); mysql_select_db('database', $conn) or trigger_error("SQL", E_USER_ERROR); $id = intval($_GET['id']); $url = intval($_GET['url']); mysql_query("UPDATE urls SET click_counter = click_counter+1 WHERE id=$id"); if ($url=="usa") $href = "SELECT usa FROM urls WHERE id=$id"; elseif ($url=="uk") $href = "SELECT uk FROM urls WHERE id=$id"; elseif ($url=="aus") $href = "SELECT aus FROM urls WHERE id=$id"; elseif ($url=="can") $href = "SELECT can FROM urls WHERE id=$id"; else $href = "SELECT int FROM urls WHERE id=$id"; $qry = mysql_query($href); list($href)=mysql_fetch_row($qry); header("Location:$href"); mysql_close($conn); ?> Hey guys im a little stumped. My pages has the following links. <a href="?page=yes">Yes</a> to Change content i use <?php if (isset($_GET['page'])) { include ("include/".$_GET['page'].".php"); } else { echo 'Welcome to Liquids Scripts PHP Code repository. Just select the categorie from the top and get all the info required '; } ?> Will this be tracked by google analytics? Any help would be awsome. So while editing my .HTACCESS file I added the proper lines to redirect users that encounter errors like 404 and 500. It works like a charm if I tell it to display a specific message. However if I tell the file to redirect users to a custom error page it fails.
When testing out my 404 redirect I get this:
Not Found
The requested URL /143/test.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
As you can see it is stating that my ErrorDocument is not found BUT if I type my ErrorDocument URL in I can go to it myself.
My .HTACCESS file looks like this:
ErrorDocument 400 /error.php ErrorDocument 401 /error.php ErrorDocument 403 /error.php ErrorDocument 404 /error.php ErrorDocument 500 /error.php ErrorDocument 502 /error.php ErrorDocument 504 /error.php # supress php errors php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off # enable PHP error logging php_flag log_errors on php_value error_log PHP_errors.log NOTE: I am using localhost (WAMP). Thanks. I have an html login page. Once a user is verified through the PHP page they get redirected to another page. For some reason once I have validated that the user exists I get the message that is was successful but the page will not redirect. This is my script I use on my HTML page to pass the parameters: Code: [Select] $(document).ready(function() { $('#submit').click(function() { var username = $('input[name=username]'); var password = $('input[name=password]'); var data = 'username=' + username.val() + '&password=' + password.val(); .ajax({ url: "login.php", type: "GET", data: data, cache: false, success: function() { alert("SUCCESS"); } }); return false; }); }); And this is my PHP page: Code: [Select] <?php $username = ($_GET['username']) ? $_GET['username'] : $_POST['username']; $password = ($_GET['password']) ? $_GET['password'] : $_POST['password']; if ($_POST) $post=1; $userFound = false; $memberId = ""; // Create connection string, Note, params are as follow // mysql_connect(databaseLocation, username, password) $con = mysql_connect("localhost","root",""); if (!$con) { die("Could not connect: " . mysql_error()); } mysql_select_db("memberdb", $con); // SQL Query $result = mysql_query("SELECT memberId, firstName, lastName, username, password FROM member"); while($row = mysql_fetch_array($result)) { if ($username == $row["username"] && $password == $row["password"]) { echo "<h1>Welcome " . $row["firstName"] ." ". $row["lastName"] . "! </h1></br>"; $userFound = true; $memberId = $row["memberId"]; } } // If User is found, continue on to next page, if not redirect to index.html if ($userFound) { echo "<h2>Login Successful</h2>"; echo "<h3>Page will redirect</h3>"; header( "url=menu.html?memberId=" . $memberId); } else { echo "<h2>LOGIN FAILED</h2>"; echo "<h3>Page will redirect</h3>"; header( "refresh: 1; url=index.html#loginPage"); } ?> It does the echo successfully but hangs on the part where is says : Quote header( "url=menu.html?memberId=" . $memberId); How can I get it to redirect? Thanks I'm trying to redirect visitors that contain broadly matched URLs. For example, redirect the visitor if their url contains: "/welcome" or "order.php" or "login.mysite/" At the same time I also want to redirect the user if they a particular User Agent. Here's what I have, but doesn't seem to be entirely working... Code: [Select] <?php //detect referrer $ref = $_SERVER['HTTP_REFERER']; $find = "order.php"; $find = "login.mysite/"; //setting the variables $linux = stripos($_SERVER['HTTP_USER_AGENT'],"Linux"); $aol = stripos($_SERVER['HTTP_USER_AGENT'],"AOL"); //detecting user agent device, os, browser, etc. if ($linux == true || $aol == true) $redirect = 1; //detect referrer elseif (preg_match($ref, $find)) $redirect = 1; //set redirects if ($redirect) { $url = "http://www.google.com"; } else { $url = "http://www.yahoo.com"; } header("Location: $url"); ?> Any help you can offer is appreciated. Thanks! Hi I have a from, now after the users send the form, i want to redirect to a thank you page. my code does not redirect and gives me this error Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\feelmalaysia.com\httpdocs\sendmailsqlar.php:1) in D:\inetpub\vhosts\feelmalaysia.com\httpdocs\sendmailsqlar.php on line 25 I have the redirect page saved in the same directory as the php file. my Php Code : <?php $headers .= 'Content-type: text/plain; charset=UTF-8; format=flowed' . "\r\n"; $headers .= 'Content-Transfer-Encoding: 8bit'."\r\n"; $to = "xxx@xxx.com"; $visitor = $_REQUEST['Name'] ; $visitormail = $_REQUEST['Email'] ; $nationality = $_REQUEST['Nationality'] ; $stulevel = $_REQUEST['Level'] ; $stfield = $_REQUEST['Field'] ; $message = $_REQUEST['Message'] ; $header = "From: $visitormail\n" . "Reply-To: $visitormail\n"; $subject = "Arab Enquiry"; $message = "From: $visitor \n\n Email: $visitormail \n\n Nationality: $nationality \n\n Level: $stulevel \n\n Field: $stfield \n\n Message: $message"; mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header, $headers); //Sending auto respond Email to visitor $reply_header = "From: xxx@xxx.com\n" . "Reply-To: xxx@xxx.com\n"; $reply_subject = "- تم استلام طلبكم"; $reply_to = "$visitormail"; $reply_message = "$visitor \n\n شكرا لزيارتكم موقعنا . \n نود ابلاغكم بأنه تم استلام طلبكم وسوف يتم الرد عليكم قريبا.\n هذه الرسالة مرسلة من نظام الموقع.\n شكرا\n "; mail($reply_to, '=?UTF-8?B?'.base64_encode($reply_subject).'?=', $reply_message, $reply_header, $headers); header('Location: thankyouar.html'); ?> Please help . Thank you this code works if i use the header() in the else section it doesnt but it will echo the commented part Code: [Select] <? /** * User has already logged in, so display relevant links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ echo "<li>Logged In "; echo "<b>$session->username</b></li>"; if($session->isAdmin()){ echo "<li><a href=\"LoginSystem/admin/admin.php\">Admin Center</a></li>"; } echo "<li><a href=\"../LoginSystem/process.php\">Logout</a</li>"; } else{header("Location: ../LoginSystem/main.php"); //echo "<li><a href=\"../LoginSystem/process.php\">Login</a></li>"; } ?> I've got an issue with a header redirect that is confusing me. I haven't been able to find any similar problems that have help me solve it and the PHP man page on headers isn't helping me either. <?php if(isset($_POST['add_cat'])) { $cat_obj->add_category($_POST['cat_title']); header("Location: admin/category.php"); } ?> This code is in a file called add_category.php which is in the same directory as the category.php file I want it to redirect to. without the 'header..' line it works perfectly; but with the 'header..' line I get the following warning - QuoteWarning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/**/**/admin/add_category.php:2) in /opt/lampp/htdocs/**/**/admin/add_category.php on line 30
but there's no other place sending headers (that I can see) and to my inexperienced eye it seems like it's cyclical logic as it's saying the same line I want to send the redirect is the one that already sent it. Would someone mind giving me an ELI5 breakdown of why this isn't working properly and maybe a route to solving the problem, please? TIA quick questions.. i have this code echo '<p>message of error</p>'; echo"<script type='text/javascript'> window.location='index.php'</script>"; and i want to know how could i delay the redirect to index.php for about 5 seconds or so? i've found how to do it using header(); but I've used that before and have gotten alot of errors, which is why i use on javascript to do it for me. i'm trying to use this code to detect if the browser of the user is IE (any version) and id true (if it is IE), then it's redirected to an error page; otherwise, it's ok and sent ot the index. I get the following error... Warning: Cannot modify header information - headers already sent by (output started at /index.php:1) in /xie.php on line 13 any ideas.. ??? <?php function ae_detect_ie() { if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) return true; else return false; } if (ae_detect_ie()) { header("Location: error.php"); } else { header("Location: index.php"); } ?> Hi I've been working on a site for 6 months and have used the header command to redirect loads and loads of times. But i just noticed some crazy behaviour today. Heres a test page: <?php include("includes/db_connect.php"); header('location:stores.php'); $sql = "insert into test (id) values (77)"; $result = mysql_query($sql); ?> when i hit this page, i get redirected to stores.php, but the sql gets executed! Is this supposed to be the behaviour? Have i completely missed the point of header(location:)?? Im baffled as i've used this before, but only now noticed this crazy behaviour! Hi, can anyone help me?
I am trying to create a form which asks the user to input their postcode then submit. the purpose is so if the service my site offers is not available in the location that the end user lives, then I want to display a message saying 'Sorry, not available', but if they are in area then it redirects to another page.
My form code is:
<form method="post" action="forwarder.php"> <p> Enter Post Code He <input type = "text" name = "zip" id = "zip" size = "10" maxlength = "5" "> <input type='submit'> </form>My PHP is: <?php $zip = isset ($_POST['zip']) { if ($zip=='NG15') { header('Location: https://www.bing.com'); } else { header('Location: http://www.google.co.uk') } ?>I am a bit of a newbie at this, and I know my PHP won't give me my desired result, but I was using this to try and test the concept. Help would be really appreciated, and if you can show me how to do it for multiple postcodes even better Code: [Select] <form action="checkbox-form.php" method="post"> <input type="checkbox" name="c1" value="1" /> Pending <input type="checkbox" name="c1" value="2" /> Approved <input type="checkbox" name="c1" value="3" /> Rejected <input type="button" name="formSubmit" value="Fetch Results"/> </form> <?php $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect:' . mysql_error()); } mysql_select_db("Products", $con); $result = mysql_query("SELECT * FROM btp_reviews" ); echo "<table border='1' cellspacing='0' cellpadding='0'>"; echo '<tr> <td>Id</td> <td>Review</td> <td>Name</td> <td>Update</td> <td>Status</td> </tr>'; while($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<td>' . $row['id'] . '</td>'; echo "<td>" . strip_tags($row['review']) . "</td>"; echo "<td>" . $row['r_name'] . "</td>"; echo "<td>" ."<form action='radio.php' method='post' ><a href=http://localhost/editt.php?id=".$row['id'].">Edit</a>.</td> <td>" ."<input type='radio' name='r1' value='2' />Approve<br/><input type=hidden name=id value='".$row['id']."' /> <input type='radio' name='r1' value='3' /> Reject<br/> <input type=submit value=Submit /></form>"."</td>"; } echo "</table>"; mysql_close($con); ?> http://paste.ee/p/OhiWv
The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working.
<script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script> i dont understand what is wrong plz help me.
here is code
$name = "img/".rand(1,9999999).".png"; $myFile = $name; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $html; fwrite($fh, $stringData); fclose($fh); $file=$name; $fst=file_get_contents($file); $im=imagecreatefromstring($fst); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_NEGATE); //Convert to Grey Scale for($i=0;$i<123;$i++){ for($j=0;$j<50;$j++){ $px=imagecolorat($im,$i,$j); if($px<0x303030){ imagesetpixel($im,$i,$j,0); }else{ imagesetpixel($im,$i,$j,0xffffff); } } } $database = unserialize(@file_get_contents("db.txt")); if($database === false) $database = array(); // modify the database if needed if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_POST['submit'] == 'Add') $database[$_POST['ident']] = substr($_POST['letter'], 0, 1); if($_POST['submit'] == 'Del') unset($database[$_POST['ident']]); if($fh = @fopen('db111.txt', 'w+')){ fwrite($fh, serialize($database)); fclose($fh); } }else{ $newimage = true; } $width = 130; $height = 40; $captcha_gridstart =1; $captcha_gridspace =2; $letters = findletters($im, $width, $height, $captcha_gridstart, $captcha_gridspace); $count = count($letters); $cellw = ($count > 0) ? intval(100 / $count) : 0; //dispeckle the image and GET co-ordinates of the characters of captcha image and return them. function findletters($image, $width, $height, $gridstart, $gridspace){ $offsets = array(); $o = 0; $atstartx = true; for($x = 0; $x < $width; $x++){ $blankx = true; for($y = 0; $y < $height; $y++){ if(imagecolorat($image, $x, $y) == 0){ $blankx = false; break; } } if(!$blankx && $atstartx){ $offsets[$o]['startx'] = $x; $atstartx = !$atstartx; }else if($blankx && !$atstartx){ $offsets[$o]['endx'] = $x; $atstartx = !$atstartx; $o++; } } $count = $o; for($o = 0; $o < $count; $o++){ for($y = 0; $y < $height; $y++){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['starty'] = $y; break; } } for($y = $height-1; $y > $offsets[$o]['starty']; $y--){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['endy'] = $y; break; } } } for($o = 0; $o < $count; $o++){ $offsets[$o]['ident'] = ""; for($x = $offsets[$o]['startx'] + $gridstart; $x < $offsets[$o]['endx']; $x += $gridspace){ for($y = $offsets[$o]['starty'] + $gridstart; $y < $offsets[$o]['endy']; $y += $gridspace){ $offsets[$o]['ident'] .= ((imagecolorat($image, $x, $y) == 0) ? "0" : "1"); #echo $offsets[$o]['ident'].'<br>'; } } } return $offsets; } $a=""; foreach($letters as $letter){ $asciiletter = $database[$letter['ident']]; if(!empty($asciiletter)) { $a.=$asciiletter; } } Can anyone provide a snip of code that I could insert into the "coupon code" field on a formmail form which has the following effect: on submit form, user goes to the normal payment page (this is already implemented) if coupon code field is filled out with correct code, user is taken to alternate payment page on form submit. Either this or another approach which has the same result is OK. I am a novice coder working in a wysiwyg - I don't REALLY know php at all - I just need a snip I can insert and a clear instruction. Thanks so much for any help. Hi, here's my problem let's say I gave an end user a url such as e.g http://www.test.com/index.php?user=asdf1234 and I did the same thing to different end users with unique $_GET['user'] value each . my question is, how to track the URLs ?, i mean, how will i know if those urls were clicked and how to count the clicks made ? some possible scenarios could be - the url is pasted and send via email - the url is embeded as a link in some portals Hey guys! I had a quick question that is more about php coding theory than actual code. Anyway, I was curious as to how one would track ad clicks and impressions (especially the impressions). There are tons of sites that do this but I don't really understand how. Thanks hi i need a script to track how many times a link has been clicked, if this is possible can i have some guidance cheers matt |