Jump to content

setcookie


mynamesleo

Recommended Posts

Hi guys, new to php so go easy

[code]<?php

if (isset($_COOKIE["TubeProgsVideo"])) {

echo "Cookie is already set: ";
echo $_COOKIE["TubeProgsVideo"];

} else {

[b]setcookie("TubeProgsVideo","New cookie", time()+60*60*24*90);[/b]

}

setcookie("TubeProgsVideo","akkksssssssss", time()+60*60*24*90);

?>[/code]

Ok so thats the code for test.php, if no cookie is set the last setcookie is set, which is great. But if the cookie is already set the last setcookie is ignored (I have changed the value, etc). What is the deal here? I tried deleting it first before setting it, no dice. I assumed cookie there or not, the last setcookie would simply overwrite it.

Help! thanks!
Link to comment
Share on other sites

cookie values are not tested, only cookie times (expires) are, so if you set the same cookie name with a new value, the second set-cookie will not overwrite the first, if the time is exactly the same! Because the script executes really fast, the time will not be different, so you need to add a second or more to the last cookie.

Sonia

Link to comment
Share on other sites

[code]<?php

if (isset($_COOKIE["TubeProgsVideo"])) {

//echo "Cookie is already set: ";
//echo $_COOKIE["TubeProgsVideo"];

} else {

setcookie("TubeProgsVideo","New cookie", time()+60*60*24*90);

}

setcookie("TubeProgsVideo","Newuuuddddddddookie", time()+60*60*24*90);


echo $_COOKIE["TubeProgsVideo"];


?>
[/code]

Ok that works now, even with the same time? should I use a different time even though its working? or ?
Link to comment
Share on other sites

Ok this is driving me crazy now!

Very first part of my code;

[code]<?php
if (isset($_POST['submit'])) {
setcookie("TubeProgsVideo","jllkkkkkkkiij", time()+60*60*24*90);[/code]
Cookie was NOT set


[code]<?php
setcookie("TubeProgsVideo","jllkkkkkkkiij", time()+60*60*24*90);
if (isset($_POST['submit'])) {
[/code]
Cookie WAS set

why is [quote]if (isset($_POST['submit']))[/quote] { blocking it?
Link to comment
Share on other sites

The code is very messy at the moment, but it will give you the idea:

[code]

<?php

if (isset($_POST['submit'])) {



setcookie("TubeProgsVideo",$video, time()+60*60*24*91);

echo $video;

$id = file_get_contents($video);
$pos = strpos($id, "/player2.swf?video_id=");

if ($pos === false) {

  echo "

<span class='header'>YouTube video downloader</span><br />
<form method='post' action='index.php'>
<input type='text' size='50' name='video' value='$link' class='btn' onclick=value=''>
<input type='submit' value='Download' name='submit' class='btn'>
</form>

<font size='1' color='#FF2829' face='Tahoma'><b>Error! make sure the YouTube video link is correct</b><font><span class='default'><br />Eg: http://youtube.com/watch?v=DLWXyM5qWFo


";


} else {



$posT = strpos($id, "<title>YouTube - ");
$posT = $posT + 16;
$title = substr($id,$posT);
$posT = strpos($title, '</title>');
$title = substr($title, 1, $posT-1);
$pos = $pos + 21;
$id = substr($id,$pos);
$pos = strpos($id, '"');
$id = substr($id, 1, $pos-1);



echo "

<table border='0'>

<tr>
<td align='right'>
<font size='1' color='#000000' face='Tahoma'><b>$title</b></font><br /><br />

<span class='default'>
<b>Help: </b>To watch downloaded YouTube videos you will need an FLV PLAYER, if you don't already have<br />
one you can download a good one <a href='http://applian.com/flvplayer/index_martijn.php' target='_blank'>HERE</a> or search google for a differernt one, theres lots around!
</span><br />
</td>
</tr>

<tr>
<td align='center'>

<form method='post' action='http://youtube.com/get_video.php?video_id=$id'><input type='submit' value='Download the video now!' name='submit' class='btn'></form>

</td>
</tr>


</table>


";

}


} else {

if (isset($_COOKIE["TubeProgsVideo"])) {

$link = $_COOKIE["TubeProgsVideo"];

} else {

$link = "eee";

}


echo $_COOKIE["TubeProgsVideo"];
echo "

<span class='header'>YouTube video downloader</span><br />

<form method='post' action='index.php'>
<input type='text' size='50' name='video' value='$link' class='btn' onclick=value=''>
<input type='submit' value='Download' name='submit' class='btn'>
</form>

";

}



?>

[/code]



The plan is to plant the cookie of the value (Link) entered in the textbox after it has been submitted, so next time they visit the vaule in the textbox will be the last one they entered. I am still new with php so have to forgive the quality, etc.
Link to comment
Share on other sites

looking at your code. Your have not created the following variables when the form has been submitted:
$video or $link

So the cookie will not be set. What you'll want to do is add the following code:
[code=php:0]    $video = $_POST['video'];
    $link = $_POST['video'];[/code]


After:
[code=php:0]if (isset($_POST['submit'])) {[/code]


Now your script should work correctly.

Link to comment
Share on other sites

Ok well it was working now its not (i dont know what/if i changed anything)

[code]


<?php

if (isset($_POST['submit'])) {

    $video = $_POST['video'];
    $link = $_POST['video'];


$id = file_get_contents($video);
$pos = strpos($id, "/player2.swf?video_id=");

if ($pos) {

setcookie("TubeProgsVideo",$video, time()+60*60*24*90);


$posT = strpos($id, "<title>YouTube - ");
$posT = $posT + 16;
$title = substr($id,$posT);
$posT = strpos($title, '</title>');
$title = substr($title, 1, $posT-1);
$pos = $pos + 21;
$id = substr($id,$pos);
$pos = strpos($id, '"');
$id = substr($id, 1, $pos-1);



echo "

<table border='0'><tr><td align='right'>
<font size='1' color='#000000' face='Tahoma'><b>$title</b></font><br /><br />
<span class='default'><b>Help: </b>To watch downloaded YouTube videos you will need an FLV PLAYER, if you don't already have<br />
one you can download a good one <a href='http://applian.com/flvplayer/index_martijn.php' target='_blank'>HERE</a> or search google for a differernt one, theres lots around! </span><br />
</td></tr>
<tr>
<td align='center'>
<form method='post' action='http://youtube.com/get_video.php?video_id=$id'><input type='submit' value='Download the video now!' name='submit' class='btn'></form>
</td>
</tr>
</table>


";



} else {

echo "<font size='1' color='#FF2829' face='Tahoma'><b>Error! make sure the YouTube video link is correct</b><font><span class='default'><br />Eg: http://youtube.com/watch?v=DLWXyM5qWFo";


}


} else {

if (isset($_COOKIE["TubeProgsVideo"])) {

$link = $_COOKIE["TubeProgsVideo"];

} else {

$link = "Enter YouTube video url here and click download!";

}

echo "<span class='header'>YouTube video downloader</span><br />
<form method='post' action='index.php'>
<input type='text' size='50' name='video' value='$link' class='btn' onclick=value=''>
<input type='submit' value='Download' name='submit' class='btn'>
</form>";



}



?>


[/code]

Can you see anything wrong with that?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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