SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot csmarshal's Avatar
    Join Date
    Jan 2005
    Location
    Munich
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation <?php echo $url;?>

    heyy!
    on my site there is an input form where users put in an URL. If they only put in the URL NOT including the http:// it will just goto http://www.mysite.com/www.theirsite.com

    So, can anyone edit this file so that it will automaticially add the http:// in front of the url, so users only have to type in the www.theirsite.com part.

    Help would be greatly appreciated.
    For whoever can do this for me will get 100 free boxes for their ad on my pixel site.

    Heres the php Document:
    PHP Code:
    <?php

    session_start
    ();
    include (
    "../config.php");
    include (
    "login_functions.php");

    process_login();

    $gd_info = @gd_info();
    if (
    $gd_info['GIF Read Support']) {$gif_support="GIF";} ;
    if (
    $gd_info['JPG Support']) {$jpeg_support="JPG";};
    if (
    $gd_info['PNG Support']) {$png_support="PNG";};

    require (
    "header.php");
    if (
    $_REQUEST['submit']!='') {
        
    //$sql = "UPDATE blocks set url='".$_REQUEST['url']."' , alt_text='".$_REQUEST['alt_text']."', approved='N' where user_id='".$_SESSION['ID']."' and status='sold' ";
        //mysql_query ($sql) or die (mysql_error());
        //echo $sql;
        
    }

    ?>


    <h3>Publish your pixels</h3>


    </p>
    <?php

    if ($_REQUEST[click_block]!='') {

        
    $map_x $_REQUEST['map_x'];
        
    $map_y $_REQUEST['map_y'];

        
    $map_x floor ($map_x 10)*10;
        
    $map_y floor ($map_y 10)*10;
        
    $clicked_block = (($map_y*GRID_WIDTH)+$map_x)/10 ;
        if (
    $clicked_block==0) {
            
    $clicked_block="0";// convert to string

        
    }

        echo 
    $clicked_block;

    }

    ######################################################

    function check_right($x$y) {

        global 
    $end_x$end_y;

        
    $sql "Select * from blocks where user_id=".$_SESSION[ID]." AND status='sold' and `x`='".($x+10)."' and y='".$y."' ";
        
    $result mysql_query ($sql) or die (mysql_error());
        
    $row mysql_fetch_array($result);

        if (
    $row[block_id]!='') {
            
    $end_x $row[x]+10;
            
    $end_y $row[y]+10;
            return 
    $row;
        } else {
            return 
    false;
        }


    }
    #######################################
    function check_down($x$y) {

        global 
    $end_x$end_y;

        
    $sql "Select * from blocks where user_id=".$_SESSION[ID]." AND status='sold' and `x`='".$x."' and y='".($y+10)."' ";
        
    $result mysql_query ($sql) or die (mysql_error());
        
    $row mysql_fetch_array($result);

        if (
    $row[block_id]!='') {
            
    $end_x $row[x]+10;
            
    $end_y $row[y]+10;
            return 
    $row;
        } else {
            return 
    false;
        }

    }

    #####################

    function save_block ($uploaded_img$b_row$url$alt_text$tmpname ) {
        global 
    $x1$y1;
        
    $img_size getimagesize($tmpname);

        if (
    $b_row[x]-$x1 >= $img_size[0]) {
            return;
        }
        if (
    $b_row[y]-$y1 >= $img_size[1]) {    
            return;
        }

        
        
    $postfix = ($b_row[x]-$x1)."".($b_row[y]-$y1);
        if (
    function_exists("imagecreatetruecolor")) {
            
    $dest imagecreatetruecolor(1010);
        } else {
            
    $dest imagecreate(1010);
        }

        
    imagecopy $dest$uploaded_img00$b_row[x]-$x1$b_row[y]-$y11010 );
        
    imagepng($dest$tmpname.$postfix);

        
    $h fopen ($tmpname.$postfix"rb");
        
    $data fread($hfilesize($tmpname.$postfix));
        
    $data base64_encode($data);
        

        
    $sql "UPDATE blocks set image_data='$data', mime_type='image/x-png', url='$url', approved='N',  alt_text='$alt_text' WHERE block_id='".$b_row[block_id]."' ";
        
    mysql_query ($sql) or die (mysql_error());
        
    //echo $sql."<br>";

        
    fclose($h);
        
    unlink ($tmpname.$postfix);

        
    imagedestroy($dest);
        
    //echo "<hr>";

    }

    ##################


    // look right. if no more, go down to next row and look right, repeat until no more rows

    //print_r($_REQUEST);

    $clicked_block $_REQUEST[block_id];
    if (
    $_REQUEST[block_id]!='') {

        
        



        
    $sql "SELECT user_id, x, y, block_id, url, alt_text, status FROM blocks where block_id=".$clicked_block;
        
    $result mysql_query ($sql) or die (mysql_error());
        
    $b_row mysql_fetch_array($result);

        if (
    $_REQUEST['url']=='') {
            
    $url $b_row['url'];
        } else {
            
    $url $_REQUEST['url'];
        }

        if (
    $_REQUEST['alt_text']=='') {
            
    $alt_text $b_row['alt_text'];
        } else {
            
    $alt_text $_REQUEST['alt_text'];
        }

        if ((
    $b_row[user_id]!=$_SESSION[ID]) || ($b_row[status]!='sold')) {

            print (
    "Erorr: you do not own this block! Please click on your block.<br>");
        } else {

            
    $u_row[y] = $b_row[y]; // init upload row vars
            
    $u_row[y] = $b_row[y];

            
    $u_row $b_row;

            
    $x1 $b_row[x];
            
    $y1 $b_row[y];

    ###########################################


            
    if ($_REQUEST['action']=='upload') {

                if (
    $_REQUEST[url]=='') {
                    
    $error .= "<b>- URL is blank. Please fill it in.</b><br>";

                }

                if (
    $_REQUEST[alt_text]=='') {
                    
    $error .= "<b>- ALT link text is blank. Please fill it in.</b><br>";

                }

                if (
    $_FILES['block_image']['tmp_name']=='') {
                    
    $error .= "<b>- No Image uploaded. Please select an image to upload.</b><br>";

                }

                

                if (
    $error) {
                    echo 
    '<font color="red"><b>ERROR:</b></font><br>'.$error;

                }

                
    $thanks='';

            }

            if ((
    $_REQUEST['action']=='upload') && (!$error)) {

                
    $thanks =  "<br><font color='green'><b>Thank you, your changes were submitted, and will be published once they are approved!</b><br> </font>";

                switch (
    $_FILES['block_image']['type']) {
                    case 
    "image/gif":
                        
    $uploaded_img imagecreatefromgif($_FILES['block_image']['tmp_name']);
                        break;
                    case 
    "image/jpg":
                    case 
    "image/jpeg":
                    case 
    "image/pjpeg":
                        
    $uploaded_img imagecreatefromjpeg($_FILES['block_image']['tmp_name']);
                        break;
                    case 
    "image/png":
                    case 
    "image/x-png":
                        
    $uploaded_img imagecreatefrompng($_FILES['block_image']['tmp_name']);
                        break;
                    default:
                        echo 
    "<b>File Not Supported:".$_FILES['block_image']['type']."</b><br>";
                        break;
                }

                
    //echo "Processing upload...$uploaded_img<br>";

                
    do {
                    
    ?><?php
                    $start_x 
    $u_row[x];
                    
    $start_y $u_row[y];

                     
    save_block ($uploaded_img$u_row$url$alt_text$_FILES['block_image']['tmp_name'] );
                    
    ///
                    
                    
    while ($u_row=check_right($u_row[x], $u_row[y])) {
                        
    ?><?php
                             save_block 
    ($uploaded_img$u_row,  $url$alt_text$_FILES['block_image']['tmp_name'] );

                    }
                    
    //echo "<br>";
                    
    $u_row[x] = $start_x;
                    
    $u_row[y] = $start_y;
                    
                } while (
    $u_row=check_down($u_row[x], $u_row[y]));
        
            }





    ############################################

    if (!$thanks) {

        
    ?>
        <p>
        
        - Supported formats: <?php echo "$gif_support $jpeg_support $png_support"?>
        <br>
        The current Image for this selection is: <br>
        </p>
    <?php


    $end_x 
    $b_row[x]+10;
    $end_y $b_row[y]+10;
        do {
            
    ?><img src="get_image2.php?block_id=<?php echo $b_row[block_id];?>&t=<?php echo time(); ?>" width="10" height="10" border='0'><?php
            $start_x 
    $b_row[x];
            
    $start_y $b_row[y];
            
    /*
            if ($b_row[url]!='') {
                $url = $b_row[url];
                $alt_text = $b_row[alt_text];

            } else{
                $url= $_REQUEST['url'];
                $alt_text = $_REQUEST['alt_text'];

            }
            */
            
    while ($b_row=check_right($b_row[x], $b_row[y])) {
                
    ?><img src="get_image2.php?block_id=<?php echo $b_row[block_id];?>&t=<?php echo time(); ?>" width="10" height="10" border='0'><?php

            
    }
            echo 
    "<br>";
            
    $b_row[x] = $start_x;
            
    $b_row[y] = $start_y;
            if (
    $b_row[url]!='') {
                
    $url $b_row[url];
                
    $alt_text $b_row[alt_text];

            }
        } while (
    $b_row=check_down($b_row[x], $b_row[y]));

    $x2 $end_x;
    $y2 $end_y;
    //echo "[$x1] [$y1] [$x2] [$y2]";
    $max_x $x2-$x1;
    $max_y =  $y2-$y1;

        
    ?>
        The current max image size is <?php echo $max_x?> pixels wide and <?php echo $max_y?> pixels high<br>
        <form enctype="multipart/form-data" method="post" action="publish.php">
        <table>
        <tr bgcolor="#ffffff" ><td width="121"><font size="2">Upload Image:</font></td><td width="1079"><input size="15" type="file" name="block_image" value=""></td></tr>
        <tr><td>
        <input type="hidden" name="block_id" value="<?php echo $clicked_block?>">
        <input type="hidden" name="action" value="upload">
        </td><td></td>
        </tr>
        <tr><td>
    My URL:</td> <td><input type='text' size='100' name='url' value='<?php echo $url;?>'> </td></tr>
    <tr><td>
    My ALT link text:</td>  <td><input type='text' size='100' name='alt_text' value='<?php echo $alt_text?>'> </td></tr>
    <tr><td colspan=2>
    <input type="submit" name="submit" value="Upload"> 
    <font color="#CC0000">Remeber that if you purchased a block of <strong>20x20</strong> pixels, you <strong>MUST</strong> format your image to be <strong>20x20</strong> pixels. Pictures have to have the same dimensions as the squares purchased by you. </font></td>
    </tr>
        </table>
    </form>
        
    <?php
        
    }
        echo 
    $thanks;
        }

    }

    ?>
    <p>
    Each square represents a block of 100 pixels (10x10). Select the blocks that you want, and then use the form to upload the image and update the link.<br>
    <b>To mark block(s) for upload: Click on the top-right corner of a block / group of blocks!</b><br>
    - Only blocks owned by you are shown. Click on a block to edit it.<br>
    - <b>Red</b> blocks have no image. Click on them to upload your image.  <br>
    - Click on 'Upload' to save your URL and Link text.<br>
    </p>
    <!--
    <input type="button" value="Refresh" onclick='window.location.reload()'><br>
    -->
    <?php
    $sql 
    "SELECT approved FROM blocks where user_id=".$_SESSION[ID]." and approved='N' LIMIT 1";
    $result mysql_query ($sql) or die (mysql_error());
    $row mysql_fetch_array($result);
    if (
    mysql_num_rows($result)==0) {
        
    ?>
    <br>
    <div width='100%' style="border-color:green;border-style:solid;padding:5px;">Note: Your pixel(s) are approved and scheduled to go live in the next update! Updates are made at least every 12 hours.</div>
        <?php

    } elseif ($row[approved]=='N') {
    ?>
    <br>
    <div width='100%' style="border-color:#FF9797; border-style:solid;padding:5px;">Note: Your pixel(s) are waiting for approval. They will be scheduled to go live once they are approved. Approval will take no longer than 6 hours. </div>
        <?php
    }
    ?>

    <?php
        $sql 
    "SELECT * FROM blocks WHERE user_id=".$_SESSION[ID]." AND status='sold'   ";
        
    $result mysql_query ($sql) or die (mysql_error());
        
    ?>
    <map name="main" id="main">

    <?php

    while ($row=mysql_fetch_array($result)) {

        
    //if (strlen($row['image_data'])>0) {
    ?>

    <area shape="RECT" coords="<?php echo $row['x'];?>,<?php echo $row['y'];?>,<?php echo $row['x']+10;?>,<?php echo $row['y']+10;?>" href="publish.php?block_id=<?php echo ($row['block_id']);?>" title="<?php echo htmlspecialchars($row[alt_text]);?>" alt="<?php echo htmlspecialchars($row[alt_text]);?>"  />

    <?php
    //    }

    }
    ?>

    <img src="show_map.php?time=<?php echo (time()); ?>" width="<?php echo GRID_WIDTH*10?>" height="<?php echo GRID_HEIGHT*10?>" border="0" usemap="#main" />

  2. #2
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try something like this, to check if www is at the start:

    PHP Code:
    if (substr($url3) == 'www') {
    $url = ("http://" $url);


  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    Beautiful Rhode Island, USA
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're better off just checking whether or not the http:// is there or not, then adding it if needed. (That way sitepoint.com will work, not just www.sitepoint.com)

    PHP Code:
    if (strpos($url'http://') != 0$url "http://" $url
    Last edited by Bil; Nov 15, 2005 at 13:42. Reason: logic error

  4. #4
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah that would be even better. Alternatively you could try connecting to the site they provided and if it doesnt connect (i.e. if they're getting the http://www.mysite.com/www.theirsite.com problem, then it wont connect. Something like this, I guess:

    PHP Code:
    if (@fopen($url"r") == false) {
    // code here

    That would just tell you whether its a valid URL, and if not you could add 'http://' to the start.

  5. #5
    SitePoint Zealot csmarshal's Avatar
    Join Date
    Jan 2005
    Location
    Munich
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the help!

    Lemonade:
    where in the php file wouldi put this?
    PHP Code:
    if (@fopen($url"r") == false) {
    // code here

    same witht the code bil suggested. Im not that good with php...sorry.

  6. #6
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant tell exactly - Quite a lot of code there. You would put it in wherever the URL is being passed into the script. Perhaps where you're checking the info after being submitted.

  7. #7
    SitePoint Zealot csmarshal's Avatar
    Join Date
    Jan 2005
    Location
    Munich
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanx again.
    ill give it a try and let you know how it went.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •