Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Posts posted by Drongo_III

  1.  

    Found a  couple of problems..

     

    First, you really want to change your mime type From multipart/related   TO: multipart/alternative.  As these are not "related" to each other. 

     

    Second...  you need to get rid of the spacing and \n's from within the body.  As you are in a quoted string the carrage returns and spacing will all be applyed in the message.

     

     

    Here's a working example with these changes:

     

    <?php
    
    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"boundaryMarker\"\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    
    $body = <<<MyEmailMessage
    --boundaryMarker
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    
    THIS IS PLAIN TEXT EMAIL
    
    
    --boundaryMarker
    Content-Type: text/html; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    
    
    <h1>THIS IS HTML VERSION</h1>
    
    
    --boundaryMarker--
    
    MyEmailMessage;
    
    
    $to      = 'me@myemail.com';
    $subject = 'This is a test message';
    
    mail($to, $subject, $body, $headers);
    
    

     

    Lachild thank you so much for your response. That fixed it all and now works perfectly. I'm now very happy :) 

     

    As you've highlighted the mime type to me the penny kind of drops. So I guess 'multipart/related' might be used for things like attachments?

     

     

     

    Might it have something to do with the indenting, and copious amount of newlines, you've added to the mail..?

    Unfortunately I do not have the time (nor the desire, to be honest) to read up on the RFC to verify this. That said, it is worth looking into, and you should definitely read the RFC.

     

    Also, no need to use "\n" inside the string to add newlines. You're already doing that with the actual newlines.

     

    Christian - thanks for the tip. To be honest I was just working from examples on php.net which isn't overly expansive but I guess I'm looking in the wrong place for descriptive info on this. I shall check out RFC article.

  2. This is probably going to centre around two main functions.

     

    Firstly file_get_contents (http://www.php.net/manual/en/function.file-get-contents.php) to grab the page data. You can enter a url as the file name.

     

    Then you'll want to break out your regular expressions and use a function such as  preg match (http://php.net/manual/en/function.preg-match.php).  This returns an array of matches.

     

     

     

    I'm brand new to PHP coding (but was a old-time VB coder). I figured out how to search a URL for a string. What I'm looking to figure out is two-fold:

     

    1. I want search a specific site and grab some content there that's date-specific. That date is listed in the site's Title tag so the title tag will say something like "This weekend's stats for February 22-23, 2013 ---".

     

    I can search for the title tag but how to I go about actually turning just the key piece I need into a string? 

     

    2. Also on this page I need to find roughly 80 pieces of data that will be all the same except for one unknown string in the middle of 80 TD/URL/name tags (movie titles). How do I get the 80 items into an array? I'm sure I'll use a FOR loop or WHILE loop but what's the code for this look like to get those lines into strings?

     

    Thanks.

  3. Hi Guys

     

    I am trying to setup an email template that contains both a html and plain text version in one.

     

    What follows is a simplified version but what I want to do is simply have both versions in an email template and then run a str_replace which will populate the template's place holders with the relevant data before sending - this is why I want everything in a single file. But before I get to that point I simply need to get the email working - however at present when I run the code below I just get  blank output in the email body.

     

    If anyone could propose a reason why this is happening it would be appreciated.

     

    Incidentally I realise the mime boundary isn't ideal - this is just for testing.

     

    <?php
    
    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/related; boundary=\"boundaryMarker\"\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    
    $body = "
    
    	--boundaryMarker\n	
    	Content-Type: text/plain; charset=\"charset=us-ascii\" \n
    	Content-Transfer-Encoding: 7bit\n\n
    	
    		THIS IS PLAIN TEXT EMAIL
    		
    		\n\n
    		
    	--boundaryMarker\n	
    	
    	\n\n
    	
    	Content-Type: text/html; charset=ISO-8859-1\n
    	Content-Transfer-Encoding: 7bit\n\n
    	
    	
    	<h1>THIS IS HTML VERSION</h1>
    	
    	\n\n
    	
    	--boundaryMarker--\n	
    
    ";
    
    
    $to      = 'MyEmail@Myemail.com';
    $subject = 'This is a test message';
    
    mail($to, $subject, $body, $headers);
    

     

  4. Setup a network drive and mount it on both servers.  You can either do this through a third server just to store the images or use one of the existing ones as the base.

     

    Hi Kick

     

    Sorry it has taken a while to respond to this.

     

    Lets assume that this isn't possible to setup - because I have very limited control over the hardware in this instance.

     

    As a way of doing it via php would perhaps ftping the files via php's ftp functions be a possible solution? Any reasons you would advise not using this?

  5. Thanks Jessica

     

    You give me too much credit and I can't in fact see from the time stamps what the dates are... However you did give me cause to check what I was doing with the dates and it appears it wasn't the output that was the problem but there was some test code messing up the strtotime conversion earlier in the code. So thank you for prompting me to check that.

     

    You can easily look at those timestamps and see that they are IN FACT in order.

    1357....

    13587...

    13589...

    1359....

    13874...

    13877...

    So...the problem is clearly not in the code you've posted.

     

     

     

    Edit: The last one in the list is:2013-12-22 19:50:33

    and the first is:

    2013-01-04 01:35:43

     

    I think you need to refer to date() for the right formats to use for your human-readable date.

  6. Hi Guys

     

    Posted on here a few days ago about sorting a multi dimensional array based on date. I thought I had it working but now i realise it doesn't appear to be sorting correctly.

     

    Essentially I have an array that is combined from feeds from twitter and facebook. I converted the dates using strtotime and the unsorted array looks like this:

     

    
    print_r($socialMediaArray);
    (
       [0] => Array
        (
    	    [date] => 1359214851
    	    [message] => some message
    	    [from] => twitter
        )
       [1] => Array
        (
    	    [date] => 1358991499
    	    [message] => some message
    	    [from] => twitter
        )
       [2] => Array
        (
    	    [date] => 1358799273
    	    [message] => some message
    	    [from] => twitter
        )
       [3] => Array
        (
    	    [date] => 1387741833
    	    [message] => some message
    	    [from] => twitter
        )
       [4] => Array
        (
    	    [date] => 1387490401
    	    [message] => some message
    	    [from] => twitter
        )
       [5] => Array
        (
    	    [date] => 1357263343
    	    [message] => some message
    	    [from] => facebook
        )
    )
    
    

     

    I then ran the following code to try and sort on date order

     

    function cmp ($a, $B)
     {
     return $a['date'] - $b['date'];
     }
     usort($socialMediaArray, "cmp"); // Sort the array by date order.
    
    
     echo "SORTED ARRAY <pre>";
     print_r($socialMediaArray);
    
    
    SORTED ARRAY
    
    Array
    (
       [0] => Array
        (
    	    [date] => 1357263343
    	    [message] => some message
    	    [from] => facebook
        )
    
       [1] => Array
        (
    	    [date] => 1358799273
    	    [message] => some message
    	    [from] => twitter
        )
    
       [2] => Array
        (
    	    [date] => 1358991499
    	    [message] => some message
    	    [from] => twitter
        )
    
       [3] => Array
        (
    	    [date] => 1359214851
    	    [message] => some message
    	    [from] => twitter
        )
    
       [4] => Array
        (
    	    [date] => 1387490401
    	    [message] => some message
    	    [from] => twitter
        )
    
       [5] => Array
        (
    	    [date] => 1387741833
    	    [message] => some message
    	    [from] => twitter
        )
    
    )
    
    
    

     

    But when I then convert the dates back into something readable it becomes apparent that the dates haven't been sorted correctly as they come out as

     

    Fri Jan 04 1:35:43

    Mon Jan 21 20:14:33

    Thu Jan 24 1:38:19

    Sat Jan 26 15:40:51

    Thu Dec 19 22:00:01

    Thu Dec 19 22:00:01

     

     

    I'm not overly familiar with using usort, hence why I posted here, so if someone could offer up a possible reason as to why this may be happening it would appreciated.

     

    Many thanks,

     

    Drongo

  7. Thanks very much guys that worked a treat. I was getting massively confused because I thought I have to pass $a and $b and I couldnt quite see how I would make that dynamic - over complicating it clearly!

     

     

     

    The usort() function passes $a and $b to the callback function where $a and $b are pairs of elements in the array.

     

    If you convert your dates to timestamps then

     

    usort($array, 'cmp');
    
    function cmp ($a $b )
    {
    return $a['date'] - $b['date'];
    }
    

  8. Two questions so I can get my tired grey matter around this:

     

    1) I should convert the date values to unix time stamps?

    2) in the example usort function on php manual ( copied below) what is $b? Is this a copy of the original array against which the value $a is compared?

     

    function cmp($a, $B)
    {
       if ($a == $B) {
        return 0;
       }
       return ($a < $B) ? -1 : 1;
    }
    $a = array(3, 2, 5, 6, 1);
    usort($a, "cmp");
    

     

    But first, store your dates in a format that can be sorted

  9. Hi Guys

     

    Bit confused on the best way to approach this so some advice would be welcome.

     

    I have a multidimensional array which is created from a twitter and facebook feed combined into a single array.

     

    I want to sort the array by date order but I'm not sure of the best way to do this. I have been looking at array_multisort but I can't see how you get that to work without specifying a precise index.

     

    An example of the array I am working with is as follows:

     

    print_r($socialMediaArray);
    
    Array
    (
       [0] => Array
        (
    	    [date] => Fri Jan 04 1:35:43
    	    [Message] => Brilliant day last thursday - lets do it again
    	    [from] => facebook
        )
       [1] => Array
        (
    	    [date] => Sat Jan 26 15:40:51
    	    [Message] => how do you like my new fb page?
    	    [from] => facebook
        )
       [2] => Array
        (
    	    [date] => Thu Jan 24 01:38:19
    	    [Message] => Some test message from twitter
    	    [from] => twitter
        )
       [3] => Array
        (
    	    [date] => Mon Jan 21 20:14:33
    	    [Message] => @tester here is a message just for you
    	    [from] => twitter
        )
       [4] => Array
        (
    	    [date] => Sun Dec 16 19:50:33
    	    [Message] => some other message #test
    	    [from] => twitter
        )
    
    )
    
    

  10. Try:

     

    $list .= implode('; ', $row['email']);

     

    I am trying to create a mailing list, with the email addresses being pulled from the dB. I have this:

    $emails = array($row['email']);
    $list .= implode('; ', $emails);
    

     

    Which returns all of the values from the dB, but it is not creating the "; " (semicolon and space) between each email address.

  11. I think you need to post the full code but based on what I can see there you setup the connection on '$this->connection' so when you try to retrieve the result you should write it:

    $result = $this->connection->query($sql);

     

    Also in your index file trying using var_dump($this->connection); to see what you're getting.

     

     

     

    I have setup the connection in a seperate file (tested it is working) with the following code:

     

    function MySQLDB(){
    /* Make connection to database */
    $this->connection = new mysqli( DB_SERVER, DB_USER, DB_PASS, DB_NAME) or die ('Cannot open database');
    //mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
    // mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
    

     

    So when I changed my code in my index file to

     

    $session->connection;
    $result = $connection->query($sql);
    While ($row = $result->fetch_array(MYSQLI_BOTH)){
    
    echo "<li class=\"clear\">";
    if ($img = $row['image'] != ""){
    echo "<div class\"imgl\"><img src=\".$img.\" alt=\"\"/></div>";
    }
    echo "<div class=\"latestnews\">".
    "<p><a href=\"news.php?id=".$row['id'].">".$row['title']."</a></p><p>".$row['content']."</p></div>";
    }
    $connection->close();
    

     

    Im sure my issue is when trying to use $connection as my database connector im just not sure why/what I am doing wrong?

  12. I've not read through the miles of code but at a glance if you wanted to get a copy of this email you would change the first line of your php script

     

    $owner_email = $_POST["owner_email"] . ", YOUREMAIL@DOMAIN.com";
    

     

    Or if you don't want the user to see your email address has been added then add yourself as a BCC http://php.net/manual/en/function.mail.php

     

     

     

    Please assist me with this form. I want to send the email to me when the client hits the send button on www.themogulwaltononthames.com/contacts.html

    Where on this script should i place my email so that i can receive the form.

     

    Here is the java script im using:

     

     

    //forms

    ;(function($){

    $.fn.forms=function(o){

    return this.each(function(){

    var th=$(this)

    ,_=th.data('forms')||{

    errorCl:'error',

    emptyCl:'empty',

    invalidCl:'invalid',

    notRequiredCl:'notRequired',

    successCl:'success',

    successShow:'4000',

    mailHandlerURL:'bat/MailHandler.php',

    ownerEmail:'support@template-help.com',

    stripHTML:true,

    smtpMailServer:'localhost',

    targets:'input,textarea',

    controls:'a[data-type=reset],a[data-type=submit]',

    validate:true,

    rx:{

    ".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},

    ".state":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},

    ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},

    ".phone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},

    ".fax":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},

    ".message":{rx:/.{20}/,target:'textarea'}

    },

    preFu:function(){

    _.labels.each(function(){

    var label=$(this),

    inp=$(_.targets,this),

    defVal=inp.val(),

    trueVal=(function(){

    var tmp=inp.is('input')?(tmp=label.html().match(/value=['"](.+?)['"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()

    return defVal==''?defVal:tmp

    })()

    trueVal!=defVal

    &&inp.val(defVal=trueVal||defVal)

    label.data({defVal:defVal})

    inp

    .bind('focus',function(){

    inp.val()==defVal

    &&(inp.val(''),_.hideEmptyFu(label),label.removeClass(_.invalidCl))

    })

    .bind('blur',function(){

    _.validateFu(label)

    if(_.isEmpty(label))

    inp.val(defVal)

    ,_.hideErrorFu(label.removeClass(_.invalidCl))

    })

    .bind('keyup',function(){

    label.hasClass(_.invalidCl)

    &&_.validateFu(label)

    })

    label.find('.'+_.errorCl+',.'+_.emptyCl).css({display:'block'}).hide()

    })

    _.success=$('.'+_.successCl,_.form).hide()

    },

    isRequired:function(el){

    return !el.hasClass(_.notRequiredCl)

    },

    isValid:function(el){

    var ret=true

    $.each(_.rx,function(k,d){

    if(el.is(k))

    ret=d.rx.test(el.find(d.target).val())

    })

    return ret

    },

    isEmpty:function(el){

    var tmp

    return (tmp=el.find(_.targets).val())==''||tmp==el.data('defVal')

    },

    validateFu:function(el){

    el.each(function(){

    var th=$(this)

    ,req=_.isRequired(th)

    ,empty=_.isEmpty(th)

    ,valid=_.isValid(th)

     

    if(empty&&req)

    _.showEmptyFu(th.addClass(_.invalidCl))

    else

    _.hideEmptyFu(th.removeClass(_.invalidCl))

     

    if(!empty)

    if(valid)

    _.hideErrorFu(th.removeClass(_.invalidCl))

    else

    _.showErrorFu(th.addClass(_.invalidCl))

    })

    },

    getValFromLabel:function(label){

    var val=$('input,textarea',label).val()

    ,defVal=label.data('defVal')

    return label.length?val==defVal?'nope':val:'nope'

    }

    ,submitFu:function(){

    _.validateFu(_.labels)

    if(!_.form.has('.'+_.invalidCl).length)

    $.ajax({

    type: "POST",

    url:_.mailHandlerURL,

    data:{

    name:_.getValFromLabel($('.name',_.form)),

    email:_.getValFromLabel($('.email',_.form)),

    phone:_.getValFromLabel($('.phone',_.form)),

    fax:_.getValFromLabel($('.fax',_.form)),

    state:_.getValFromLabel($('.state',_.form)),

    message:_.getValFromLabel($('.message',_.form)),

    owner_email:_.ownerEmail,

    stripHTML:_.stripHTML

    },

    success: function(){

    _.showFu()

    }

    })

    },

    showFu:function(){

    _.success.slideDown(function(){

    setTimeout(function(){

    _.success.slideUp()

    _.form.trigger('reset')

    },_.successShow)

    })

    },

    controlsFu:function(){

    $(_.controls,_.form).each(function(){

    var th=$(this)

    th

    .bind('click',function(){

    _.form.trigger(th.data('type'))

    return false

    })

    })

    },

    showErrorFu:function(label){

    label.find('.'+_.errorCl).slideDown()

    },

    hideErrorFu:function(label){

    label.find('.'+_.errorCl).slideUp()

    },

    showEmptyFu:function(label){

    label.find('.'+_.emptyCl).slideDown()

    _.hideErrorFu(label)

    },

    hideEmptyFu:function(label){

    label.find('.'+_.emptyCl).slideUp()

    },

    init:function(){

    _.form=_.me

    _.labels=$('label',_.form)

     

    _.preFu()

     

    _.controlsFu()

     

    _.form

    .bind('submit',function(){

    if(_.validate)

    _.submitFu()

    else

    _.form[0].submit()

    return false

    })

    .bind('reset',function(){

    _.labels.removeClass(_.invalidCl)

    _.labels.each(function(){

    var th=$(this)

    _.hideErrorFu(th)

    _.hideEmptyFu(th)

    })

    })

    _.form.trigger('reset')

    }

    }

    _.me||_.init(_.me=th.data({forms:_}))

    typeof o=='object'

    &&$.extend(_,o)

    })

    }

    })(jQuery)

    ---------------------------------------------------------------

    Im also using a form mail handlers PHP script:

    ----------------------------------------------------------------------------

     

     

    <?php

    $owner_email = $_POST["owner_email"];

    $headers = 'From:' . $_POST["email"];

    $subject = 'A message from your site visitor ' . $_POST["name"];

    $messageBody = "";

     

    if($_POST['name']!='nope'){

    $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['email']!='nope'){

    $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }else{

    $headers = '';

    }

    if($_POST['state']!='nope'){

    $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['phone']!='nope'){

    $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['fax']!='nope'){

    $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['message']!='nope'){

    $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";

    }

     

    if($_POST["stripHTML"] == 'true'){

    $messageBody = strip_tags($messageBody);

    }

     

    try{

    if(!mail($owner_email, $subject, $messageBody, $headers)){

    throw new Exception('mail failed');

    }else{

    echo 'mail sent';

    }

    }catch(Exception $e){

    echo $e->getMessage() ."\n";

    }

    ?>

  13. Could be a silly question but you have formed the connection via mysqli to create an object? i.e.

     

    $mysqli = new mysqli("localhost", "user", "password", "database");
    

     

    And are you sure the sql query is sound?

     

    Hey there im trying to change my website from mysql statments to mysqli. I tried changing one of my simple statments to get some news from the db and im running into the following error:

     

     

     

    Here is the code I am using, does anyone know what/why the error is producing:

     

    $sql = "SELECT * FROM news ORDER by id DESC LIMIT 2,0";
    $result = $mysqli->query($sql);
    While ($row = $result->fetch_array(MYSQLI_BOTH)){
    
    echo "<li class=\"clear\">";
    if ($img = $row['image'] != ""){
    echo "<div class\"imgl\"><img src=\".$img.\" alt=\"\"/></div>";
    }
    echo "<div class=\"latestnews\">".
    "<p><a href=\"news.php?id=".$row['id'].">".$row['title']."</a></p><p>".$row['content']."</p></div>";
    }
    
    

  14. I went with Barand's suggestion as it seemed more inline with the way I envisoned it working and it worked a treat.

     

    I confess I've only used very simple joins and I would like to understand mutilple joins better - I am a bit weak on my sql. So I'm hoping someone can answer a few questions on this...

     

    Firstly this line:

     

    CASE WHEN jobs.request_other <> 0 THEN req.email ELSE users.email END as email
    

     

    The only thing confusing me is the 'as email' bit at the end. Why do you give it the alias 'email'? It doesn't appear to be used anywhere else in the query so what's the purpose here?

     

    Also the req.email part. 'req' at this point in the query has no meaning so am I right in saying that it becomes meaningful when you alias it as 'uses as req' later in the query?

     

     

    And my last question is about how the query gets executed with mutliple joines like this. Is it the case that the Inner join statement will run first and retrieve all email results where and ID matches in both tables. Then the query gets re-run with the Left join statement and overwrites the email results whereever there is an id match resulting from 'jobs.request_other <> 0' in boht tables? Is that right?

     

    Many thanks for your patience,

     

    Drongo

     

     

     

     

    try

     

    SELECT jobs.job_number, jobs.brand, jobs.description,
    CASE WHEN jobs.request_other <> 0 THEN req.email ELSE users.email END as email
    FROM jobs
    INNER JOIN users on jobs.user_id = users.id
    LEFT JOIN users as req ON jobs.request_other = req.id
    WHERE jobs.status !='live'
    ORDER BY jobs.brand ASC, jobs.date_created DESC

     

    or you could replace the CASE...END with

     

    IFNULL(req.email, users.email) as email

  15. Hello

     

    Very much stuck on this and it's held me up for a good few hours so help is much appreciated - i'll try and keep this brief.

     

    Essentially I have two tables - a 'users' table with cols for user id, email, name etc. and a 'jobs' table containing a lot of columns that I won't list but there are two that are relevant to this.

     

    The two columns are 'user_id' and 'request_other' - both of these are relational to the users table user id. There are two cols because the application stores data on the person adding the job (in user_id) and the person who requested it (in request_other). This latter field get set to '0' if the person adding the job is also the requester.

     

    So here's where I'm stuck. When I query the jobs table to populate some data in a page I need to get the email address, based on the user_id, from the users table. So I query the jobs table and perform an inner join as follows and all works well(stripped out most of the fields for the sake of clarity):

     

    SELECT jobs.job_number, jobs.brand, jobs.description, users.email FROM jobs INNER JOIN users on jobs.user_id = users.id WHERE jobs.status !='live' ORDER BY jobs.brand ASC, jobs.date_created DESC
    

     

    Here the join is done on the basis of a match between user_id in both tables. BUT what I really want is to conditionally alter the '...INNER JOIN users on' part of the query to say:

     

    "If request_other !=0 then use request_other = users.id ELSE use jobs.user_id = users.id"

     

    I dont know if that's possible or not? I've tried adding in cases and If statements but nothing seems to work as I am probably doing it wrong - despite a lot of trying :/

     

    If anyone could suggest a means of achieving what I am after I would be eternally thankful!

  16. Here are a few things to try and help you resolve the issue:

     

    1) ensure error reporting is on - error_reporting(E_ALL); . This might give you a clue as to the issue.

    2) Your include uses short tags, i.e. <? SOME PHP CODE ?> instead of full tag structure <?php SOME PHP CODE ?>- So try using full tags as depending your individual configuration short tags may not be enabled.

     

     

     

    <?include("inc/incfiles/headder.inc.php"); ?>

     

    Hi, I am following a tutorial on Youtube and I am trying to construct a php menu that will be a single php file that will be inserted as a header on all my pages. I have created the index.php file and a header.inc.php file (for the header script), and when I insert the "include" code to grab the header and display it, it doesn't show.

    (yes, my file is misspelled --headder instead of header, so that shouldn't be an issue)

     

    Here is my indiex.php code:

     

    <?include("inc/incfiles/headder.inc.php"); ?>

    <body>

    </html>

    <table class="homepageTable">

    <tr>

    <td width="60%" valign="top">

    <h2>Join friendbook today!</h2>

    <img src="img/social_image.jpg" width="400">

    </td>

    <td width="40%" valign="top">

    <h2>Sign Up Below</h2>

    <form action="#" method="post">

    <input type="text" size="25" name="fname" placeholder="First Name">

    <input type="text" size="25" name="lname" placeholder="Last Name">

    <input type="text" size="25" name="Username" placeholder="User Name">

    <input type="text" size="25" name="email" placeholder="Email">

    <input type="text" size="25" name="email2" placeholder="Repeat Email">

    <input type="text" size="25" name="password" placeholder="Password">

    <input type="text" size="25" name="password2" placeholder="Repeat Password">

    <input type="submit" name="submit" value="Sign Up!">

    </form>

    </td>

    </tr>

    </table>

    </body>

    </html>

     

    and here is my "header.inc.php" script that I want to display (I am directing the index.php to grab this code and use it for a common header:

     

    <head>

    <link href="css/main.css" rel="stylesheet" type="text/css">

    <title>friendsBook - A New social network</title>

    <head>

    <body>

    <div class="headerMenu">

    <div id="wrapper">

    <div class="logo">

    <img src="img/logo.png">

    </div>

    <div class="search_box">

    <form method="GET" action="search.php" id="search">

    <input name="q" type="text" size="60" placeholder="search ..." />

    </form>

    </div>

    <div id="menu">

    <a href="#">Home</a>

    <a href="#">About</a>

    <a href="#">Sign Up</a>

    <a href="#">Login</a>

    </div>

    </div>

    </div>

    <br />

    <br />

    <br />

    <br />

     

     

     

    Any help would help me from pulling out my hair at this point.

     

    Jimmy

  17. Hello

     

    Wonder if someone can give some advice.

     

    I am working on quite a high volume website (800k+ hits per month) which operates on two load balanced servers.

     

    I'm creating an image upload page that will enable users to send images and some other details to backoffice staff. The upload facility will typically allow around 4-5 image uploads at once totalling between 2-10mb of images (need to be quite high res).

     

    The intention is to allow backoffice staff to access these images for their own business purposes. But the problem i foresee is that because the servers are load balanced the images will be uploaded to one or other of the servers. So if had the system simply generate a link to a zipped folder of images and email the link to backoffice staff they would end up not being able to access the images if the load balancer directs them to a server other than the one where the images were uploaded - phew!

     

    So I'm looking for some advice on the best approach in this scenario:

     

    a) setup some kind of sync between the servers - what would you suggest?

    b ) store the images in a database - guessing blob data ? The servers both share a mysql service so this seems reasonable.

    c) some other ingenious solution proposed by the all knowing people of php freaks :)

     

    Any advice is very welcome!

     

    Drongo

  18. Hi Mate

     

    As christian pointed out basename is needed - sry my bad i was typing it out a bit fast earlier.

     

    Your code to grab what is essentially the file name should look like this:

     

    $PageLink = basename($_SERVER['PHP_SELF']);
    

     

    Then the conditional for the link will look something like

     

    <a href="fysio.php" <?php if($PageLink == 'fysio.php'){ echo 'class="ClassToApplyUnderline"';}
    else {echo 'class="ClassThatDoesNotUseUnderline"';}?> >page1</a>
    

     

    A good practice if you need to test a variable that doesn't appear to be matching is to echo it out.

     

    So try doing

     

    echo $PageLink;
    

     

    This way you can see what basename(...) is giving you to work with and you can formulate your if statement from there.

     

    Hope that helps!

     

     

    [quote name=Togo' timestamp='1360361064' post='

    1411153]

    Yes, and that is exactly what i want the script to do.

    I want the link beeing clicked on underlined when the condition is met (beeing on the page the link refers too), and if not then don't underline it.

     

    My html table may be a mess, but it looks fine to me. I did try building it the way i assume you wan't to, but it didn't give me a different result.

     

    But this:

     

    Dosen't do a thing, and thats what im now trying to figure out why not.

  19. Hi Togo

     

    What follows is a very simplistic demonstration to get you kick started.

     

     

    You need to be able to grab the url. So if your site is www.mysite.com/page1.php you can do something along the lines of the following:

     

    $pageLink =  $_SERVER['PHP_SELF'];
    

     

    This will populate a variable with whatever follows the base domain. So in the example of www.mysite.com/page1.php $pageLink will now be equal to "page1.php"

     

    You can then perform your if statement to find if you actually are on page1

     

     

    
    <a href="page1.php" id="navLink" <?php if($pageLink == 'page1.php'){ echo 'class="UNDERLINE"'} ?> >page1</a>
    

     

     

    In reality you wouldn't really get by with something quite as simplistic as the above because the url structure would be more complicated but it should get you thinking in the right direction.

     

     

    Hi,

     

    First of all, thanks for creating this site, lots of wonderful information here :)

     

    Im totally new to PHP, and im trying to implement a little php script in a new website im building.

     

    Basicly i have a table:

     

     

     

     

    When i click on a certain page, say Page 1, i wan't Page 1 to be underline and the rest of the links not.

     

    Im really lost as how i would code this in PHP, but i figure it would go something like this:

     

     

     

     

     

    This obviously dosen't work, i need a "little" help here.

  20. There are probably lots of ways of acheiving this and if it does what you want then who is to argue?

     

    If you would prefer the page didn't refresh itself then you should look into ajax. Just do a google search on 'ajax php' and you will find lots of examples.

     

    Ajax uses javascript to get/post data asynchronously enabling data to be exchanged with the server in the background without need to to refresh the page.

     

    ajax looks a bit puzzling at first but once you break it down it's very straight forward.

     

    If you have any more questions on it after googling just shout.

  21. Hey mate

     

    Don't know if you're still working on this and what follows is a hidiously impractical solution but this might point you in the right direction.

     

    In this instance it hinges on you wrapping a span around the letter in question - which would probably mean you need to do some sort of str replace when you generate the document. Probably not worth it unless you only use the fonts sparingly - i.e. in a header.

     

    Hope thi shelps a bit!

     

     

    <html>
    <head>
    <style>
    span  {
    display: inline-block;
     -webkit-transform:rotateY(180deg) !important;
     -moz-transform:rotateY(180deg) !important;
     -o-transform:rotateY(180deg) !important;
     -ms-transform:rotateY(180deg) !important;
     unicode-bidi:bidi-override !important;
     direction:rtl !important;
    
    }
    </style>
    </head>
    <body>
    <p> H<span>e</span>llo World</p>
    </body>
    </html>
    

  22. Hi Guys

     

    I worked this out in the end and I learned two things - firstly that most tutorials for this online are outdated, and secondly that facebook is the single largest sack of horse s%$t known to man with a 'war and peace' sized documentation that is mostly contradiction and dead ends.

     

    Anyway rant aside I thought I would post the solution that will hopefully help other facebook dev. noobies like me work it out.

     

    The very first step is to setup an app. For this you need to have a normal facebook profile and not a page account. IF you register just with a page style account facebook will still let you register as a developer, it will still let you enter your telephone number but once you get to the app section it will not give you the 'create app' button that you need - but facebook wont tell you that! And then you'll try to register a normal profile account and it wont let you re-enter that telephone number to register as a dev again - haha yes it's true!

     

    One you've visited the dev section of facebook and registered there (you need to enter your telephone number and they text you a code) then click 'create app'. Once you create the app you will get an 'App ID' and 'App Secret' - two long strings. Note those down and then use the script below to access the graph api:

     

    // First off you need to get an access token. This is done by sending a HTTP request to facebook. Facebook responds with a $_GET variable named $access_token . You can access this by parsing the $appToken result.
    
    $appToken = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=APP_ID_GOES_HERE&client_secret=APP_SECRETE_GOES_HERE&grant_type=client_credentials');
    
    // Use this function to retrieve the $_GET var. The variable name, as sent by FB, is called $access_token
    
    parse_str($appToken);
    
    //Now we've retrieved the access token we can make a call to the graph api for user data. In this instance we request id, name, feed. Requesting 'feed' retrieves status updates. It gets returned as Json
    
    $json_str = file_get_contents('https://graph.facebook.com/USER_PAGE_ID_GOES_HERE?fields=id,name,feed&access_token='.$access_token);
    
    //Decobe the json str which gives an array and then go nuts
    
    $data = json_decode($json_str);
    
    //var_dump($data);
    //print_r($data);
    

     

     

    Hi Guys

     

    Having my first unsuccessful trip into the world of facebook graph api (oh how i hate facebook).

     

    All I want to do is retrieve the facebook wall posts for a specified user.

     

    I created an app to get an access token and secret that part appears to be working as no errors are being returned.

     

    However when i try to pull the feed using the following line of code I get only the user ID back and nothing else:

     

    $json_str = file_get_contents('https://graph.facebook.com/100005065530030?fields=feed&access_token='.$access_token);
    

     

    If I replace ''feed' with 'name' I get the name so it's clearly working on one level.

     

    As I am woefully unfamiliar with facebook api I would very much appreciate if someone could give me a clue as to why this might be happening?

     

    Thanks,

     

    Drongo

  23. Thanks Christian - as ever.

     

    I think I need to spend some time learning about building a class to inject the right resource based on requirement - altho that's quite a BIG topic to get to grips with. At least I am vaguely on the right track by passing the db con via the model constructor so that's reassuring .

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