Please someone help. I want to put the $url which is created into $shorturl = to generate a custom url ($url actually outputs a http://something.com actual link) but don't know how. or can you help me put the $url in header("Location:"

.$url

']); to redirect users to the generated $url from mysql. Please help

<?php include("function.php"); 

     if(!isset($_GET["u"])){ //this is user id


         } else if(!isset($_GET['o'])){  //this is offer id


         } else {
             $offer = mysql_real_escape_string($_GET["o"]);
             $checkOffer = mysql_query("SELECT * FROM offers WHERE offerId = '$offer'");
             if(mysql_num_rows($checkOffer) == 0){


             } else {
             $user = $_GET["u"];

             $ip = $_SESSION['ip'] ;
            $checkIp = mysql_query("SELECT * FROM clicks WHERE clickIp = '$ip' AND offerId = '$offer' AND status = 'complete'");
            if(mysql_num_rows($checkIp) != 0){
            $outPut = "<h2>Already Complete!</h2><p> You clicked an offer which is now PAUSED for your unique IP.";
            } else {

                $clickId = rand_string();
            $check_clickId = mysql_query("SELECT * FROM clicks WHERE clickId = '$clickId'");
            while(mysql_num_rows($check_clickId) != 0){
                $clickId = rand_string();
                $check_clickId = mysql_query("SELECT * FROM clicks WHERE clickId = '$clickId'");
            }

            $checkClick = mysql_query("SELECT * FROM clicks WHERE clickIp = '$ip' AND offerId = '$offer' AND status = 'clicked'");

            if(mysql_num_rows($checkClick) == 0){
            mysql_query("INSERT INTO `clicks` (`clickId`, `clickIp`, `offerId`, `userId`, `status`,`date`,`time`) VALUES ('$clickId', '$ip', '$offer', '$user', 'clicked',NOW(),NOW())");   
            } else {                        
            while ($row = mysql_fetch_assoc($checkClick)) {
                $clickId =  $row["clickId"];
            }   
            }
                $urlCheck = mysql_query("SELECT * FROM offers WHERE offerId = '$offer'");
                while ($row = mysql_fetch_assoc($urlCheck)) {
                $url =  $row["url"];
            }   
            $url = str_replace("XXX", $clickId, $url);
            $url = str_replace("YYY", $user, $url);

    }

             $clicks = mysql_result(mysql_query("SELECT clicks FROM offers WHERE offerId = '$offer'"), 0);

            // Inputs
$shorturl = "http://example.com";
$username = "xxxxx";
$password = "xxxxx";
$siteurl = "http://trck.clix4offer.info";

// Phases url
$yourlsinput = "".$siteurl."/yourls-api.php?action=shorturl&url=".$shorturl."&username=".$username."&password=".$password."" ;

// Open phased url
$fh = fopen($yourlsinput, 'r') or die("can't open file");
//$yourlsoutput = fread($fh,filesize($yourlsinput));
$yourlsoutput = fread($fh,1024);
fclose($fh);

// Converts xml to php array
$xml = simplexml_load_string($yourlsoutput);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

// Output status
echo "
<html><head><title>Yourls</title></head>" ;
echo "<body><p><b>Status:</b> ".$array['status']."<br>";
echo "<b>Message:</b> ".$array['message']."<br>";
echo "<b>Short url:</b> <a href='".$array['shorturl']."'>".$array['shorturl']."</a></p>";

            }

             }



                        //Establishing Connection with Server
                        $connection = mysql_connect("localhost", "user", "pass");

                        //Selecting Database
                        $db = mysql_select_db("db", $connection);

                        //MySQL Query to read data

     if(!isset($_GET["u"])){
             echo " <h2>OOPS!</h2><p> The link you have followed is INVALID. It would be great, if you could contact support@clix4offer.info to report this issue. REASON: Doesn't contain any PUBLISHER parameter";   

         } else if(!isset($_GET['o'])){
         echo " <h2>No Offers Found!</h2><p> The link you clicked was invalid. REASON: Doesn't contain any CAMPAIGN ID, contact support."; 

         } else {
             $offer = mysql_real_escape_string($_GET["o"]);
             $checkOffer = mysql_query("SELECT * FROM offers WHERE offerId = '$offer'");
             if(mysql_num_rows($checkOffer) == 0){
                  echo " <h2>No Offers Failed!</h2><p> The link you clicked was invalid. REASON: Campaign ID is not given by us! Don't trick us. Please try again, if the problem occurs again, contact support."; 

             } else { 
         echo $outPut;
         }

         } 

?> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> </body> </html> <?php
//Closing Connection with Server
mysql_close($connection);
?> 

Recommended Answers

All 4 Replies

Please someone help.

Why do people insist on opening their post with something like this? It's pretty obvious that you're looking for help if you're posting on the forum here. I don't mean to be rude, but it's really unnecessary. Maybe I'm just being nit picky, and should go take a nap.

I read your problem maybe a few different times, and it still doesn't make any sense to me.
What is this supposed to be, your own URL shortner?

Also, you might want to check your code, it appears you have also posted credentials to your database.

Yes. It's my url shorter with YOURLS. When the $url creates a http://something.com/?a=123 I want to put that cteated $url I the $shorturl. So the custom url generator generates a shorturl for the long url created by $url above.

Really sorry

If i understand what your saying

$shorturl = $url

is what you should have on line 52.

found a way to do it. thanks everyone

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.